A ray tracing renderer that creates photorealistic images from scene description files.
To compile the project using g++:
g++ -o main main.cpp lodepng.cpp object.cpp parser.cpp raytracer.cppOr simply use the included Makefile:
makeTo render a scene, run the executable with a .ray scene file:
./main scenes/basic.rayThe program will generate an output PNG image in the same directory as the input scene file.
The scenes/ folder contains several example scenes you can render:
./main scenes/basic.rayRenders spheres with reflective materials, a plane, and a mesh object.
./main scenes/teapot.ray./main scenes/scene_avec_refraction/refraction_front.rayDemonstrates light refraction through transparent objects from the front perspective.
Scene files (.ray format) use a simple text-based syntax to define the rendered image. Here's how to create your own:
# Set output image dimensions
Dimensions 640 480
# Camera perspective (like gluPerspective)
Perspective 30.0 1.33 3 20
# Camera position (like gluLookAt)
LookAt 1.2434 1.2533 9.8429 # eye position
0.6500 0.3000 -0.9843 # focus position
-0.0157 0.9921 -0.1243 # up vector
Materials specify the appearance of objects:
Material "materialName"
"ambient" [r g b] # Ambient color
"diffuse" [r g b] # Diffuse color
"specular" [r g b] # Specular highlight color
"emission" [r g b] # Emissive color
"shininess" 500.0 # Specular exponent
"reflect" 0.8 # Reflection factor (0-1)
Example - Red Reflective Material:
Material "red"
"ambient" [1.0 0.0 0.0]
"diffuse" [1.0 0.0 0.0]
"specular" [1.0 1.0 1.0]
"emission" [0.0 0.0 0.0]
"shininess" 500.0
"reflect" 0.8
PushMatrix
Translate x y z
Rotate angle axis_x axis_y axis_z
Scale sx sy sz
Sphere radius "materialName"
PopMatrix
Example:
PushMatrix
Translate -1.0 0.75 -1.75
Sphere 1.75 "teal"
PopMatrix
PushMatrix
Translate x y z
Rotate angle axis_x axis_y axis_z
Plane "materialName"
PopMatrix
Example - Ground Plane:
PushMatrix
Translate 0 -1.25 0
Rotate -90 1 0 0
Plane "white"
PopMatrix
PushMatrix
Translate x y z
Scale sx sy sz
Rotate angle axis_x axis_y axis_z
Mesh "materialName" "path/to/mesh.obj"
PopMatrix
Example:
PushMatrix
Translate -1.25 1.75 2.25
Scale 0.4 0.4 0.4
Rotate 90 0 1 0
Mesh "green" "meshes/icosahedron.obj"
PopMatrix
Mesh "materialName" [numFaces] [vertex indices] "P" [
x1 y1 z1
x2 y2 z2
x3 y3 z3
...
]
Example - Triangle:
PushMatrix
Translate 1.75 -1.25 2.5
Rotate -45 1 0 0
Mesh "yellow" [3] [0 1 2] "P" [
0 0 0
1 0 0
0 1 0
]
PopMatrix
Point lights illuminate the scene:
PointLight x y z
"ambient" [r g b] # Ambient light color
"diffuse" [r g b] # Diffuse light color
"specular" [r g b] # Specular light color
"attenuation" [const lin quad] # Light attenuation
Example:
PointLight 2 10 2
"ambient" [0.1 0.1 0.1]
"diffuse" [8.0 8.0 12.0]
"specular" [20.0 20.0 20.0]
"attenuation" [1.8 3.0 0.0]
Transformations work like OpenGL matrix operations:
PushMatrix/PopMatrix- Save/restore transformation stateTranslate x y z- Move objectsRotate angle axis_x axis_y axis_z- Rotate objects (angle in degrees)Scale sx sy sz- Scale objects
Educational project from the course IFT3355 - 3D Computer graphics.


