Ray tracing is one of the most popular methods used in 3D computer graphics to render an image. It works by tracing the path taken by a ray of light through the scene, and calculating reflection, refraction, or absorption of the ray whenever it intersects an object in the world - hence the name.
For example, starting at a light source, we may trace a ray of light to a surface, which is transparent but refracts the light beam in a different direction while absorbing some of the spectrum (and altering the color). From here, the beam may strike another surface, which is not transparent and so the light undergoes both absorption (further changing the color) and reflection (changing the direction). Finally, from this second surface it may be reflected directly into the virtual camera, where its color contributes to the final rendered image.
Ray tracing's popularity stems from its realism over other rendering methods (such as scanline algorithms); effects such as reflections and shadows, which are difficult to simulate in other algorithms, follow naturally from the ray tracing algorithm. The main drawback of ray tracing is that it can be an extremely slow process, due mainly to the large numbers of light rays which need to be traced, and the larger number of potentially complicated intersection calculations between light rays and geometry (the result of which may lead to the creation of new rays). Since very few of the potential rays of light emitted from light sources might end up reaching the camera, a common optimization is to trace hypothetical rays of light in the opposite direction. That is, a ray of light is traced starting from the camera into the scene, and back through interactions with geometry, to see if it ends up back at a light source. This is usually referred to as backwards ray tracing.
Nonetheless, since its first use as a graphics technique by Turner Whitted in 1980, much research has been done on acceleration schemes for ray tracing; many of these focus on speeding up the determination of whether a light ray has intersected an arbitrary piece of geometry in the scene, often by storing the geometric database in a spatially organised data structure. Ray tracing has also shown itself to be very versatile, and in the last decade ray tracing has been extended to global illumination rendering methods such as photon mapping and Metropolis light transport.
Ray tracing in computer graphics derives its name and principles from a much older technique used for lens design since the 1900s. Geometric ray tracing is used to describe the propagation of light rays through a lens system or optical instrument, allowing the properties of the system to be modelled. This is used to optimise the design of the instrument (e.g. to minimise effects such as chromatic aberration) before it is built.
The principles of ray tracing for computer graphics and optical design are similar, but the technique in optical design usually uses much more rigorous and physically correct models of how light behaves. In particular, optical effects such as dispersion, diffraction and the behaviour of optical coatings are important in lens design, but are less so in computer graphics.
Before the advent of the computer, ray tracing calculations were performed by hand, but now they are common features of optical design software such as Zemax. A simple version of ray tracing known as ray transfer matrix analysis is often used in the design of optical resonators used in lasers.