This project is based on Qt framework and DirectX math library.
In computer graphics, ray tracing is a technique for generating an image by tracing the path of light through pixels in an image plane and simulating the effects of its encounters with virtual objects. The technique is capable of producing a very high degree of visual realism, usually higher than that of typical scanline rendering methods, but at a greater computational cost. This makes ray tracing best suited for applications where the image can be rendered slowly ahead of time, such as in still images and film and television visual effects, and more poorly suited for real-time applications like video games where speed is critical. Ray tracing is capable of simulating a wide variety of optical effects, such as reflection and refraction, scattering, and dispersion phenomena (such as chromatic aberration).
It works by tracing a path from an imaginary eye through each pixel in a virtual screen, and calculating the color of the object visible through it. Each ray must be tested for intersection with objects in the scene. Once the nearest object has been identified, the algorithm will estimate the incoming light at the point of intersection, examine the material properties of the object, and combine this information to calculate the final color of the pixel.
Emit rays from each pixel
In order to render each pixel of the widget, the function paintEvent() provided by Qt should be overwritten. Then I use QPainter to set the color of the pixels.
The resolution of the picture is set to 600 * 600. So I map [0, 600] to [-1, 1] and calculate out the ray vector. The function EmitRay() will return the color of its pixel.
Recursive ray tracing
I trace the rays recursively for maxDepth times. It is undesirable to trace the rays infinitely since there are possible situations that the rays never end, considering two mirrors reflecting each other. The colors should be modulated according to the reflectiveness of its material.
classes designed for the objects in the scene:
classes designed for the materials of the objects in the scene:
Monte Carlo method to simulate color bleeding caused by diffuse reflection: