Jump to content


HLSL Geometry shader normals problem


1 reply to this topic

#1 Tottel

    Member

  • Members
  • PipPip
  • 49 posts

Posted 07 June 2012 - 09:21 AM

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?

#2 Tottel

    Member

  • Members
  • PipPip
  • 49 posts

Posted 07 June 2012 - 11:48 AM

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users