Implementing ray-traced reflections
In this section, we are going to leverage the hardware ray tracing capabilities to implement reflections. Before diving into the code, here’s an overview of the algorithm:
- We start with the G-buffer data. We check whether the roughness for a given fragment is below a certain threshold. If it is, we move to the next step. Otherwise, we don’t process this fragment any further.
- To make this technique viable in real time, we cast only one reflection ray per fragment. We will demonstrate two ways to pick the reflection’s ray direction: one that simulates a mirror-like surface and another that samples the GGX distribution for a given fragment.
- If the reflection ray hits some geometry, we need to compute its surface color. We shoot another ray toward a light that has been selected through importance sampling. If the selected light is visible, we compute the color for the surface using our standard lighting model. ...