How Ray Tracing Works


Ray tracing is a rendering technique for more life-like lighting effects in a 3D scene. As the name suggests, each ray of light has its path traced from the camera to objects on screen and then to light sources. Traditionally, games use rasterization for calculating the lighting effects, where the image being displayed on screen is flattened into a 2D plane and the brightness of each pixel is calculated according to the amount of light hitting it. With ray tracing, there is a lot more involved such as reflections, refractions, chromatic aberrations, light scattering and more.

The most basic form of reflection, such as a mirror, would be by creating an inverse duplicate of the room being mirrored on the other side of an invisible wall. Anything more advanced isn’t possible with rasterization, which is why you’ll see things such as the scope of a rifle in Battlefield giving a very inaccurate rendition of the reflection of the world around you.

Games make use of further techniques for reflections such as cubemap reflections, but even these won’t give the most accurate lighting effects. With ray tracing, each pixel can be affected by light which has been manipulated an infinite number of times (although the more calculations involved, the slower the rendering will be done). For example, a light ray could hit a mirror and be reflected onto a glass of water, where is is refracted onto an ice cube, which refracts it onto the table, which is heavily diffused and finally ends on a book. The sky is the limit when it comes to possibilities.

All of these calculations mean that ray tracing has an incredibly large negative effect on performance. Finding Nemo took up to four days to render each frame, which is only displayed for 1/24 of a second when played back in real time. Such computational power is still not available for real time rendering today, so consumer graphics such as that being touted by NVIDIA at the moment with the upcoming GeForce RTX series make use of a watered down version. That said, the results are still orders of magnitude more realistic and impressive than anything achievable using rasterization.