# Vertex shader deformation and normals

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

## 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?

Thanks.

##### 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.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 9
• 15
• 9
• 11