Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

184 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

miniRT

A minimal raytracer built in C as part of the 42 school curriculum

image

Overview

miniRT renders 3D scenes defined in .rt files using raytracing techniques. The project implements basic geometric primitives, Phong lighting, and an interactive scene editor.

Features

Mandatory

  • Geometric primitives: spheres, planes, cylinders
  • Ambient and point lighting
  • Camera with configurable FOV

Bonus

  • Cones
  • Full Phong reflection model with specular highlights
  • Bump mapping via XPM textures
  • Checkerboard patterns
  • Multiple colored light sources

We wanted it

  • Real-time scene editing with GUI, keys and mouse

Building

make        # Build mandatory version
make bonus  # Build bonus version

Usage

./miniRT scenes/example.rt
./miniRT_bonus scenes/example.rt
./miniRT -h   # Display help

or simply

make demo
make demo_bonus

(see below the screenshots from the demo scenes)

Scene Format

Scenes are defined in .rt files with the following elements:

Element Syntax
Ambient A <ratio> <r,g,b>
Camera C <x,y,z> <dir_x,dir_y,dir_z> <fov>
Light L <x,y,z> <ratio> <r,g,b>
Sphere sp <x,y,z> <diameter> <r,g,b>
Plane pl <x,y,z> <normal_x,y,z> <r,g,b>
Cylinder cy <x,y,z> <axis_x,y,z> <diameter> <height> <r,g,b>
Cone co <x,y,z> <axis_x,y,z> <diameter> <height> <r,g,b> (bonus)

Controls

Key Action
N / P Select next/previous object
I/J/K/L Move object (forward/left/back/right)
U/H Move object (up/down)
↑/↓/←/→ Rotate object
V/B Decrease/increase radius
X/C Decrease/increase height
0-9 Quick color presets
Space Snap to grid
Left click Select object
Right click Point camera
Esc Exit (saves to snapshot.rt)

Dependencies

  • MiniLibX (cloned automatically)
  • X11 development libraries
# Debian/Ubuntu
sudo apt install libx11-dev libxext-dev

Authors


42 School Project — 2025

Examples

Colored spheres, cylinders and planes. Shadow casting from a single spot light.

image image image

The interior of shapes is also calculated. This is the camera and the light inside a cylinder that is inside a blue sphere, with yellow spheres as decoration.

image

The same three simple shapes aligned to form interesting artistic compositions.

image image

Colored lights and phong reflections

A blue light illuminating a white cylinder and a red sphere. The sphere appears totally dark. image

Phong reflections are correctly calculated; note how 3 lights reflect on the cylinder but only 2 on the sphere. image

These 5 light sources reflect off the plane and the base of the cylinder, creating an interesting shadow gradient. image

This demonstrates how light composition works naturally, with blue, green, and red lights creating white, magenta, cyan, and yellow. image

Extra shape: cone

image image

Color disruption: checkered pattern on spheres

image

Bump maps

A white sphere with a yellow light on top and a blue light below, with a bump map of the continents of the Earth. image

Bump maps and phong effects work correctly with multiple spot lights. image

Bump maps can also be applied to cones. image

About

Humble raytracer, part of the 42 curriculum

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages