Skip to content
forked from 4n4k1n/42-miniRT

Distributed ray tracing engine with multi-threading, BVH acceleration, and physically-based rendering. Network rendering across multiple machines. Built in C.

Notifications You must be signed in to change notification settings

nweber23/miniRT

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

547 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

miniRT - Distributed Ray Tracing Renderer

    โ–ˆโ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—
    โ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ•šโ•โ•โ–ˆโ–ˆโ•”โ•โ•โ•
    โ–ˆโ–ˆโ•”โ–ˆโ–ˆโ–ˆโ–ˆโ•”โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•   โ–ˆโ–ˆโ•‘   
    โ–ˆโ–ˆโ•‘โ•šโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ•šโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ•‘   
    โ–ˆโ–ˆโ•‘ โ•šโ•โ• โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘ โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•‘   
    โ•šโ•โ•     โ•šโ•โ•โ•šโ•โ•โ•šโ•โ•  โ•šโ•โ•โ•โ•โ•šโ•โ•โ•šโ•โ•  โ•šโ•โ•   โ•šโ•โ•   

โšก A Lightning-Fast, Distributed Ray Tracing Engine

Render photorealistic images across multiple machines with multi-threading, BVH acceleration, and real-time camera control

42 School License: MIT Build Status PRs Welcome

๐Ÿš€ Quick Start โ€ข โœจ Features โ€ข ๐Ÿ“ธ Gallery โ€ข ๐Ÿ“– Documentation


๐ŸŽฌ See It In Action

๐ŸŒˆ Material Showcase

Lambertian, Metal, and Glass materials with realistic light interactions

Material Showcase

๐ŸŽจ Primitive Gallery

Spheres, planes, cylinders and cones

Object Showcase

๐Ÿ”ฅ 100,000 Spheres - BVH Acceleration

Rendering 100K objects at interactive framerates

100K Spheres

๐Ÿบ Mesh Support

Triangle-based mesh rendering with material support

Wolf Mesh


๐Ÿš€ Quick Start

Get rendering in 60 seconds:

# One-line installation
bash <(curl -L https://raw.githubusercontent.com/4n4k1n/42-miniRT/refs/heads/master/setup.sh)

# Build
make

# Run a demo scene
./miniRT scenes/demo.rt

๐ŸŒ Want to try distributed rendering?

# Terminal 1 - Master Node
./miniRT --master scenes/solar_system.rt --port 9000

# Terminal 2 - Worker Node (same or different machine)
./miniRT --worker 192.168.1.100 --port 9000

That's it! Press ENTER in the master terminal and watch your scene render across multiple machines.


โœจ Features

๐ŸŽฏ Core Rendering

  • ๐ŸŒŸ Physically-based ray tracing with global illumination
  • ๐ŸŽจ Advanced materials: Lambertian, Metal, Dielectric (glass)
  • ๐ŸŒˆ Soft shadows with adjustable sample counts
  • โœจ Anti-aliasing via Monte Carlo sampling (8-64 samples)
  • ๐Ÿ—ฟ Bump mapping for surface detail
  • ๐Ÿ”„ Recursive reflections/refractions

โšก Performance

  • ๐Ÿš€ Multi-threaded rendering (auto-detects CPU cores)
  • ๐Ÿ“Š BVH acceleration (500x faster on complex scenes!)
  • ๐Ÿ”ฅ Aggressive optimizations (-Ofast, LTO, SIMD)
  • ๐ŸŽฏ Cache-optimized data structures
  • ๐Ÿ“ˆ Real-time FPS counter

๐ŸŒ Distributed Computing

  • ๐Ÿ–ฅ๏ธ Master-Worker architecture for render farms
  • ๐Ÿ”€ Dynamic load balancing across workers
  • ๐Ÿ“ก Real-time camera updates broadcast to all nodes
  • ๐Ÿ”„ Fault-tolerant - workers can disconnect/reconnect
  • ๐ŸŽ›๏ธ Tile-based rendering (256x256 pixels)

๐ŸŽฎ Interactive Features

  • โŒจ๏ธ Real-time camera control (WASD + Arrow keys)
  • ๐Ÿ”„ Runtime toggles for AA and lighting
  • ๐ŸŽฌ Live preview as tiles complete
  • ๐Ÿ–ผ๏ธ Multiple rendering modes: Local, Master, Worker
  • ๐Ÿ“Š Performance monitoring

๐ŸŽฏ Why miniRT?

๐ŸŒ Traditional Ray Tracer โšก miniRT
Single-threaded Multi-threaded (all cores)
O(n) intersection tests O(log n) with BVH
Single machine only Distributed across network
Static camera Real-time camera control
Minutes per frame Interactive framerates

๐Ÿ“Š Performance Benchmark

Scene with 10,000 spheres at 1920x1080:

Without BVH: 0.01 FPS  (100 seconds per frame) ๐ŸŒ
With BVH:    5.00 FPS  (0.2 seconds per frame)  โšก

Speedup: 500x faster!

Scene rendered across 8 worker machines:

1 Worker:  60 seconds  (baseline)
2 Workers: 32 seconds  (1.88x faster) 
4 Workers: 17 seconds  (3.53x faster)
8 Workers:  9 seconds  (6.67x faster)

Near-linear scaling!

๐ŸŽจ Supported Primitives & Materials

๐Ÿ“ Geometric Primitives

  • โšซ Sphere (sp) - Perfect spherical objects
  • ๐Ÿ“ Plane (pl) - Infinite flat surfaces
  • ๐Ÿฅซ Cylinder (cy) - Finite cylinders with caps
  • ๐Ÿฆ Cone (co) - Conical shapes
  • ๐Ÿ”บ Pyramid (py) - Four-sided pyramids
  • ๐Ÿ”ท Triangle (tr) - For mesh support

๐ŸŽจ Material & Texture Types

Lambertian (Matte)

sp 0,0,0 2 255,100,100 L

Perfect diffuse surfaces

Metal (Reflective)

sp 0,0,0 2 255,255,255 M

Specular reflection

Glass (Dielectric)

sp 0,0,0 2 255,255,255 G:1.5

Refraction + reflection (IOR: 1.5)

Checker Texture

sp 0,0,0 2 255,255,255 L tx:checker:12

Procedural checker pattern

Bump Mapping

sp 0,0,0 2 255,255,255 L bm:assets/earth.png:1.0

Surface detail from image


๐ŸŽฎ Interactive Controls

๐ŸŽฏ Action โŒจ๏ธ Key ๐ŸŽฏ Action โŒจ๏ธ Key
Move Forward W Move Up Space
Move Backward S Move Down Shift
Move Left A Look Up โ†‘
Move Right D Look Down โ†“
Look Left โ† Look Right โ†’
Toggle Anti-Aliasing R Toggle Lighting L
Exit ESC - -

๐Ÿ“– Scene File Format

Create stunning scenes with our simple text format:

# Ambient lighting (intensity R,G,B)
A   0.15   255,255,255

# Camera (position orientation FOV)
C   0,1,5   0,0,0.5   70

# Light source (position brightness [R,G,B optional])
L   -5,8,3   0.8

# Sphere (center diameter R,G,B [material] [texture/bump])
sp  0,0,-1   1.2   255,255,255   L tx:checker:12

# Sphere with bump mapping
sp  3,0,-1   1.2   50,205,50   bm:assets/earth.png:1.8

# Glass/dielectric sphere
sp  0,3,-1.8   0.4   240,230,140   G:1.5

# Metal sphere
sp  -3,0,-1   1.2   255,255,255   M

# Plane (point normal R,G,B [material])
pl  -1,1,-40   0,0,1   200,200,255

# Cylinder (center axis diameter height R,G,B [material])
cy  3,4.5,11.5   1,1,0   0.7   7   139,69,19

# Cone (base_center axis diameter height R,G,B)
co  0,-3,12   0.23,1,0   3.1   11   205,133,63

Material Options:

  • L - Lambertian (diffuse/matte)
  • M - Metal (reflective)
  • G:index - Glass/dielectric (e.g., G:1.5)
  • tx:checker:scale - Checker texture
  • bm:path:scale - Bump mapping from image

Check out scenes/ for 15+ example scenes including:

  • ๐Ÿช solar_system.rt - Planetary configurations
  • ๐ŸŒˆ material_showcase.rt - All material types
  • ๐Ÿ”ฅ 10000_spheres.rt - BVH stress test
  • ๐ŸงŠ ice.rt - Ice cream cone scene

๐Ÿ› ๏ธ Installation

๐Ÿ“‹ Prerequisites

๐Ÿง Linux

sudo apt-get install \
  build-essential \
  cmake \
  libglfw3-dev

๐ŸŽ macOS

# Install Homebrew first
brew install \
  cmake \
  glfw

๐Ÿ“ฆ Build

git clone [repo]
cd miniRT
make

๐ŸŽ“ Architecture Overview

miniRT uses a sophisticated multi-mode architecture:

                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚   Command Line  โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                โ”‚            โ”‚            โ”‚
         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
         โ”‚ Local Mode  โ”‚ โ”‚ Master  โ”‚ โ”‚  Worker   โ”‚
         โ”‚   (Solo)    โ”‚ โ”‚  Mode   โ”‚ โ”‚   Mode    โ”‚
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                โ”‚            โ”‚            โ”‚
                โ”‚       โ”Œโ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”       โ”‚
                โ”‚       โ”‚ Network โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                โ”‚       โ”‚Protocol โ”‚
                โ”‚       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                โ”‚
         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
         โ”‚    Multi-threaded Render Loop    โ”‚
         โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”‚
         โ”‚  โ”‚   BVH    โ”‚ Ray Tracing  โ”‚     โ”‚
         โ”‚  โ”‚Traversal โ”‚   Pipeline   โ”‚     โ”‚
         โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ” Key Components

  • ๐ŸŽฏ Ray Tracing Pipeline - Recursive path tracing with material interaction
  • ๐Ÿ“Š BVH Acceleration - Hierarchical spatial indexing for fast intersection
  • ๐Ÿงต Thread Pool - Work-stealing multi-threaded rendering
  • ๐ŸŒ Network Protocol - Custom binary protocol for distributed rendering
  • ๐ŸŽฌ Real-time Updates - Camera changes broadcast instantly to all workers

๐Ÿ“š Detailed Architecture Documentation โ†’


๐Ÿ“Š Project Statistics

Metric Count
Lines of Code ~15,000
Source Files 80+
Supported Primitives 6
Material Types 3 (+bump mapping)
Example Scenes 15+
State Machine Diagrams 10
Network Message Types 7

๐Ÿค Contributing

We welcome contributions! This is a 42 School project, but improvements are always appreciated.

# Fork, clone, and create a branch
git checkout -b feature/amazing-feature

# Make your changes and test
make re
./miniRT scenes/demo.rt

# Submit a pull request

Guidelines:

  • Follow the 42 Norm
  • Test with multiple scenes
  • Update documentation
  • Add state machine diagrams for architectural changes

๐Ÿ“š Documentation

๐Ÿ“Š Architecture Diagrams

๐Ÿ” View State Machine Diagrams

๐ŸŒŸ Inspiration & Resources


๐Ÿ‘ฅ Authors

Developed at 42 School

4n4k1n nweber23


๐Ÿ“œ License

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


๐ŸŽฏ Troubleshooting

๐Ÿ”ง Common Issues

Build Issues

MLX42 build fails:

git clone https://github.com/codam-coding-college/MLX42.git
cd MLX42
cmake -B build && cmake --build build -j4
cd .. && make

GLFW not found:

# Linux
sudo apt-get install libglfw3-dev

# macOS
brew install glfw

Runtime Issues

Slow rendering:

  • โœ… Enable BVH (enabled by default)
  • โœ… Reduce anti-aliasing samples
  • โœ… Lower resolution for testing
  • โœ… Use distributed rendering

Worker can't connect:

  • โœ… Check firewall settings
  • โœ… Verify IP address: ./miniRT --worker localhost --port 9000
  • โœ… Ensure master is running first

โญ If you found this project helpful, please consider giving it a star!

Made with โค๏ธ at 42 School

๐Ÿ” Back to Top

About

Distributed ray tracing engine with multi-threading, BVH acceleration, and physically-based rendering. Network rendering across multiple machines. Built in C.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 97.7%
  • Makefile 2.2%
  • Shell 0.1%