C++ Path Tracer from scratch with zero third-party libraries.
C++ Path Tracer from scratch with zero third-party libraries.
Luz is a C++20 Path Tracer developed from scratch with zero third-party dependencies.
It supports Monte Carlo path tracing, global illumination, BVH acceleration, adaptive sampling, denoising, atmospheric scattering, physically parameterized scene files, and a Blender-to-Luz exporter.
https://github.com/user-attachments/assets/7dc03485-9418-47af-a7e7-c4c4c53b6b70
.luzvol with optional VDB converter.luz scene filesBuild with the Makefile:
makeRender a bundled example scene:
./luz examples/scenes/cornell.luz --samples 50 --resolution 300x300The primary output is render.bmp, with render_denoised.bmp written by
default. Scene files can set outputfilename=..., and the CLI can override
common render settings. Use a .bmp, .png, or .tiff output path to select
the format.
The volumetric fog and godrays sample is:
./luz --file examples/scenes/volumetric_godrays.luz --threads 8Run the test suite:
make testRender procedural clouds with no extra assets:
./luz examples/scenes/procedural-cumulus-daylight.luz --samples 32 --resolution 960x540More presets and a layered cloudscape are in examples/scenes/.
Use --samples and --resolution to balance render time and quality.
For the Disney golden-hour hero, first follow the
volume import instructions
to create assets/volumes/wdas_cloud_half.luzvol, then render:
./luz examples/scenes/disney-cloud-golden-hero.luz --samples 32 --resolution 960x540Disney scenes need a separately downloaded dataset. Only the optional VDB converter requires OpenVDB; Luz itself has no third-party dependencies. See the cloud reference for customization.
Luz includes deterministic benchmarks for render, denoise, post-process, and overall score comparisons.
make benchmark BENCH_CPUS=1 BENCH_THREADS=1 > before.csv
make benchmark BENCH_CPUS=1 BENCH_THREADS=1 > after.csv
make benchmark-compare BEFORE=before.csv AFTER=after.csvFor details, see docs/benchmarks.md.
A CMake build is also available:
cmake -S . -B build
cmake --build build
ctest --test-dir buildSupported platforms:
On macOS and Linux, the Makefile is the primary path. On Windows, use CMake with MSVC or the MinGW-based Makefile target:
make windowsWSL is also supported as a Linux build environment.
Release builds are tuned for the machine doing the build by default. The
Makefile enables -O3, native CPU tuning with -march=native, and link-time
optimization with -flto. It also enables a fast floating-point mode where the
compiler/platform supports it. CMake uses the same release intent: -O3, native
CPU tuning, and interprocedural optimization/LTO when supported.
These defaults produce faster local renders, but binaries built with
-march=native may not run on older or different CPUs, and LTO can expose
toolchain-specific linker issues. If you hit an illegal-instruction crash,
linker error, or need a more portable binary, disable the aggressive options and
rebuild from clean objects:
make clean
make NATIVE=0 LTO=0For CMake builds, configure with the optimization toggles off:
cmake -S . -B build -DLUZ_NATIVE_OPTIMIZATIONS=OFF -DLUZ_ENABLE_LTO=OFF
cmake --build build --clean-first…TIFF output stores RGB as uncompressed 32-bit IEEE floating-point samples. Use
--output render.tiff --view-transform raw to preserve scene-linear ACEScg HDR
values above 1.0. Raw output is for debugging, measurement, and compositing data,
not normal viewing.
Luz scene units are controlled with meters_per_unit, and color values are
converted into scene-linear ACEScg before rendering. Numeric triples are ACEScg
values by default; use explicit functions for other sources:
color=srgb(0.8,0.2,0.1)
color=wavelength(550nm)
color=blackbody(3000K)
color=solar
color=reflectance(materials/red_paint.spd)Lights can be authored with physical quantities:
area_light softbox {
position=(0,3,0)
size=(2,1)
normal=(0,-1,0)
color=blackbody(3200K)
lumens=12000
}
directional_light sun {
direction=(-0.2,-1,-0.1)
color=solar
solar=1
}Cameras can use real lens controls:
camera main {
position=(0,1.5,5)
direction=(0,0,-1)
focal_length_mm=50
sensor_width_mm=36
sensor_height_mm=24
f_stop=2.8
focus_distance=4
shutter=0.0166667
iso=400
}The complete scene-file reference is in
docs/scene-files.md.
Adaptive sampling is enabled by default: --samples sets the maximum samples
per pixel, and converged pixels stop early. Lower --adaptive-threshold for
more detail, or use --no-adaptive to render every pixel at the full sample count.
See the scene-file reference for advanced settings.
Lower thresholds keep more detail and cost more time. For final renders, start with a high max sample count and tune with values like:
./luz exports/stormtroopers.luz --samples 4096 --adaptive-min-samples 512 --adaptive-check-interval 64 --adaptive-threshold 0.005Denoising is enabled by default. Luz's NFOR-style feature-buffer denoiser writes
a separate companion image: by default, render.bmp becomes
render_denoised.bmp; use --denoise-output PATH.EXT to choose the exact
path. Use --no-denoise or --denoise false to skip the companion render.
PNG output writes post-processed 8-bit RGB SDR images using stored DEFLATE blocks for dependency-free writing.
The denoiser has no hard minimum resolution or sample count, but it needs enough signal to estimate useful color and feature statistics. One sample per pixel is mainly a stress test: there is no per-pixel variance estimate, so the denoised image can look almost unchanged or can smooth the wrong details. Use at least a few samples per pixel for previews, and prefer roughly 16+ samples per pixel when judging denoiser quality. Very low resolutions also make evaluation misleading because each local filter window covers too much of the image.
Example scenes live in examples/scenes/. The scene-file format is documented in docs/scene-files.md.
Object paths in .luz files use the path provided by the scene: absolute paths are used as-is, and relative paths are resolved from the directory containing the .luz file. Keep large or generated OBJ assets local unless they are intentionally reviewed for inclusion.
OBJ meshes can be declared, transformed, and assigned named scene materials:
[materials]
material gold {
type=metal
preset=gold
roughness=0.15
}
[meshes]
mesh statue_mesh {
file=objects/statue.obj
}
[scene]
object statue {
mesh=statue_mesh
position=(0,0,0)
material=gold
}Blender scenes can be exported through Blender's Python API:
"/Applications/Blender.app/Contents/MacOS/Blender" -b scene.blend --python tools/blender_export_luz.py -- --output exports/scene.luz
./luz --file exports/scene.luz --threads 8The exporter writes a .luz file plus OBJ meshes. Usage and current fidelity
limits are documented in docs/blender-exporter.md.
…Special thanks to the Ray Tracing in One Weekend book series. It was a great source of inspiration and information during a big part of the development of Luz, specially since those were times before AI.
MIT. See LICENSE.
No open issues yet, or sync has not completed.