Jump to content

  • Log In with Google      Sign In   
  • Create Account


Vertex shader deformation and normals


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 george7378   Members   -  Reputation: 1185

Like
0Likes
Like

Posted 23 April 2014 - 05:26 AM

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.



Sponsor:

#2 Hodgman   Moderators   -  Reputation: 29455

Like
1Likes
Like

Posted 23 April 2014 - 07:17 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS