This project was graded 125/100.
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
git clone --recurse-submodules https://github.com/Nuno-Jesus/42_miniRT.git
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!
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)
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)
Here's a small demo with one of our maps.
miniRT.mp4
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
...
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
andmake bfast
take advantage of parallel compilation to build the mandatory and bonus part, respectively.
To launch the executable you should follow this syntax...
$ ./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
andworld_bonus.c
)
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
- Ray Tracing primitives and their intersections
- Ray Tracing books
- Ray Tracing and global illumination
- Cornell University Ray Tracing slides
This project was tested using self-made tests.
Feel free to ask me any questions through Slack (ncarvalh).