Ray tracing, as a term, can be found in both computer graphics and physics. However, this blog post will only focus on the computer graphics part of it.
So then, what is ray tracing? Ray tracing is an umbrella term for a wide variety of image order algorithms. An image order algorithm iterates over the pixels in an image to produce it. Contrast that with the object order algorithms, that iterate over the objects in the scene in order to produce the final image. However, this is only half the story. The other half is how to produce the final image.
To produce the final image with ray tracing, a ray is computed for each pixel and sent into the scene. The computation of the ray is based on a virtual camera in the scene and a plane defined by the image itself. When the ray has been sent into the scene, it is tested for intersections with all objects in the scene. If the ray intersects an object, the color of the pixel can be calculated by some shading algorithm. If the ray intersects more than one object, make sure the closest object is used in the shading process. If it did not intersect an object, use a constant color, such as black, or a background image to calculate the color of the pixel.
So what should the shading algorithm do? Its purpose is to calculate the color of the pixel based on an intersection with an object. So it could do as little as return a constant color for a specific object, or it could do a lot more. The sky is the limit. However, a constant color is a good start. Once you’ve come this far, you can add lights to the scene and send so called shadow rays from the intersection point of the object to the lights. If there are no intersections between the two, the light hits the object and thus it can be seen from the virtual camera and shaded accordingly.
What is described above is often called ray casting. That is, rays sent from the camera into the scene, which are often called primary rays. From here it is possible to create other ray tracing algorithms, such as Whitted ray tracing, which sends secondary rays from the surface intersection point of the object in order to calculate reflections and refractions. There are many more variations out there, some using so called Monte Carlo methods, which essentially sends primary rays in seemingly random directions and calculates an average pixel color.