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;
}