A simple 2D ray tracing simulation built using SDL3. This project visualizes rays emitted from a light source interacting with an obstacle (circle).
- Interactive light source (controlled via mouse)
- Multiple rays emitted from a single point
- Ray-circle intersection (basic obstruction)
- Real-time rendering using SDL3
- Clean modular structure (Ray, Circle, rendering functions)
| Ray Simulation |
|---|
![]() |
The simulation displays:
- A light source emitting rays in multiple directions
- A circular obstacle blocking the rays
- Rays stop when they intersect with the obstacle
- Language: C++
- Graphics Library: SDL3
Ray-Tracing-Simulator/
│
├── main.cpp
├── src/
│ ├── include/ # SDL headers
│ └── lib/ # SDL libraries
│
├── assets/
│ ├── demo.mp4 # demo recording
│ └── output2.jpg # screenshot
│
├── README.md
└── SDL3.dll #Linker
Rayclass → Represents individual raysCircleclass → Represents objects (light source + obstacle)setlines()→ Initializes rays with endpointsdrawlines()→ Handles ray rendering and collision logicdrawcircle1()→ Renders light sourcedrawcircle2()→ Renders obstaclemain()→ Entry point and event loop
- Rays originate from a source (first circle)
- Each ray is extended toward a random endpoint on screen edges
- If a ray intersects the obstacle (second circle), it stops at the intersection point
- Otherwise, it continues to its endpoint
- Rays are generated using multiple random endpoints
- No strict angular distribution yet
- Uniform angular distribution of rays (true radial emission)
- Ray reflection / bouncing
- Multiple obstacles
- Better collision precision
- Performance optimizations (spatial partitioning, etc.)
- C++ compiler (G++)
- SDL3 installed (include + lib folders)
g++ main.cpp -o main.exe -I src/include -L src/lib -lsdl3./main.exeSDL (Simple DirectMedia Layer) is a cross-platform library. It supports:
- Windows
- Linux
- macOS
- Mouse movement → Moves the light source
This project demonstrates:
- Basic ray casting principles
- Geometry (line-circle intersection)
- Real-time rendering
- SDL event handling
Even though ray tracing is often associated with game engines, this project is valuable for:
- Understanding graphics fundamentals
- Building problem-solving skills in geometry
- Strengthening low-level rendering knowledge
- Aditya Chauhan
Feel free to fork, modify, and extend this project 🚀
