HLSL Geometry shader normals problem

F861248e62fd7640cb766decacdb1d15
0
Tottel 101 Jun 07, 2012 at 09:21

Hello,
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.

http://i.imgur.com/2WGoT.png

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.

F861248e62fd7640cb766decacdb1d15
0
Tottel 101 Jun 07, 2012 at 11:48

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