Raytracing

Raytracing

Raytracing is a global illumination method , meaning Objects cast shadows and lit diffuse objects spread light on the objects around it. The original paper was written by Turner Whitted in 1980: An improved illumination model for shaded display .

It is done by sending rays of photons through the scene that can bounce off of objects. These rays form a ray tree, as one ray-hit can cause multiple new rays being spawned.

Forward Raytracing #

Shoot photons from the light into the scene and wait until some hit the camera. Drawback: Most photons will never hit the camera.

Backwards Raytracing #

Trace photons back thorough the pixel grid. For each hit, calculate the illumination (shadow rays) and color (more rays).

Shadow Rays #

Shadow Rays are rays, that are sent out from a surface hit towards a light, to check if it is visible from the light source or in shadow.

  • For non area lights, one shadow ray has to be sent out
  • For area lights, multiple rays have to be sent out (you could for example send rays towards every vertex of the light-casting mesh)

Diffuse Surfaces #

In theory you would have to sample light from all directions off a diffuse surface. This is because a diffuse surface would reflect light from every direction. What you can do about it:

  1. Randomly samlpe incoming light, which is then is averaged

  2. Stochastic methods for the reflection direction are chosen (this is also called Importance sampling)

Complexity #

Raytracing without bouces has a complexity of

raytracing_0a7f1acba8c44b44538f610771e763a1c4a997ed.svg

with:

  • raytracing_5df9548c84cdfee8b064111f28e72866eb974404.svg pixel count (1 ray per pixel)
  • raytracing_45093609f75ed8c0a71eb030e7b9d21f86e5c815.svg object count / polygon count

Every ray has to be tested against every object / polygon.

Improving the performance of Raytracing #

  1. Fewer Rays

    • adaptive ray-tree depth control (abort when influce drops)
    • better stochastic sampling
  2. Fewer Ray-Object intersections

  3. Faster Ray-Object intersections

Raytraced Phong Shading #

You could use the shadow rays for determining shadows and use the Phong Lighting way of calculating the fragment colors, removing the diffuse component when in shadow. In this case you would generally also not use the ambient component, because ambient light is used to fake global illumination, which is not necessary, because raytracing already gives us global illumination

Calendar October 22, 2023