1

I am having problems calculating normals after tesselation.

Currently I have code which samples height map and calculates normal from that:

float HEIGHT = 2048.0f;
float WIDTH =2048.0f;
float SCALE =displace_ratio;

vec2 uv =  tex_coord_FS_in.xy;
vec2 du = vec2(1/WIDTH, 0);
vec2 dv= vec2(0, 1/HEIGHT);
float dhdu = SCALE/(2/WIDTH) * (texture(height_tex, uv+du).r - texture(height_tex, uv-du).r);
float dhdv = SCALE/(2/HEIGHT) * (texture(height_tex, uv+dv).r - texture(height_tex, uv-dv).r);

N = normalize(N+T*dhdu+B*dhdv);

But doesn't look ok with low level tesselations enter image description here

How can I get rid of this ?

Jozef Culen
  • 344
  • 1
  • 2
  • 10
  • 1
    Can you move the normal calculation to the fragment-stage? I would need more information about what you're actually doing to provide a more thorough answer. – Gigo Apr 13 '15 at 02:20
  • I think I could, Code above is calculating normals for vertices in tesselation evaluation shader. – Jozef Culen Apr 13 '15 at 06:28

1 Answers1

0

Only way to get rid of this is to use a normal map in combination with the computed normals. The normals you see on the right are correct. They're just in low resolution, because you tesselate them so. Use a normal map and per-pixel lighting to highlight the intricate details.

Also, one thing to consider is the topology of your initial mesh. More evenly spaced polygons result in more evenly spaced tesselation.

Additionally, you might want to do, instead of:

float dhdu = SCALE/(2/WIDTH) * (texture(height_tex, uv+du).r - texture(height_tex, uv-du).r);
float dhdv = SCALE/(2/HEIGHT) * (texture(height_tex, uv+dv).r - texture(height_tex, uv-dv).r);

sample a few more points from the heightmap, and average them to extract a more averaged version of the normal at each point.

Dimo Markov
  • 422
  • 2
  • 9