Volumetric Shadows in Unity

Hello!

I’m currently studying volumetric rendering in Unity, and I think I got something interesting already. I applied a shadow mapping technique with a ray marching shader. Basicaly what I do here is to transform a fragment position using the light perspective, or in other words, I multiply it by its VP matrix. Then I use the XY value of this transformed position to sample the shadow map texture, and I compare this value with the Z value of the position. By adding the differences between those values alongside a view direction ray it creates a trail of shadow.

In order to get the shadow map texture in Unity, I used an ortographic camera with a replacement shader, which renders only the opaque objects with a shader that calculates its normalized depth, with a clear flag of a white color. The directional light is a child of this camera, to make the light direction convincing with the shadows.

I propagate the shadow test using ray marching techniques, and finally I apply the final shadow value to the opacity of a particle. Then, by adding a bunch of smoke particles it creates the illusion of volume.

The next step is to optimize it in order to use it on a realtime VR scenario!

Critiques and comments are welcome.

ps.: The smoke effect is very generic as I did it only for testing the shadows

5 Likes