Zylann/godot_heightmap_plugin

Single line of pixels on top of detail texture

BartekDe opened this issue · 3 comments

Hi,
great job on the plugin!

I have a question about the detail layers. I applied a grass texture to one of the layers and when the objects are rendered there is a single line of pixels on top of every grass object.
I took some screenshots, hopefully it's visible.
image

The texture I used is from free Kenney Foliage pack to which I applied green color in GIMP. There are no pixels in the top row of the texture.
The texture I use:
sprite_0053_colorized

Searching on the internet I found that it's common issue, because of the texture tiling.
I added a line of transparent pixels on the bottom of my texture, but the lines on top are still visible.
Adding more and more transparent pixels on the bottom seems to gradually make the lines disappear. But even with 5+ transparent pixels it's showing those lines when looking from the distance, while grass is already visibly floating off the ground.
Is there any way to solve this? Is it behaving this way on purpose?

The reason you have to add so many empty lines is because your texture is very big, to the point that most of the time you don't even see it fully, but only one of its mipmaps. Mipmaps are lower-resolution versions computed by the importer, which reduces by half the distance between the bottm of the grass and the bottom of the image at every level, so it gets closer and closer the further away you look from it. I wouldn't recommend using such a big texture as alpha-scissor will already make it look sharp at a lower resolution.

As for the issue itself, it happens in your case because you likely enabled MSAA. I don't have this issue without MSAA.

An easy way to fix it would be to disable texture repetition in the detail shader, which prevents the texture from wrapping to its bottom due to filtering when the top is rendered. In Godot 3 it used to be an import option of textures. Unfortunately, since 4.0 this option is no longer there, and it cannot be an inspector option because Godot shaders require you to hardcode this option as part of the shader:

// detail.gdshader
uniform sampler2D u_albedo_alpha : source_color, repeat_disable; // <--

I'm assuming this is the desired setting for most cases, so I pushed the fix in beb990e.
If a different setting is required you may use a custom version of the shader.

Single line in the shader resolved the issue, there are no more lines.
Thank you!