Home Technical Talk

Shader Math: Normals from non-texture height?

polycounter lvl 5
Offline / Send Message
mAlkAv!An polycounter lvl 5
I'm currently testing various methods of recalculating normals for an ocean shader with some vertex displacement waves.

One of these approaches uses sine - cosine correcelations to calculate the normal components, as described here:
http://www.antongerdelan.net/opengl/vertex_displacement.html
What I'd like to know is, how would you modify this method for waves that are not linear like in the example but irregular or circular shaped?

Replies

  • CrazyButcher
    Offline / Send Message
    CrazyButcher polycounter lvl 20
    you could mathematically create the derivative of the position function

    or use something like forward differencing
    // Use forward differencing to compute the normal:
    float du = 0.0001; float dv = 0.0001;
    vec3 C = SurfaceFunc(p.x + du, p.y);
    vec3 B = SurfaceFunc(p.x, p.y + dv);
    vec3 A = tePosition;
    teNormal = normalize(cross(C - A, B - A));
    

    http://github.prideout.net/sympy-surfaces/
  • mAlkAv!An
    Offline / Send Message
    mAlkAv!An polycounter lvl 5
    Yes that's possible, and that's what I've already done. At first I thought that sine/cosine appraoch described in the linked article is a different method but in fact it's just a derivative for the special case of waves moving along a single axis only?

    Thanks for the help and the code sample. Forward differencing is a term I never heard of, although I've been using it for generating normals from height before.
Sign In or Register to comment.