A little 3d pathtracer
this project is the 2nd graphical project at 42, the goal is to create a cpu raytracer using the mlx graphics library, the original subject only ask for a small raytracer, you will find here a extended version featuring pathtracing, texture mapping, multithreading, fully movable camera and runtime settings
all material are store in the ./scenes/material.rt file to add a new material simply add a new entry at the end, this is all the settings,
name | description | values |
---|---|---|
name | name of mat | string: "my-name" |
albedo | mat color | vec3: [0, 255] |
emission | emission power (color is same as albedo) | int: [0, +inf] |
roughness | 0 = relfective, 1 = not relfective | float: [0.0, 1.0] |
shininess | 0 = not shiny, 512 = very shiny | int: [0, +inf] |
specular coef | intensity of spec reflection | float: [0.0, 1.0] |
use checker | is the object affected by the checker grid | int: [0, 1] |
texture map | path for texture (leave '#' for null) | string: "./my-texture.ppm" |
normal map | path for normal map (leave '#' for null) | string: "./my-normal.ppm" |
(texture / normal maps need to be using .ppm format)
example: default 125,125,150 0.0 1 126 0.6 1 # #
files are using the .rt format
this is al B4C2 l possible entry with the option needed:
name | description | options |
---|---|---|
C | camera | vec3: position vec3:direction , int:fov [0, 180] |
A | ambiant light | float: ratio [0.0, 1.0] vec3:color [0, 255] |
L | light | vec3:position float: ratio [0.0, 1.0] vec3:color [0, 255] |
sp | sphere | vec3:position float: scale string:material name |
pl | plane | vec3:position vec3: normal string:material name |
cy | cylinder | vec3:position vec3: normal float: diameter float: height string:material name |
co | cone | vec3:position vec3: normal float: diameter float: height string:material name |
example map:
A 1 150,150,255
C 0.2,0,3 0,0,-1 70
L 0,1.5,2 0.2 241,120,57
sp 0,0,0 0.5 default
sp -2.1,0,-1 1 white
cy 0,1.1,0 0,1,0 0.3 0.8 blue
pl 0,-0.8,0 0,1,0 red
to interact with the object in the scene use the control panel to so.
the panel can be disable by settings
SHOW_BUTTON
to 0 inincludes/button.h
here is the available keybinds:
key | description |
---|---|
escape |
exit the program |
press right mouse button |
enter movement mode |
release right mouse button |
exit movement mode |
mouse movement |
move the camera direction (is movement is enable) |
wasd |
move the camera (only work if movement mode is on) |
0 |
reload the scene |
1 |
toggle grayscale filter |
2 |
toggle pixelate filter |
3 |
toggle invert filter |
4 |
toggle chromatic aberation filter |
5 |
toggle posterize filter |
6 |
toggle depth of field |
z |
toggle ambiant pass |
x |
toggle diffuse pass |
c |
toggle specular pass |
v |
toggle uv pass |
b |
toggle normal |
n |
toggle depth map pass |
k |
show camera settings |
f |
show frame render time |
r |
reset camera orientation |
g |
save render (.ppm format) |
+ |
increase number of bounce by 1 |
- |
decrease number of bounce by 1 |
r |
reset camera orientation |
all settings are up the top of the Makefile.
# ---------------------------------- window ---------------------------------- #
WIDTH = 480 # width of window
HEIGHT = 360 # hight of window
# --------------------------------- rendering -------------------------------- #
DEFAULT_BOUNCE = 10 # for better result set to hight value
SSAA_FACTOR = 1 # supersampling factor
# -------------------------------- preformance ------------------------------- #
MAX_THREAD = 4 # check your cpu for best value
MAX_RAM = 10 # max amount of RAM miniRT can take (a medium render is ~2GB)
# ------------------------------------- - ------------------------------------ #
/!\ super sampling can help making smother render, however expect a big performance drop
you will need to install the following packages
sudo apt-get update && sudo apt-get install xorg libxext-dev zlib1g-dev libbsd-dev
- clone the repo
git clone https://github.com/abidolet/miniRT.git miniRT
cd miniRT
- build using make
make
or make a debug build (which increase performance by decreasing render quality) run:
make MODE=debug
make clean
will remove .obj / .d filemake fclean
same as clean but also remove executable
to run the project, you will need a scenes/ folder inside must be a material.rt
file containing your materials
you also need a <scene-name>.rt
containing a valid scene
run miniRT:
./miniRT <scene>.rt
the project already has a few examples scene, to try you can run:
./miniRT scenes/<name>
available scenes are showcase.rt
, mirror.rt
, room.rt
, 42.rt
, lights.rt
differents pass |
---|
uv pass |
normal pass |
depth map pass |
more renders |
---|
with some filters apply |