Hello,
Based on a question I got about an older thread (http://forum.unity3d.com/threads/146254-Computing-normals-in-vertex-shader), I decided to put together a quick and light project and video explaining an approach to recreating normals in a vertex shader in a little more detail. Might be useful for water, who knows?
Video
Project zip:
adrianswall.com/temp/simpleplanewave.zip
The approach shown here is just about finding a way to define “fake neighbors”, or additional points that lie on the unperturbed surface. In the case of the original post, that was a unit sphere. In this case, it’s a plane. Once you have two neighbors, you just take the cross product of the vectors between the sample vertex (the one known to the vertex shader at that time) and each neighbor, and that’s it. In both cases, I used very small displacements between sample and neighbor, which is to help eliminate frequency/accuracy/phasing problems as the perturbation function is basically just sin().
Towards the end of the video, I mention the possibility of storing offsets from sample to neighbor in vertex metadata channels. That would eat quite a lot of metadata, but it might be useful for applying this process to arbitrarily complex meshes. Another way of going about it is to think about what your perturbation is actually doing, and whether there’s a way to just operate on the normal directly, without needing neighbor data.
Cheers,
-Adrian