You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Godot 4草地Shader采样地面纹理在不同渲染器下结果不一致

Godot 4草地Shader在不同渲染器下的差异问题

我正在Godot 4中开发一款采样地面纹理的草地Shader,但遇到了一个问题——Shader的输出结果会因使用的渲染器(Forward+ 和 Compatibility)不同而产生差异。

渲染效果对比

Forward+ 渲染器

Forward+渲染效果

Compatibility 渲染器

Compatibility渲染效果

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

内容的提问来源于stack exchange,提问作者ilies

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 14:13:13