Hello 
I made a simple vertex displacement shader that uses a render texture to distort the vertices. It looks like this:
However, the shadows created by this distortion do not seem to work. It seems as if the light source uses the screen position values from its perspective to create the distorted shadows, and therefore change when the light source is rotated:
What is the reason for this and how can I fix it?
(The shader normally also has a wind displacement and the shadows work correctly there)
I found the solution, here it is in the unlikely event someone else needs it:
From the few other posts I found, it appears that the screen position node doesn’t work during the shadowcaster pass because it uses the projection and view matrices from the light’s point of view (and not the camera’s).
After searching the internet for a while, I found a “replica” of the screen position node in shadergraph that used said matrices (unfortunately I can’t find the original post anymore). I replaced the matrices with a global shader variable and set the matrices of the camera instead (worldToCameraMatrix as view and projectionMatrix as projection). This way the matrices stay the same even when rendering the shadows. The whole thing is here:
The view matrix needs to be updated when the camera moves.
(I don’t really know what I’m talking about, so my reasoning might be wrong. But it worked
!)
1 Like