This raytracer was made with C/C++ and the framework SDL.
This image here show what happens when we have a constant for one axis. All of them appear grounded.
Here we have a bunch of them scattered around using random values for X, Y, Z.
And finally, this one shows what happens when we use some kind of interval for the X axis while keeping Y and Z free.
It definitely looks like magic, but it isn't. Maths gives us a helping hand here, let's dive in and see how.
First we have a camera that acts like a position from which we "see". A class is used for simulating a ray which comes from the camera position. We have our image dimensions and objects on the scene specified through code. Upon starting we iterate through all of the pixels and our ray goes through every one of them, also when entering a pixel which is occupied by and object we specify RGBA values and send them to a SDL Texture. This texture gives us the ability to set the color of a single pixel using the calculated RGBA values before that. I wanted to see how the image is drawn, because it is more exciting than just waiting for a result. Computation time varies on every machine and on specified image dimensions, objects on the scene and other settings.
This image helps visualise what is happening.
- C++ 17
- SDL version 2.0.16 stable
The major programming concepts used are classes, polymorphism, reading and writing to files and smart pointers. C++ is used for computation on the CPU and SDL for displaying the result in a separate window.
The vclib folder contains everything you need to run the project. No setup is required.
All you need to do is clone the repository and build and run the solution. Enjoy!