rAI is a real-time raytracer built with CUDA and OpenGL interoperability. It features progressive rendering, anti-aliasing, and depth of field effects. The engine supports both spheres and triangle meshes, and includes a physically-inspired material system with diffuse, specular, glossy, and emissive surfaces. Lighting includes a procedural sky with sun and ground gradients, and the final image is rendered in HDR with tone mapping.
Download for Windows: Download Link
A CUDA-capable NVIDIA GPU is required.
- CUDA Toolkit 11.0+
- CMake 3.15+
- C++20-compatible compiler
- NVIDIA GPU with CUDA support
The raytracer is built on CUDA-OpenGL interoperability, allowing us to render directly to an OpenGL texture. This setup allows us to:
- Create an OpenGL texture that can be displayed as an
ImGui::Imagein the viewport - Map this texture to CUDA memory for direct writing
- Launch a CUDA kernel with a 2D grid matching the image dimensions for parallel pixel processing
- Write rendered pixels directly to GPU memory without CPU transfer
The initial implementation focused on raytracing fundamentals:
- Camera-based ray generation
- Ray-sphere intersection
- Diffuse shading
- Simple lighting model
Camera controls (WASD and right-click drag) allow you to move around the scene and rotate the view. On the right panel, Save allows you to save the render as a png image.
Progressive rendering with frame accumulation reduces noise and improves visual fidelity. Over time, the image converges to a clean result. Clicking Render on the right panel freezes the camera controls and starts the accumulation process. Stop stops the accumulation and resets it. It also unfreezes camera controls.
Multi-sample anti-aliasing is achieved by jittering ray origins. Results are averaged to produce smooth edges. The Diverge Strength setting controls jitter intensity, acting like a blur.
Depth of field is implemented by perturbing ray directions across a virtual aperture and adjusting convergence at a configurable focal plane, producing realistic bokeh effects. This is controlled by the Defocus Strength and Focus Distance.
Mesh rendering was added to go beyond primitives:
- Ray-triangle intersection with backface culling
- OBJ file loading
- Bounding box acceleration for performance
Materials include:
- Mirror-like specular reflection
- Glossy highlights with adjustable roughness
- Emissive surfaces to simulate area lights
To support HDR lighting:
- Exposure control
- Gamma correction
- Tone mapping (Reinhard and ACES)
This project is released under the MIT License. See the LICENSE file for details.












