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:
-
Randomly samlpe incoming light, which is then is averaged
-
Stochastic methods for the reflection direction are chosen (this is also called Importance sampling)
Complexity #
Raytracing without bouces has a complexity of
with:
pixel count (1 ray per pixel)
object count / polygon count
Every ray has to be tested against every object / polygon.
Improving the performance of Raytracing #
-
Fewer Rays
- adaptive ray-tree depth control (abort when influce drops)
- better stochastic sampling
-
Fewer Ray-Object intersections
-
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