Inconsistent Results for Grass Shader Sampling Ground Texture Between Different Renderers
I'm currently developing a Grass Shader that samples the ground texture in Godot 4. However, I've encountered an issue where the shader produces different results depending on the renderer being (Forward+ and Compatibility)
Rendered : Forward+
Rendered : Compatibility
The multimesh3D shader
render_mode cull_disabled,unshaded;
uniform sampler2D Texture;
varying vec3 pos;
uniform float size;
uniform float test;
uniform vec3 wind_direction;
uniform float wind_strength: hint_range(0.0, 1.0, 0.01) = 0.3;
uniform sampler2D wind_noise;
uniform float wind_noise_size: hint_range(0.0, 1.0, 0.001) = 0.05;
uniform float wind_noise_speed: hint_range(0.0, 1.0, 0.001) = 0.1;
uniform sampler2D texture_height : source_color, filter_linear_mipmap, repeat_enable;
uniform sampler2D texture_normal : source_color, filter_linear_mipmap, repeat_enable;
uniform vec3 cam_pos;
uniform float grassRange = 20;
uniform float fadeGrassFactor = 0.25;
uniform vec3 scale ;
float random (vec2 uv) {
return fract(sin(dot(uv,
vec2(12.9898,78.233))) * 43758.5453123);
}
void vertex() {
pos = NODE_POSITION_WORLD;
vec3 world_position = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
vec3 wind_texture = texture(wind_noise, world_position.xz * wind_noise_size + normalize(-wind_direction.xz) * TIME * wind_noise_speed).rgb;
vec3 wind_vector = (vec4(wind_texture * normalize(wind_direction) * wind_strength, 0.0) * MODEL_MATRIX).xyz;
VERTEX += wind_vector * mix(2.0 * (pow(2.0, -UV.y)-0.5), 1.0 - UV.y, 0.5);
vec3 Color = texture(Texture,pos.xz * 1.0/size-.5).rgb;
float distancetocam = distance(pos, cam_pos);
vec3 scaled_vertex = VERTEX * clamp((grassRange - distancetocam ) * fadeGrassFactor,0.0,1.0) ;
float rotation = random(pos.xz * 1.0/size-.5);
mat3 rotation_matrix = mat3(
vec3(cos(rotation), 0.0, sin(rotation)),
vec3(0.0,1.0,0.0),
vec3(-sin(rotation), 0.0, cos(rotation))
);
vec3 rotated_vertex = rotation_matrix * scaled_vertex;
VERTEX = rotated_vertex;
VERTEX.y += texture(texture_height,pos.xz * 1.0/size-.5).r * 6.0;
}
uniform sampler2D colorv;
void fragment() {
vec3 Color = texture(Texture,pos.xz * 1.0/size-.5).rgb;
ALBEDO = Color;
if(FRONT_FACING){
NORMAL = -NORMAL;
}
}