Rendering from the perspective of direction light

Please can anyone help, I’m trying to render (to a texture) from the perspective of the scene’s directional light in exactly the same way as it’s done in the shadow caster shader pass (“LightMode” = “ShadowCaster”)

Basically i want the built in shader variable UNITY_MATRIX_VP matrix EXACTLY as it is in the “LightMode” = “ShadowCaster” but from a “LightMode” = “ForwardBase” shader.

Does anyone know how or where this matrix is calculated so i can send it to my “ForwardBase” pass ?

Any help would be much appreciated.

It’s calculated deep in the bowls of Unity’s C++ code and c# never gets access to that data. I know some people have tried to calculate this manually, and one person said they succeeded, but have never posted the code publicly. They also didn’t ultimately use that code for what they were working on and instead managed to get it all working fully on the GPU instead.

Unity’s Adam demo used a curious technique where they copy off the necessary information to a structured buffer for reuse at other times on the GPU, but you could conceivably read back that data to the CPU.

Unfortunately those matrices will be pre-transformed for the platform, where as the projection matrix you set on a camera is expected to be in OpenGL form. This means if you take the matrix you get from that shader and apply it to a camera it will not match (and it’ll get transformed again making it even weirder).