Since Nvidia’s 2018 announcement of its 20-series RTX graphics cards, its killer feature, “ray tracing” has been a popular term in video gaming circles. But it can be difficult to understand what ray tracing is, how it works, and why it looks better than previous techniques.
What is ray tracing and how does it work?
In the real world when you see something, what you’re seeing is a photon from a light source. On its way to you, that photon may have been reflected by one or more surfaces. Each reflection changes the characteristics of the light that reaches your eyes.
The sun emits a broad range of colours of light, each surface absorbs some light and reflects others. What we see as a green surface, such as a leaf, it appears that way because it reflects mostly green light. If the light reflecting off the leaf hits another surface, such as a white wall, then that surface will look slightly different than it would if it was a pure white light shining on it. Each reflection affects every future surface that the light interacts with, changing its intensity and the visible colour.
Ray tracing is a graphical technique that follows the same principles. Rays of light are projected, the properties of the reflected and refracted light, such as colour are calculated, and the ray continues travelling.
In the real world every light source, such as a light bulb or the Sun, emits photons in all directions, the vast majority of which never reach your eyes. Simulating this would be an insanely intensive process that produces a mostly wasted result. To reduce the workload, ray tracing works in reverse, projecting rays from the camera. Each ray is allowed to travel a certain distance without reflection or reflect a certain number of times before the calculations are performed and the pixel value is set.
For example, a ray is cast from the viewer’s perspective, when it hits a white wall an algorithm recursively generates a reflected ray which then travels through a pane of blue glass, finally, the reflected ray hits a white light source and is absorbed. The blue glass absorbs all but blue light which casts a blue light on the wall, resulting in the pixel being coloured blue.
Why does Ray Tracing look so much better?
The standard method of rendering scenes in real-time involves using precomputed lightmaps and whole scene lighting. Some games make use of limited volumetric lighting to include moving light sources and to allow dynamic shadows, this technique is used sparingly though as it is quite processor-intensive.
Ray tracing can achieve a photorealistic result if some extra work is done in the game design stage. If all surfaces include details such as reflectivity, transparency and how the light will refract through them the overall outcome can appear more natural. While this approach obviously involves more work at the game design stage, it allows the result to appear photorealistic with light reacting the way it should when it reflects off concrete, metal, wood, and glass etc.
Ray tracing allows accurate reflections and shadows to be cast as part of the rendering process. in traditional rendering methods, both of these effects are entirely optional and can cause significant performance hits.
Ray tracing itself comes with a massive performance hit. Until Nvidia’s RTX graphics cards were announced with hardware acceleration for ray tracing, it was thought that the necessary processing power to perform ray tracing in real-time in software was more than a decade away. Even with the hardware acceleration, ray tracing still causes a significant decrease in performance as it is still the slowest part of rendering a frame.
Did this help? Let us know!