## The Raytracer

The next project i want to showcase is the miniRT (mini-raytracer).
Like the shell, this was part of the 42 curriculum, and was achieved within the same rules and constraints as the previous project.

Again, the source code for this project is availiable here

This time, the assignment was to create a simple raytracer from scratch, using a custom wrapper around the linux X11 API, for simple window creation and I/O.

A raytracer is a program that uses a technique called "raytracing", which is a technique used to create realistic images digitaly. Raytracing essentially means that we simulate looking at a scene from our "eye-position", and use the computer screen like a window through which we look at this scene.

Now, we imagine shooting a perfectly straight "ray" from our "eye" through each pixel of the screen, and trace that ray's path to see if it will intersect with an object. If yes, we know that this specific pixel should display the color of the object that it hit. We repeat this process for each pixel. Using some math to check for lighting, shadows from other objects, distance and more, we can determine a final color for each pixel, and with that create a remarkably realistic image from our scene.

On top of the basic image generation, we added some extra feature that were not required by the subject, but seemed interesting enough to learn about and implement on our own.
Some of the extra features are:

- Multithreaded
- Textures and Bumpmaps
- Dynamic Scene/Texture/Bumpmap loading
- Menus with buttons and sliders
- Simple File-Explorer to load resources at runtime
- Diffrent Reflection Models
- Objects as Perfect Mirrors
- Skybox

This project was again a team effort, and my teammate Benjámin Szilas implemented a lot of functionality and features which where essential to the project. He is responsible for a lot of the tracing functions, and implemented features like shadows, mirrors, phong-reflection, multiple lights, anti-aliasing and much more.

I had a lot of fun with this project, and learned a lot about graphical programming, working as a team and (some) maths!

As a final note: since we finished the project, I was planning on showcasing it here, and so I have reimplemented the graphical part to use Raylib since it seemed more appropriate to use.

Again, I have provided a live version below, feel free to play around in it!

Credits go to noVNC for providing the web integration, their stuff is really great!

There two ways to run the app: either directly in your browser with the to WASM compiled program, or over a live noVNC connection to a running instance on the server. The raytracer itself is multithreaded, but since JS/WASM runs on a single thread the wasm version is very slow, and so i scaled down the resolution for that version in order to have it not run at -5 FPS.

Wasm Version (Raylib) VNC Version (noVNC)