Advertisement Jump to content
Sign in to follow this  

Vertex shader deformation and normals

This topic is 1732 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've got a question about deforming a plane using a vertex shader. I'm trying to create a reflective ocean surface using a cube map as the reflection texture. I start with a subdivided plane and then I deform its surface according to this equation:


VSIn.Position.y += 0.1f*sin(5*VSIn.Position.x - f_ElapsedTime)*sin(5*VSIn.Position.z - f_ElapsedTime);


where VSIn.Position is the raw position data taken into the vertex shader. This is the first line in the vertex shader. This seems to work in that I get my desired rolling wave effect on the plane, but my cube map reflections don't work properly because the normals still seem to be pointing in the straight up direction when ideally they should follow the curvature of the plane as it deforms.


Do I need to manually recalculate the directions of the normals, or is there an easy way to get them to follow the plane's curvature? How would you solve this problem?



Share this post

Link to post
Share on other sites

You need to know the slope of your procedural function at that position (and convert that slope into a normal).


For some functions, you might be able to analytically solve this problem -- rearrange the math to tell you what the derivative of that function is.

For other functions, you can solve it numerically by computing the same function 3 times, once as you have it, once with a small x offset, and once with a small z offset. Then compare the 3 heights, which tells you the slope.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!