1

I am displacing vertices to form a 3D planet, using a random noise function:

float hash( float n ) { return fract(sin(n)*753.5453123); }

float snoise( in vec3 x )
{
    vec3 p = floor(x);
    vec3 f = fract(x);
    f = f*f*(3.0-2.0*f);

    float n = p.x + p.y*157.0 + 113.0*p.z;
    return mix(mix(mix( hash(n+  0.0), hash(n+  1.0),f.x),
                   mix( hash(n+157.0), hash(n+158.0),f.x),f.y),
               mix(mix( hash(n+113.0), hash(n+114.0),f.x),
                   mix( hash(n+270.0), hash(n+271.0),f.x),f.y),f.z);
}

As the points are calculated on the GPU I have no way of calculating smooth normals ( apart from flat normals using a geometry shader). I have found various methods of doing this i.e using the neighbour method, however this leaves lots of artefacts on the terrain while performing the lightning calculations.

I am currently calculating the normals using this function with varying different theta values however the lighting has loads of patched areas of bright light :

vec3 calcNormal(vec3 pos)
{
    float theta = Theta; 
    vec3 vecTangent = normalize(cross(pos, vec3(1.0, 0.0, 0.0))
     + cross(pos, vec3(0.0, 1.0, 0.0)));
    vec3 vecBitangent = normalize(cross(vecTangent, pos));
    vec3 ptTangentSample = getPos(normalize(pos + theta * normalize(vecTangent)));
    vec3 ptBitangentSample = getPos(normalize(pos + theta * normalize(vecBitangent)));

     return normalize(cross(ptTangentSample - pos, ptBitangentSample - pos));
  }
galaban
  • 11
  • 4
  • 1
    Possible duplicate of [Per-Vertex Normals from perlin noise?](http://stackoverflow.com/questions/6503257/per-vertex-normals-from-perlin-noise) – Noah Witherspoon Oct 28 '16 at 20:09

0 Answers0