Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Nuno-Jesus/42_miniRT

A small version of a Ray Tracer implemented in C
https://github.com/Nuno-Jesus/42_miniRT

42 42-minirt 42born2code 42cursus 42porto 42portugal 42projects 42school c-programming graphics-programming optimization raytracer raytracing

Last synced: 7 days ago
JSON representation

A small version of a Ray Tracer implemented in C

Awesome Lists containing this project

README

        

# **miniRT**
This project was graded 125/100.

## 📝 **Authorship**

- [Mario Henriques](https://github.com/maricard18) ([**maricard**](https://profile.intra.42.fr/users/maricard))
- [Nuno Jesus](https://github.com/Nuno-Jesus) ([**ncarvalh**](https://profile.intra.42.fr/users/ncarvalh))

## đŸ§Ŧ **Cloning**

This repository uses a **git submodule**, a git repo nested in this one (the **libnc** folder). By default, cloning this repo will ignore the submodule, which comes out as an empty folder. To successfully clone both, use this command

```shell
git clone --recurse-submodules https://github.com/Nuno-Jesus/42_miniRT.git
```

## 📒 **About**
Rendering a 3-dimensional image can be achieved using Ray Tracing, an expensive technique, which is based on casting rays from the camera into the space. If a ray intersects a shape, it illuminates it, based on both the shape's characteristics and also the environment around it as well.

This isn't an advanced Ray Tracer, since it's implemented in C, but it definitely is functional and has a bit of our own bonus in it too!

## **Mandatory Part**



Images











The mandatory part features:

- Map file parser
- Ambient and diffuse lighting
- Display of planes, spheres and cylinders
- Shapes intersections
- Hard shadows
- Ray tracing (without recursive steps)

## **Bonus Part**



Images











The bonus part features the mandatory and also the following:

- Phong Illumination Model (ambient + diffuse + specular)
- Checkerboarded planes
- Multi-spot lights
- Colored light sources
- Multithreaded rendering (our bonus)
- Interectable menu (our bonus)

## đŸŽĨ **Demo**

Here's a small demo with one of our maps.

https://github.com/Nuno-Jesus/42_miniRT/assets/93390807/7ef7cc40-ab9f-4611-bdaf-18cd1a157213

## 🚨 **Disclaimer**
At 42, the C projects are built following a bunch of rules that enforce good coding style, stated in a file called **Norminette**. Some of them are:

- No for, do while, switch, case or goto are allowed
- No more than 25 lines per function and 5 functions per file
- No assigns and declarations in the same line (unless static)
- No more than 5 local functions in 1 function
- No more than 4 parameters in 1 function
...

## đŸ“Ļ **Compilation**
To compile the mandatory part of the ray tracer you should run `make`.

This rule will generate a `miniRT` file, which is the zipped version of all the object files. Running `make bonus` will compile the bonus part of the ray tracer.

> **Note**
> The rules `make fast` and `make bfast` take advantage of parallel compilation to build the mandatory and bonus part, respectively.

To launch the executable you should follow this syntax...

```sh
$ ./miniRT scene_name
```

Where `scene_name` is the name of a file that represents the world map. The scene must have a `.rt` extension. You can find example scenes in the `scenes` folder.

> **Warning**
> On the macOS mlx version, the `mlx_destroy_display` function does not exist, which will cause a compilation error, unless you comment it (`world.c` and `world_bonus.c`)

## 🕹ī¸ **Controls**

Mandatory:
- **W** - increments the camera y coordinate
- **A** - decrements the camera x coordinate
- **S** - decrements the camera y coordinate
- **D** - increments the camera x coordinate

Bonus:
- **M** - toggles/untoggles the menu, which displays several other commands you can try

## 📚 **Resources**

- [Ray Tracing primitives and their intersections](https://hugi.scene.org/online/hugi24/coding%20graphics%20chris%20dragan%20raytracing%20shapes.htm)
- [Ray Tracing books](https://raytracing.github.io)
- [Ray Tracing and global illumination](https://digitalcommons.unf.edu/cgi/viewcontent.cgi?article=1100&context=ojii_volumes)
- [Cornell University Ray Tracing slides](https://digitalcommons.unf.edu/cgi/viewcontent.cgi?article=1100&context=ojii_volumes)

## đŸ’Ģ **Testing**

This project was tested using self-made tests.

## 📞 **Contact me**

Feel free to ask me any questions through Slack (**ncarvalh**).