CPU Ray Tracer

High-performance CPU-based ray tracer written in modern C++. Global illumination. Physically-based materials. Multi-threaded rendering pipeline.

Ray tracer architecture diagram showing light paths

CPU Ray Tracing Engine

In this project I focused on building CPU-based ray tracer in modern C++17 that simulates global illumination by tracing rays recursively through scenes composed of geometry, materials, and light sources. Built from the ground up without GPU acceleration.

The engine uses std::thread for parallelism with tiled rendering, BVH acceleration structures for fast ray traversal, and outputs high-quality PNG images via stb_image_write. Every pixel is calculated through Monte Carlo sampling to achieve photorealistic results.

Comparison of different lighting models and their effects

Advanced Material System

The renderer features a simple material pipeline supporting physically-based rendering (PBR) with metallic/roughness workflows. Materials include dielectric refraction for glass, basic procedural textures like marble and plasma, and specialized materials including iridescent, chrome, titanium, ice, and concrete surfaces.

Each material implements custom scatter() and emitted() functions with BRDF approximations. The system handles complex lighting interactions including colored lighting, soft shadows from area lights, and realistic surface properties.

Performance benchmarks and optimization results

Performance & Architecture

The core rendering loop builds scenes with camera setup, geometry definition, and BVH construction for spatial acceleration. Multi-threaded tile rendering distributes work across CPU cores, with each pixel receiving stratified sampling and recursive ray bouncing up to customizable maximum depth limits.

Various sampling techniques reduce noise while maintaining efficiency. The light manager handles direct lighting queries with shadow rays and BRDF sampling. A procedural skybox provides environmental lighting fallback for rays that miss geometry, creating more realistic ambient illumination.

Showcase of different material types and their properties

Geometry & Acceleration

The engine supports diverse geometric primitives including spheres, boxes, cylinders, cones, planes, and rectangles, all implementing the hittable interface with bounding box support. A Bounding Volume Hierarchy (BVH) provides logarithmic-time ray intersection testing for complex scenes.

The modular architecture separates the code into simpler parts with dedicated classes for cameras, rays, materials, lights, and geometry. Custom 3D vector math handles all point, color, and direction calculations. Gamma correction and color clamping ensure proper image output with support for both PNG and PPM formats.

Newest Render

This is the newest render. 6000 x 3000 px, 500 samples per pixel, 20 max bounces.

Newest high-quality render
Explore other projects