Awesome
Inline Ray Tracing Shadows
Sample scene that uses ray traced shadows generated by a compute shader using ray queries (DXR 1.1).
Technical Document
https://docs.google.com/document/d/1uRoUbW4m6Y_Bo7uCRUKwEhbKVTu5MKvto-Pm89DYXoY/edit
Requirements
- Unity 2023.1 beta - inline ray tracing support in compute shaders.
- Unity 2023.2 beta and above - inline ray tracing support in any shader stage.
- SystemInfo.supportsInlineRayTracing must be true.
Effect Description
The shadow texture is generated in screen space and blit directly on top of the rendered scene. To generate the screen space shadows texture, a compute shader reads the depth value from _CameraDepthTexture built-in texture. The world space position for a particular pixel is generated and from that point a number of rays are cast along the light direction with some random offsets for generating variable penumbra based on the distance from the shadow caster.
The world normal is read from the GBuffer _CameraGBufferTexture2 and is used to avoid generating shadows for surfaces that have the same orientation as the directional light.
There is a simple temporal accumulation of samples which resets when parameters related to camera change.
Limitations:
- The Rendering Path must be set to Deferred in Camera settings.
- The shadow is currently generated on top of everything else so the regular shadows must be disabled from the Light settings.
- The effect works only in Game view.
Examples using varying penumbra based on distance to shadow caster and Shadow Spread option (Main Camera).
<img src="Images/1.jpg" width="1280"> <img src="Images/2.jpg" width="1280"> <img src="Images/3.jpg" width="1280">