E F
E F

Reputation: 11

How to calculate Gertner waves normals?

I'm unable to properly calculate the normals for gertner waves following the Nvidia article

vec3 get_wave(vec4 wave, vec2 direction,vec3 vtx)
{
    // x = SPEED, y = WAVELENGTH, z = AMPLITUDE, w = STEEPNESS
    float p = wave.x * (2.0 / wave.y);
    float w = 2.0 / wave.y;
    vec3 res = vec3(0.0);
    float factor =  wave.y * dot(direction, vtx.xz) + TIME * wave.x;
    res.x = (wave.w * wave.z) * direction.x * cos(factor);
    res.z = (wave.w * wave.z) * direction.y * cos(factor);
    res.y = wave.z * sin(factor);
    return res;

}


vec3 get_normal(vec4 wave, vec2 direction, vec3 vtx)
{
    float w = 2.0 / wave.y;
    float phi = wave.x * w;
    float WA = w * wave.z;
    float factor = w * dot(direction, vtx.xz) + phi * TIME;
    vec3 res;
    res.x = - direction.x * WA * cos(factor);
    res.z = - direction.y * WA * cos(factor);
    res.y = wave.w * WA * sin(factor);
    return res;
}

void vertex() {
    vec3 original_vtx = VERTEX;
    vec3 res = get_wave(wave_1, wave_1_dir, VERTEX);
    VERTEX.x += res.x;
    VERTEX.y = res.y;
    VERTEX.z += res.z;
    NORMAL = get_normal(wave_1, wave_1_dir, original_vtx);
    NORMAL.y = 1.0-NORMAL.y;

}

This is the code (godot), however the normals look like this enter image description here Can anyone help me figure out what's wrong?

Upvotes: 1

Views: 32

Answers (0)

Related Questions