Skip to main content
GameDev.net gamedev.net
🔒 Locked

moving each vertex along its normal

Started by ehmdjii Jan 4, 2011 at 11:39 AM 6 replies 4.1k views
Original Post
ehmdjii
ehmdjii
hello i want to apply an extrude effect to a mesh so i just want to move each vertex along its normal.
this is what i try in glsl code:

vec4 v = vec4(gl_Vertex.xyz + gl_Normal * moveamount, 1);
gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * v;

unfortunately this seems to only work for vertices that are part of frontfacing polygons. all backfacing polygons seem to move inward.

this is how it looks on a sphere:


thanks for any help on this!
Burnt_Fyr
Burnt_Fyr
Do you notice a difference in the amount of translation for polys that are perpendicular to the view vector, compared to those that are at an angle?

I'm guessing that the transformation is happening in a different space then your normals are in. Could you post some sample verts, and perhaps a render of the front and back sides of the sphere, or perhaps a cube?
rubicondev
rubicondev
I'm not overly familiar with GLSL, but shouldn't the order of multiplies be v*view*proj ?
------------------------------Great Little War Game
karwosts
karwosts
Quote:
Original post by Rubicon
I'm not overly familiar with GLSL, but shouldn't the order of multiplies be v*view*proj ?


No, he is correct. If you're coming from DirectX it's the opposite way, due to hlsl being based on row vectors. GLSL uses column vectors, so pre-multiplying occurs on the right.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
ehmdjii
ehmdjii
you were right, there was a problem with the sphere model itself. all the faces where duplicated and mirrored. that's why i saw backfaced faces in the first place.
rubicondev
rubicondev
Quote:
Original post by karwosts
Quote:
Original post by Rubicon
I'm not overly familiar with GLSL, but shouldn't the order of multiplies be v*view*proj ?


No, he is correct. If you're coming from DirectX it's the opposite way, due to hlsl being based on row vectors. GLSL uses column vectors, so pre-multiplying occurs on the right.
Thanks, seems obvious now you point it out, but I'll note that for next time. It just wouldn't do for any two similar things to work the same huh. :)
------------------------------Great Little War Game

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.