A set of C++ codes to render a scene using stochastic ray tracing.
This repository contains codes that can be used to :
- define a scene with objects having their own optical properties
- and render this scene (as an image) with stochastic ray casting
Each object can be a sphere, a triangular face, or a more complex object defined by a triangular mesh (i.e. an ensemble of triangular faces).
Ray casting 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. In our case, we use the recursive version of that algorithm where each cast ray generates refracted or reflected rays which will be taken into account to compute tje color of the pixel.
Here a brief and visual summary of the different features available in this code.
Each object can be illuminated in two ways :
- through direct lighting, i.e. with light coming from the light source
- through indirect lighting, i.e. with light reflected by intermediary objects
Direct lighting only | Direct & Indirect lighting |
---|---|
Also note the importance of the number of stochastic rays (N) in the monte-carlo integration and the influence it has on the quality of the rendered image.
4 rays | 2000 rays |
---|---|
Having a spatially extended light source (instead of a punctual one) causes shadows to be softer. In our case, we modeled that by considering that the light source was a sphere oy radius R_lum.
Expanded source, R_lum=2 | Expanded light source, R_lum=6 |
---|---|
There are several methods to implement anti-aliasing. We opted for one that consists in casting N rays from random positions inside each pixel instead of having all of them cast from pixel centers.
Without anti-aliasing | With anti-aliasing |
---|---|
Phong's smoothing is a technique that renders smoother meshes. It consists in interpolating, for each pixel, surface normals of triangular elements.
Without Phong's smoothing | With Phong's smoothing |
---|---|
To simulate blur in our images, we chose to model a pinhole camera, which are made of a lens and a shutter.
Default camera | Pinhole camera |
---|---|
To use this code, first make sure that you have a C++ compiler. Then, we advise you to use Visual Code Studio. You can open the project from Visual Studio Code using the Lancer de Rayon\Lancer de Rayon.sln
file.Finally, generate the solution and run the code to render the image that was defined in the Lancer de Rayon\Lancer de Rayon\Source.cpp
script.