I'm trying to write a simple shader that moves all verts with a sin wave.
v.vertex.y += sin(_Time.y * _Speed + v.vertex.x * _Amount * v.vertex.z) * _Distance;
The problem is that after moving them, the normals are wrong, thus there are no real time shadows. I've searched a lot and found that I need to recalculate the normals using fake neighbours. None of the implementations were for Unity Shaderlab, so I can't just copy and paste them, and my knowledge of shader code is pretty basic so I can't translate what I found to what I need.
Can anyone help me with what and how to recalculate normals after moving a vertex?
The math behind normal calculation is cross product.
Take vertex A, B and C from a triangle. Then create vectors AB and AC. ABxAC will give you the normal of the triangle. ACxAB will give the opposite normal (ABxAC = - ACxAB).
en.wikipedia.org/wiki/Cross_product
If you were to move the mesh from Mesh class, there is a RecalculateNormals. But I guess that doesn't apply here as you work on the shader.