Skip to content

Repository files navigation

Path-Tracer

What this project is:

This project is a fairly simple multithreaded reverse ray-tracing renderer, written in C++. It generates a series of random spheres, and uses the principle of path tracing to render an image of those spheres.

Sample Image

The above image is a sample image generated by the program. The four larger spheres you see are fixed and used to demonstrate the materials, whereas all the smaller spheres are randomly generated by the program. In its current form as some proof-of-concept toy code, the simulation only supports spheres as a shape, and accurately simulates the three main material types (Lambertian, Metal, and Dielectric).

The file PathTracer.cpp is the main file for this project.

Notes on the code.

The core vector object used for this simulation is the PhysicsVector object of my basic utilities library, and beyond that the design follows a fairly standard approach of dedicated classes to handle each shape, material, etc. Concurrency is achieved through use of a basic thread pool, allowing multiple rows of the output image to be calculated in parallel. One consequence of this is that rows tend to all finish processing at approximately the same time, meaning that the user display of remaining rows may appear to not be progressing, until several rows all compelete and print to the console at once.

The configuration of the simulation itself can be modified by a series of settings in config.txt, which are read into the program at runtime. These can be altered to make high or low quality images, change the position and orientation of the camera, change the number of spheres generated, etc. As the program runs, and after these values are read, the program instantiates the five set spheres (four larger ones visible in the sample image with a fifth acting as the ground), and then generates a series of random spheres on the ground around, in random positions and with random colours and materials. It then simulates reverse ray tracing, pixel by pixel, to determine the colour seen at a particular point in the output image.

Notes on Ray Tracing

This is just a brief summary on the method of reverse raytracing for those not familiar. In the real world, when we see an object, it is because light from a source collided with that object, was randomly scattered, and just happened to fly in the direction of our eyes. It hits our eyes and our brain translates that into an image. This is the process we are simulating to draw our image. However, if we simulate that process as it is, we would be wasting considerable resources simulating all the light rays which collide with an object, and don't go anywhere near our eyes. While this is happening all the time in reality (and the vast, vast majority of the time no less), if we want efficiency we should only select rays to simulate which will contribute to the final image. So instead of simulating rays from the light source, to the object (or objects), and then to our eyes; we reverse the process. We simulate the rays going out of our eyes and colliding with the objects. That way, we guarantee that every single ray we simulate will contribute to the final image. This reversing the process and simulating it is what reverse ray-tracing is.

About

A multithreaded path-tracing renderer which generates a collection of random spheres, and renders them. Supports opaque, reflective, and transparent spheres.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages