INedelcu / InlineRayTracingShadows

Sample scene that uses ray traced shadows generated by a compute shader using ray queries.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inline Ray Tracing Shadows

Sample scene that uses ray traced shadows generated by a compute shader using ray queries.

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 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).

About

Sample scene that uses ray traced shadows generated by a compute shader using ray queries.


Languages

Language:C# 93.6%Language:ShaderLab 6.4%