It gives a nice wavy movement to a gridded mesh I’m using as a water surface.

My only problem now is that I’m not quite sure what happens to the normals and other variables in the shader related to the position of the vertices. Are e.g. the normals updated automatically?

Obviously I’m a bit lost at the moment, so if anyone could push me in the right direction I would appreciate it

@makeshift said:
My only problem now is that I'm not quite sure what happens to the normals and other variables in the shader related to the position of the vertices. Are e.g. the normals updated automatically?

No. No magic happens unless you code it, really. You supplied the normals in the mesh. The normals were not updated for the new position... and in fact there is no way they could have been since it is not known exactly which way a normal should point once its vertex has moved. That would be based on the rest of the mesh.

For water, this almost never matters... or you can pick some arbitrary deformation. But this is not something your GPU could know without you providing that in the shader.

@pspeed said:
and in fact there is no way they could have been since it is not known exactly which way a normal should point once its vertex has moved. That would be based on the rest of the mesh.

Good point. In my case it will always be the one with a positive y value, I don't need a general solution. I'm only using colors in the surface's material, so when initially the normals are computed for a flat surface there is no change to how the surface looks except for the y position of the vertices.

Is recomputing the normal's for each frame something you wouldn't recommend? It sounds a bit resource demanding.

Depends on where and how you recompute them. If you have to recompute them in the Mesh every frame then that is kind of expensive just to get a wavy effect… especially considering that the normals shouldn’t matter much in that case.

From your description, it sounds like you don’t need to recompute the normals. If the vertex normals don’t change when they are moved then there is nothing to do.

Thanks for bearing with me. I think I might have misunderstood how normal’s are used. In the diagram below you see the triangle from the side and the arrow is the normal. Now what I have assumed is that the result if I do nothing with the normals is scenario 1, but hopefully it’s 2, and I need to do nothing as you say.

Normals are attached to vertexes. Change your diagram to have normals at the end points and then tell me what you expect the normals to do.

Diagram 1 is closest to what actually happens.

Diagram 2 is hard to calculate correctly though you might be able to fake it given some assumptions.

Note: if your vertexes are always the peaks and the troughs of a sine wave then their normals wouldn’t change anyway. If the sine wave “moves” then you can calculate the normal pretty easily as the tangent of the sine wave.

Yeah, I didn’t mean the tangent… but hopefully you know what I mean. You know the slope at that point on the sine wave so you can calculate the normal. It will be perpendicular to the tangent of course.

@pspeed said:
Yeah, I didn't mean the tangent... but hopefully you know what I mean. You know the slope at that point on the sine wave so you can calculate the normal. It will be perpendicular to the tangent of course. :)

Yeah, got that part:) Googled up: http://www.gamedev.net/topic/551569-finding-the-normal-of-a-point-on-a-sine-wave/ just to be sure. @pspeed and @normen:
Maybe you guys should post a live graph with your point score over time :p