Skip to content

procrastinator-101/minirt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

118 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MiniRT

MiniRT is a lightweight yet capable ray tracer inspired by classic graphics techniques. It explores the fundamentals of rendering, mathematics, and low-level programming by implementing a miniature 3D engine from scratch.

The project includes the core concepts used in real rendering systems: rays, intersections, lighting, shadows, reflections, and color blending.

πŸ–Ό Gallery

Here are some images rendered using Minirt:

Close Solar System

Close Solar System

Cone with Bump Map

Cone Bump Map

Cone with Checkerboard

Cone Checkerboard

Cylinder with Checkerboard

Cylinder Checkerboard

Fountain Scene

Fountain

Golf Scene

Golf

Plane with Wave Pattern

Plane Wave

Sphere with Bump Map

Sphere Bump Map

Sphere with Checkerboard

Sphere Checkerboard

Square with Checkerboard

Square Checkerboard

✨ Features

πŸ’‘ Lighting & Shading

  • Ambient, diffuse, and specular lighting (Phong model)
  • Multiple light sources with colors and intensities
  • Simple reflections

πŸ”Ί Geometry & Primitives

  • Planes
  • Spheres
  • Cylinders
  • Cones
  • Triangles
  • Cubes
  • Pyramids
  • Squares

πŸŽ›οΈ Rendering Techniques

  • Anti-aliasing (custom sampling factor)
  • Multi-threaded rendering
  • Texture mapping
  • Bump mapping
  • Procedural patterns:
    • Checkerboard
    • Waves
  • Skybox support

πŸ”Ή Overview

πŸ“Œ Key Areas

MiniRT combines several key disciplines:

  • ✨ Computer graphics fundamentals
  • 🧠 Vector mathematics and geometry
  • βš™οΈ C programming and memory management
  • πŸ” Numerical precision and debugging
  • 🎨 Scene construction and visualization

πŸ›€οΈ Rendering Pipeline

MiniRT demonstrates how light interacts with objects in 3D space and how mathematical equations translate into visual output. Although minimal compared to full-scale ray tracers, MiniRT captures the essential mechanisms used to build 3D worlds and provides full control over each step of the rendering pipeline.

This project illustrates how theoretical graphics concepts become a functioning rendering system.

πŸ“„ What It Processes

The program reads a .rt file containing:

  • A camera definition
  • One or more lights
  • Basic geometric shapes (sphere, plane, cylinder)

βš™οΈ How It Works

For each pixel:

  1. A ray is generated from the camera
  2. The ray is tested against all scene objects
  3. The closest intersection is selected
  4. Lighting, shadows, and surface color are computed
  5. The pixel is displayed through MiniLibX

🧩 Installation

MiniRT uses MiniLibX, which has different requirements depending on the operating system. Below are the steps for Linux and macOS.


🐧 Linux Installation

πŸ”§ Prerequisites

MiniLibX for Linux depends on X11, Xorg extensions, and zlib. Install them with:

sudo apt-get update && sudo apt-get install xorg libxext-dev zlib1g-dev libbsd-dev

πŸ“₯ Build

Clone the repository, then compile using the Linux flag:

make linux

This will:

  • Build MiniLibX from minilibx_linux/
  • Compile MiniRT with the LINUX=1 flag
  • Produce the miniRT executable

Run it with:

./miniRT scenes/example.rt

🍎 macOS Installation

πŸ”§ Prerequisites

For macOS, MiniLibX uses Cocoa and comes with its own .dylib. No extra packages are needed.

πŸ“₯ Build

Simply run:

make

This will:

  • Build the macOS version of MiniLibX from minilibx_macos/
  • Compile the final miniRT binary

Run MiniRT:

./miniRT scenes/example.rt

🧹 Cleaning

Standard cleanup:

make clean

Full cleanup (binary + MLX):

make fclean

Linux-specific cleanup versions are also available:

make clean_linux
make fclean_linux

πŸ” Rebuild

make re
make re_linux

πŸ–±οΈ Usage Guide

MiniRT supports interactive exploration of 3D scenes using the keyboard and mouse. Users can select cameras, lights, objects, and apply transformations or filters in real time.

πŸŽ₯ Camera Controls

Key Action
C Select the first scene camera
N Select next camera in the scene
P Select previous camera in the scene

Once a camera is selected, it can be rotated or moved:

Rotation:

Key Axis
1 / 7 Rotate around camera's v axis
2 / 8 Rotate around camera's u axis
3 / 9 Rotate around camera's v axis
4 / 6 Rotate around camera's w axis

Translation:

Key Direction
UP Move forward
DOWN Move backward
LEFT Move left
RIGHT Move right
+ Move up
- Move down

πŸ’‘ Light Controls

Key Action
L Select the scene first light
N Select next light in the scene
P Select previous light in the scene

Lights can be translated using the same arrow and +/- keys as the camera.

πŸ—οΈ Object Controls

Selecting Objects: Click on objects with the mouse to make them the current active object.

Rotation & Translation: Use the same rotation (1-9) and translation (arrow keys, +/-) controls as the camera.

Special Object Modes:

Key Object Action
O Cylinder Toggle caps (open/closed)
M Sphere Toggle static / interactive mode, updating texture mapping

πŸŽ›οΈ Filters & Anti-Aliasing

Filters:

Key Action
S Toggle sepia filter
A Select anti-aliasing (AA) as active object for adjustments

Anti-Aliasing (AA): After selecting AA with A:

Key Action
+ Increase AA factor
- Decrease AA factor

The factor is clamped between 1 and MAX_AA_FACTOR. Changing the factor triggers automatic re-rendering.

πŸ–±οΈ Mouse Interaction

  • Left click: Select objects in the scene.
  • The closest intersection to the camera determines the selected object.
  • Parent objects (e.g., squares or triangles that belong to cubes/pyramids) are automatically selected when clicking their subcomponents.

β›” Exiting

Key Action
ESC Exit MiniRT and close the window

πŸ“– Reference

For detailed information on the input files, scene format, and texture configuration, please refer to the man pages included with this project:

  • minirt(6) - Complete guide to using the minirt program and keyboard/mouse controls.
  • scene(5) - Specification of the scene input file and entity syntax.
  • texture(6) - Detailed explanation of texture types, their fields, and usage examples.

These man pages provide all the necessary information to correctly configure your scenes, textures, and object properties.

⚠️ Large Repository Size

Please note that this repository is relatively large. This is due to the inclusion of high-quality texture images, bump maps, and skybox images used for rendering in minirt. These assets are essential for achieving realistic visuals in the rendered scenes.

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors