/MiniRT

Primary LanguageC

miniRT

A program coded in My Skills in accordance with The Norm of 42 School.

Team project created by: Flavia & Mary Kate

πŸ“ Description

"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":

overview_example Graphics Library that was used: MLX42

πŸ‘€ Preview:

./miniRT scenes/icecream.rt HD:
icecream

./miniRT scenes/grape.rt HD:
grape

./miniRT scenes/dwarf.rt HD:
dwarf

./miniRT scenes/snowman.rt HD:
snowman

🎯 Mandatory requirements:

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:

    Scene decription file (scene.rt):

  • 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:

scene_map_explained πŸ’‘ TIP: You can create any scene you want, by following the above requirements and specified ranges for the numbers.

❗ Error Handling:

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]

⭐ Additional (bonus) features we added:

 1️⃣  Cone Object 🍦

  • 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: cone_description
  • You can notice the presence of cone for example in the icecream and dwarf scenes above in the Preview πŸ‘€.

 2️⃣  Colored Light πŸŽ¨πŸ’‘

colored_light_images

 3️⃣   Specular Reflection   πŸ”¦

"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.

specular reflection

 4️⃣   Soft Shadows   πŸŒ”

Here's an example of the soft shadows we added, vs the hard shadows that were asked in the mandatory part of the subject:

soft_shadows

 5️⃣   LIVE Movements of Camera, Light, Objects   πŸŽ₯

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 πŸš€ )

1. Translation and Rotation of the Camera πŸ“· :

camera_movement_gif

2. Translation of the Light πŸ”¦ :

light_movement_gif

3. Translation & Rotation of the Objects :

objects_movement_gif

 6️⃣   Dual Mode for Running the Program   πŸ”„

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 ⬇️.

 7️⃣   Randomized stars in the backround   🌌

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":

stars_and_rocket

βš™οΈ Installation

  1. Clone the repository:
git clone --recursive https://github.com/dendeaisd/MiniRT.git 
  1. Navigate to the project's directory:
cd MiniRT
  1. Compile the program:
make

πŸš€ Usage

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.

 1. For HD mode  πŸ–₯️

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

 2. For Interactive mode πŸ•ΉοΈ

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

πŸ“–  How to move the scene in the interactive mode:

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): movements_memo πŸ“Œ 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.

Examples:
  • C + +moves the camera in the z axis, giving the feeling of zooming in.
  • C + Wrotates 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 the scene.rt, in the z axis, bringing it closer to the camera.
  • 3 + Drotates the 3rd object (third in the scene.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.

πŸ™Œ  Acknowledgements