A high-performance, real-time GPU-accelerated ray tracer built using CUDA for kernel computations and rendered via OpenGL / GLUT.
- GPU Acceleration: Parallelized ray tracing model (one CUDA thread per pixel).
- Interactive Shading: Phong shading model including ambient, diffuse, specular, and rim lighting.
- Dynamic Lighting: Control the light direction dynamically using your mouse cursor.
- Soft Shadows & Reflections: Multi-sampled soft shadows via jittered rays and reflection bounce accumulation up to 5 bounces.
- Scene Customization:
- 4 Geometry Types: Independently toggleable Sphere, Box, Cone, and Cylinder.
- 5 Presets: Cycle presets using standard functions.
- Live HUD Overlay: Translucent panel displaying real-time FPS telemetry, camera position, and shape toggle states.
Ensure your environment has the following installed:
- NVIDIA GPU with CUDA support.
- CUDA Toolkit (>= 11.0) with
nvccavailable in your system path. - OpenGL/GLUT Library:
sudo apt install freeglut3-dev
- WSL Users: Make sure an X server (like VcXsrv or WSLg) is active, and your
DISPLAYvariable is set correctly.
To compile the primary application and the test suite, run:
makeIf your GPU has a different compute capability, edit the ARCH variable in the Makefile.
To find your GPU capability, build and run the check test:
make test-check && ./test/checkRun the main compiled binary:
./mainIf running under WSL without WSLg, ensure you export your display:
export DISPLAY=:0
./main| Control | Action |
|---|---|
| W / S | Move camera forward / backward (Z axis) |
| A / D | Move camera left / right (X axis) |
| Q / E | Move camera up / down (Y axis) |
| Mouse Move | Rotate light source dynamically |
| F1 | Toggle Sphere visibility |
| F2 | Toggle Box visibility |
| F3 | Toggle Cone visibility |
| F4 | Toggle Cylinder visibility |
| F5 | Cycle through scene presets |
| ESC | Quit application |
├── src/
│ ├── main.cu # Host orchestration, window setup, display loop, input handlers
│ ├── renderer.cuh # CUDA raytracing kernels, shading models, shadow/reflection calculations
│ ├── scene.cuh # Geometry intersection test functions (Sphere, Box, Cone, Cylinder, Triangle)
│ └── hud.cuh # OpenGL HUD overlay text rendering
├── test/
│ ├── check.cu # Verifies CUDA environment, prints device name and compute capability
│ ├── math.cu # Verifies CUDA kernel executions and host-device memory transfers
│ └── rgb.c # Verifies OpenGL/GLUT drawing canvas functionality
├── Makefile # Main build configuration file
├── .gitignore # Build artifacts and ignore configuration
└── README.md # Project user guide
You can test individual system components:
# Verify CUDA Device Detection
make test-check && ./test/check
# Verify CUDA Math Operations
make test-math && ./test/math
# Verify OpenGL Pixel Drawing
make test-rgb && ./test/rgb