Ray Tracing Algorithm

3 minute read

Published:

(Work in progress…)

Ray Tracing Algorithm

Ray tracing is a popular ray-based rendering technique, often suitable for real-time rendering as under limited sample budget, ray tracing generates less noisy results than other Global Illumination algorithms, e.g., Path Tracing. On the other hand, ray tracing is biased, deterministic, and often the global lighting effects are hard to achieve. There is another ray-based rendering, Ray Casting which sometimes make the beginners confused. Compared with ray tracing, ray casting is much straight forward. It is limited to the primary rays only (visibility). Consequently, the algorithm is limited to the simple shading and depth.

Ray Tracing Algorithms Classification

An overall classification of ray tracing could be infeasible as it could be seen from different angles. For example, the generic forward and backward ray tracing (See) also applied. However, when only talk about different ray tracing, the followings are two popular choices:

1. Whitted-Style ray tracing

2. Cook-Style Ray Tracing

3. Other Ways

Other than above two,

Hybrid Ray Tracing: is also popular, especially in the game industries. Sometimes also named as screen-space ray tracing. The technique commonly uses rasterization to compute visibility with the first visible surface from the eye or, ray origin and next saves the data in a Z-buffer. Ray tracing then replaces the raster shadows and reflections. Consequently, this approach simulates better visual effects such as reflection and refraction. In other words, real-time ray tracing doesn’t usually shoot the primary rays from the camera; instead, it uses rasterization to fill a depth and normal buffer. Then it uses the buffers to get a list of world-space positions to cast rays from (Unity).

Inline Ray Tracing: after the release of DXR Tier 1.0, developers who used DXR wanted more flexibility with the ray-tracing pipeline, which was improved with DXR Tier 1.1. This release included something called inline ray tracing. With this feature, rays can be generated without shader tables or the ray-tracing pipeline introduced in DXR Tier 1.0. This feature is available in any shader stage, including compute shaders and pixel shaders. Inline ray tracing uses the same acceleration structures as in DRT. It allows for simple ray-tracing tasks such as hard shadows without restructuring and/or adding a new pipeline which would have been the case when using DRT. Inline ray tracing is said to be faster in performance than DRT when performing jobs with low computations such as hard shadows, but it is assumed to run slower when the shader complexity is high.


Number of Ray Calculation

Calculation of total rays per pixel, or frame, or per second (for videos) is very easy, for example, if we shoot:

- $m$ rays per sample
- $n$ samples per pixel
- $o$ pixels per frame
- $p$ frames per second

The total number of rays per second will be $m\times n\times o\times p$. In real-time scenario, under very low ray count, we still requires billions of ray per second.

Biasness

Ray Tracing vs. Path Tracing

Resources and References

  1. Real-time rendering resources: All in one place
  2. Dr. Jacco Bikker’s tutorial series