Strange render issue depending on player position
Asked Answered
A

3

0

Hello there,
for my RPG project I added some grass to the 3D scene:

  • I created a scene asset for a tuft of grass and another scene asset of a fern plant
  • I created a spatial shader so that the plants are slightly moving in the wind.
    • Render mode render_mode cull_disabled, depth_draw_alpha_prepass; (gave the best result)
    • The plants are just several planes put together in different angles and a texture with leaves on it (with transparent areas)
  • then I used the Godot-Plugin Scatter (https://github.com/HungryProton/scatter) to spread the plants over a large area.

So far it looks pretty nice, but one issue shows up:
In some areas it looks exactly as it is intended: The plants in the front hide the plants behind them. But then when I move around and cross a line unknown to me the view changes.
Suddenly the plants far away are much brighter and they are visible through the grass in front of the player.

Since the scatter plugin just places the objects into the world, I dont think it is a problem of the plugin. I guess I miss something in the shader.

What did I miss?

Issue is best seen in unshaded mode:


Shader:

shader_type spatial;
render_mode cull_disabled, depth_draw_alpha_prepass;

uniform sampler2D plantTexture : hint_albedo;
uniform float windSpeed = 0.1;
uniform float strength = 1.0;
uniform vec4 additionalColor : hint_color;
uniform float additionalColorStrength : hint_range(0, 1) = 0.0;
// Wind Noise
uniform sampler2D noise1;

void vertex() {
	// Get the speed of the wind
	float t1 = TIME * windSpeed;
	
	vec3 vertexPos = VERTEX.xyz;
	float height = vertexPos.y;

	// Get the "noise-wind-value" from the position shifted by time
	float noiseCol = texture(noise1, vertexPos.xz * t1).r * strength;

	float influenceNoise = smoothstep(0, 1, noiseCol );
	vertexPos.xz *= (1.0 + noiseCol * height) *strength;

	VERTEX = vertexPos;
}


void fragment() {
	vec4 color = texture(plantTexture, UV).rgba;
	ALPHA = color.a;
	color = mix( color, additionalColor, additionalColorStrength);

	ALBEDO = color.rgb;
}
Anabas answered 9/2, 2023 at 15:44 Comment(0)
G
0

I'm inclined to wonder and ask if it might be to do with the import settings of the specific texture in question.

Gordie answered 9/2, 2023 at 16:20 Comment(0)
A
0

I gave it a try and played a bit with the import settings. Indeed... this problem does not show up if deactivate the Mipmaps of the grass texture. Then of course the grass looks awfully pixelated in the distance. But at least it is a direction where to investigate further. Thanks for the hint. :-D

Anabas answered 9/2, 2023 at 17:4 Comment(0)
A
0

Short update in case someone else might run into the same problem. I found the reason for this behaviour which I fixed and now it works fine.

I imported the plant's texture as PNG, which I created with GIMP. In the image there were large transparent areas. When drawing a straw of grass (which was very slim), Gimp applied some antialiasing so even the small straws were some kind of transparent. This looked pretty good in close distance. As I understand it, Godot automatically calculates Mipmaps from PNG images for views from far away. Since the grass was half transparent, the calculated image was just a blurry transparent blop so that the plants behind the grass were fully visible.

To fix this:
1) I edited the image and made the straws of grass wider so that there were not so many transparent areas
2) I made sure that there was no antialiasing. So: No half transparent areas. The areas where no grass is shown is fully transparent, but where grass is visible: no transparency at all.
3) I exported the image in Gimp as DDS file with precalculated Mipmaps. (Settings: Filter "Nearest", Wrap mode "clamp" to make sure that the precalculated mipmaps dont have half transparent areas either)

When I now import the DDS files into Godot and use them in my shader it looks fine and this issue does not show up any more.
Of course it looks a bit pixelated, but it is almost not noticable and way better than it looked like when I just disabled the Mipmap calculation for the PNG file.

Anabas answered 10/2, 2023 at 15:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.