A program coded in in accordance with The Norm of 42 School.
"The goal of this project is to generate images using the Raytracing protocol. Those computer-generated images each represent a scene, as seen from a specific angle and position, defined by simple geometric objects, and each with its own lighting system."
In simpler words, from a 'weird' .rt file, full of numbers that follow specific guidelines, we generate images, that represent the "scene" that the .rt file "describes":
Graphics Library that was used: MLX42
./miniRT scenes/icecream.rt HD
:
./miniRT scenes/grape.rt HD
:
./miniRT scenes/dwarf.rt HD
:
./miniRT scenes/snowman.rt HD
:
as specified in the Subject
βοΈ Handling of the three geometric objects: plane π, sphere π and cylinder π§¨.
βοΈ Management of all possible intersections of the objects.
βοΈ Resizing of the object's unique properties: diameter for a sphere, width and height for a cylinder.
βοΈ Implementation of Ambient and Diffuse lightning. (Ambient so that the objects are never in the dark.)
βοΈ Hard shadows and spot brightness.
βοΈ The program displays the image in a window, which can be closed by clicking either ESC or the red cross on the window's frame.
βοΈ The program must take as first argument a scene description file with the .rt extension:
- Each type of element in it can be separated by one or more line break(s).
- Each type of information from an element can be separated by one or more space(s), and/or tabs.
- Each type of element can be set in any order in the file.
- Elements which are defined by a capital letter (A,C,L) can only be declared once in the scene.
- Each element firstβs information is the type identifier (composed by one or two characters), followed by all specific information for each object in a strict order as follows:
π‘ TIP: You can create any scene you want, by following the above requirements and specified ranges for the numbers.
You can browse many cases of invalid scene files and run them according to the Usage π instructions, to check the Error messages we provide.
- Running the program with more than 3 arguments, or less than 2.
- Empty or unexisting .rt file
- Wrong extension of file, like
.txt
- Wrong element identifier (only
A
,C
,L
,sp
,pl
,cy
are accepted) - Duplicate or absent ambient lightning, camera or light
- Wrong number of arguments for some element(s) (for example, 8 numbers provided for the camera, instead of 7).
- RGB color values not in the integer range [0-255]
- Ambient Lightning Ratio not in the range [0-1]
- 3d normalized vectors with x,y,z axis not in the range [-1,1]
- Camera's field of view not in the range of [0-180] degrees
- Light brightness ratio not in the range of [0-1]
- The cone (with identifier
cn
) follows the pattern of the cylinder declaration, with only difference that the first x,y,z coordinates represent now the bottom of the cone: - You can notice the presence of cone for example in the
icecream
anddwarf
scenes above in the Preview π.
- We are parsing RGB color values for the Light (as shown above in the scene decription file explanation).
- Examples of rendered images with colored light:
"It's the reflection from a mirror-like surface, where parallel rays all bounce off at the same angle."
Our objects present specular reflection because they have smooth surfaces and thus don't have the imperfections that most objects in real life do, creating a clear and sharp reflection similar to that seen in mirrors. This effect enhances the realism and detail of the rendered objects, making them appear more lifelike.
Here's an example of the soft shadows we added, vs the hard shadows that were asked in the mandatory part of the subject:
We provide the option to interact LIVE with the Camera, Light and Objects so that you see directly the modification on the rendered image. (For "How to" check the corresponding section in Usage π )
In order for the LIVE movements (presented above) to be smooth, we needed a lightweight mode to run the program, so that we could see the modified (after every movement) image quickly. However, an interactive miniRT couldn't, of course, support the higher computational demands of soft shadows or a full HD window. That's why we decided to create 2 different modes for running the program, according to the needs every moment:
Mode π | Window size | Soft shadows | LIVE movements | Launching |
---|---|---|---|---|
1. HD mode π₯οΈ | 1920x1080 | β | β | ./miniRT scenes/grape.rt HD |
2. Interactive mode πΉοΈ | 800x600 | β | β | ./miniRT scenes/grape.rt |
πββοΈ For analytical info on how to run the different modes, check out the Usage π section below β¬οΈ.
That was an aesthetic addition, because in the absence of planes as background, there was an absolute black background which we wanted to "beautify", so randomized stars were our "solution":
- Clone the repository:
git clone --recursive https://github.com/dendeaisd/MiniRT.git
- Navigate to the project's directory:
cd MiniRT
- Compile the program:
make
You can run the program in 2 different ways, depending on what mode you want (check above the Dual mode for running the program π).
β For both modes, replace the <scene_of_your_choice.rt>
below β¬οΈ with the scene you choose from the scenes folder.
You need to give as third argument the HD
string and run it as follows:
./miniRT scenes/<scene_of_your_choice.rt> HD
which will open the bigger window mentioned in the Dual mode above, with the greater resolution and soft shadows.
Examples:
./miniRT scenes/snowman.rt HD
./miniRT scenes/grape.rt HD
You run the scene without any third argument:
./miniRT scenes/<scene_of_your_choice.rt>
This opens a smaller window, with hard shadows, where you can move LIVE the camera, objects and light, to see the changes directly, like it's shown above in the Live Movements Examples.
Examples:
./miniRT scenes/light_coloring/blue.rt
./miniRT scenes/icecream.rt
When you run the program, the terminal will output this information:
AVAILABLE KEYS TO USE
You can combine moving the Element that you want:
- C for Camera,
- L for Light,
- O for all Objects at the same time,
- 1, 2, 3, etc for each object individually,
with either:
- Arrow Keys,'+','-' for translation in x, y, z axis
or
- ADWSEZ for rotation in x, y, z axis, respectively
which means that you can combine holding one element key with one movement key (for either translation or rotation):
π Note that, the number keys can only be used if the scene has less than 10 objects, and the numbering of the objects follows the order of their declaration in the
scene.rt
file. If the objects are more than 9, use the O
key to move all objects at the same time.
C
++
: moves the camera in the z axis, giving the feeling of zooming in.C
+W
: rotates the camera in the y axis, giving the feeling of looking up.L
+βΆοΈ
: moves the light in the x axis, more on the right.O
+βοΈ
: moves all objects at the same time more on the left.1
+-
: moves the object, that is first declared in thescene.rt
, in the z axis, bringing it closer to the camera.3
+D
: rotates the 3rd object (third in thescene.rt
), in the x axis, making it "lean on" the right.
Notes regarding the movements:
β«οΈ Light can only be moved, not rotated.
β«οΈ Camera can not rotate in the z axis, nothing happens in that case.
β«οΈ Spheres are symmetrical so can not be rotated.
β«οΈ The planes are not moved when pressing O
so that the difference from before is visible, since they consist the "background" to the other objects.
β«οΈ The more the objects are, the more time it will take to see the movement if you use the O
key.
- The files
icecream.rt
andsnowman.rt
are borrowed from the oph-design/miniRT authored by oph-design and LaurinUB. - Special Thanks also to oph-design for the creation of our scene
dwarf.rt
π