Luz: A C++20 Path Tracer Built from Scratch
Luz is a high-performance C++20 path tracer developed from scratch without the use of third-party libraries. It implements Monte Carlo path tracing and global illumination to produce photorealistic renders using a multithreaded CPU renderer.
Core Rendering Capabilities
Luz provides a comprehensive suite of rendering features designed for physical accuracy and efficiency. The engine supports a wide array of geometric primitives, including spheres, planes, rectangles, triangles, cubes, volumes, and OBJ meshes.
Materials and Lighting
To achieve realistic light interaction, Luz implements several material types and lighting models:
- Materials: Support for Lambertian (diffuse), metal, dielectric (refractive), emissive, and isotropic materials.
- Lighting: Support for area, point, sphere, and directional light sources.
- Sampling: The engine utilizes importance sampling with Probability Density Functions (PDFs) to reduce noise and improve convergence.
Advanced Visual Effects
Beyond basic ray tracing, Luz includes a post-processing and atmospheric pipeline:
- Atmospheric Simulation: Includes scattering effects for realistic sky and aerial perspectives.
- Camera Effects: Depth of field, antialiasing, exposure compensation, contrast adjustment, tone mapping, gamma correction, and bloom.
- Output Formats: Renders are exported as BMP and TIFF files.
Performance Optimization and Acceleration
Luz employs several technical strategies to maintain reasonable performance on CPU-based rendering.
BVH Acceleration
To handle complex scenes with many objects, Luz uses Bounding Volume Hierarchy (BVH) acceleration. This includes packed mesh BVHs constructed using binned Surface Area Heuristic (SAH) and near-first traversal to minimize intersection tests.
Adaptive Sampling and Denoising
To optimize render times, Luz implements adaptive per-pixel sampling. The engine renders a minimum number of samples (defined by --adaptive-min-samples) and then periodically checks luminance and RGB confidence intervals to determine if a pixel has converged. This prevents the engine from wasting computation on pixels that have already reached a stable color.
Additionally, Luz features an NFOR-style feature-buffer denoiser. This allows users to generate a denoised companion image (render_denoised.bmp), which is particularly useful for previews or reducing the total sample count required for a clean image.
Tooling and Integration
Luz is designed to be integrated into existing 3D workflows through custom scene files and external exporters.
Blender Integration
Luz includes a Python-based exporter that allows users to transfer scenes from Blender to the .luz format. This tool utilizes Blender's Python API to write the necessary scene files and export OBJ meshes for rendering within Luz.
Build and Benchmarking
The project is built using C++20 and can be compiled via Makefile or CMake 3.16+. For maximum performance, the build system defaults to -O3 optimization, -march=native for CPU-specific tuning, and link-time optimization (LTO).
Luz also includes a deterministic benchmark harness that provides detailed breakdowns of render, denoise, and post-process times, allowing developers to measure the impact of code changes on performance.
Community Perspective and Development
Developed by user martiano, Luz began as a personal project inspired by the "Ray Tracing in One Weekend" series. The author noted that while the project was initially coded without AI, AI tools were used for recent cleanup and feature additions.
Discussion among the developer community highlights the enduring appeal of building ray tracers as a "rite of passage" for graphics programmers. While some users noted that "without AI" has become a marketing hook similar to "written in Rust," others emphasized the conceptual simplicity and implementation complexity that makes ray tracing a rewarding technical challenge.
"Ray tracing is one of those problems that is conceptually so simple, yet continues to take so much mindshare because of all the challenges to implementation."
Technical Specifications Summary
| Feature | Implementation |
|---|---|
| Language | C++20 |
| Dependencies | Zero third-party libraries |
| Acceleration | BVH with binned SAH |
| Sampling | Monte Carlo / Adaptive |
| Denoising | NFOR-style feature-buffer |
| Compatibility | macOS, Linux, Windows |