HLSL Geometry shader normals problem

Tottel 101 Jun 07, 2012 at 09:21

I’m making a geometry shader that generates waves on a mesh (preferably a flat plane), using a heightMap.
Everything is working fine, except the normals don’t really work out.


I set the normal for each vertex using the crossproduct, which is correct for each triangle individually.
However, the geometry shader goes over every vertex multiple times, so it will assign a different normal for every triangle (right?).
Which means it cannot interpolate correctly.

I tried to be creative and check for every vertex if its normal is default (0,1,0), like so:

if ((vertices[0].Normal.y >= 1.01f && vertices[0].Normal.y <= 0.99f)) normal0 = vertices[0].Normal;
else normal0 = normalize(cross(top0 - top1, top0 - top2));

So that it will reuse the normal if it’s already assigned to that vertex. However, it’s still giving me the same problem. Any ideas how to solve this?

1 Reply

Please log in or register to post a reply.

Tottel 101 Jun 07, 2012 at 11:48

Well, nevermind. I can just do the exact same in the vertex shader. Silly me.