I’m trying to make a bending effect (horizontally) on a surface shader (lighting is important in my scenario). Currently I’ve added the following vertex calculations on the surface shader:
The bending effect is OK but the shadows are all wrong:
I’m a little confused on what to do to fix the problem, should the normals be recalculated on the go? Isn’t a demanding process? Or is a completely different problem?
It’s not the normal. That’s from not updating the shadow caster pass, which gets used for both shadow casting and the camera depth texture. The way Unity does directional shadows it actually casts upon the depth texture. The result is if you’re not applying the bend to the shadow caster pass the shadows won’t match.
With a surface shader you can add addshadow to the #pragma surface line. However you can’t use UnityObjectToClipPos() to do the bend, since in the shadow map pass that’ll get the distance from the light, not from the game camera. You’ll want to get the distance to _WorldSpaceCameraPos or use unity_WorldToCamera.