I have a shader that is supposed to warp terrain the further it is away from the camera. The problem is shadows are still based off the un-deformed vertices, which casts against the deformed terrain. Essentially casting a shadow on itself.
Googling around said I need to use ‘addshadow’, but it doesn’t do anything for me.
here is with the deformation, shadows included, note the shadowing on the terrain… that is coming from what would be the terrain if it weren’t deformed.
That seems strange to me. As far as I can tell, specifying a custom vertex function in a surface shader generates appropriate shadow passes. Everything should just work. The standard tree shaders use the same approach, and their shadow passes reflect distortion from wind.
Does your shader produce correct shadows when used on regular meshes? If so, then perhaps terrain shadows are handled in a special way. In this case, you might have to get input from Unity on whether the terrain shadow pass can be replaced.
As an aside, you should avoid branching (usually if statements) in shaders whenever possible. It could very well be being optimized out by the compiler in this case, but it’s very unlikely that you’ll gain any performance on any hardware by enclosing your vertex function in a conditional.