MiTrace is a CPU-based path tracer written in C++20. It renders physically-accurate images by simulating light transport through GLTF scenes using Monte Carlo sampling. The renderer includes a Cook-Torrance BRDF, BVH acceleration, multi-threaded tile-based work distribution, and an optional real-time preview window. It's still work-in-progress so some rough edges are still there. ^^
![]() |
![]() |
- Cook-Torrance BRDF - GGX microfacet distribution, Schlick-Fresnel, Smith geometry masking, split diffuse/specular
- Russian-roulette path termination - configurable energy threshold to limit path depth
- Statistical firefly elimination - configurable threshold in standard deviations to clamp outlier samples
- Multi-threaded path tracing - work distributed across all CPU cores in configurable tiles
- BVH acceleration structure - SAH-based construction with configurable max triangles per leaf and max depth
- CPU affinity pinning - optional worker thread pinning for cache efficiency
- GLTF scene loading -
.gltffiles with multi-scene and multi-camera support - PBR textures - base color, metallic/roughness, normal maps, occlusion, emissive
- Point lights - with configurable radius and color/intensity
- HDRI / environment lighting - loaded from GLTF or CLI-overridden; supports rotation and separate primary/secondary intensity
- Export formats - PNG, JPEG, HDR
- Live preview window - optional GLFW + ImGui + OpenGL real-time preview (5 FPS refresh); compile-time optional via
ENABLE_PREVIEW_GUI
MiTrace follows a three-stage pipeline:
Reads .gltf files and extracts scene data: meshes, materials, textures, cameras, lights, and transforms. Produces intermediate loader types.
Converts loader types into a renderable scene: builds material cache, loads textures into memory, constructs BVH acceleration structures, and stores cameras/lights for path tracing.
Multi-threaded Monte Carlo path tracer. Distributes work via a tile queue across worker threads. Each thread:
- Generates primary rays from the camera
- Traces rays through the scene (BVH intersection tests)
- Evaluates materials and lighting at hit points
- Samples indirect illumination recursively
- Accumulates contributions to a shared render buffer
Live visualization during render via GLFW window + ImGui overlay. Periodically samples the accumulated render buffer and displays it at 5 FPS. Compile-time optional via ENABLE_PREVIEW_GUI CMake option.
Accumulated render buffer is tone-mapped and exported to PNG, JPEG, or HDR format.
All dependencies are fetched automatically by CMake via FetchContent.
| Library | Purpose |
|---|---|
| argparse | CLI argument parsing |
| nlohmann/json | GLTF JSON parsing |
| spdlog | Logging |
| GLM | Math (vectors, matrices) |
| stb | Image load/write |
| GLFW | Window/OpenGL context (preview only) |
| Dear ImGui | Preview UI (preview only) |
Requirements: CMake ≥ 3.16, a C++20-capable compiler, OpenGL development headers (for preview).
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel| Option | Default | Description |
|---|---|---|
ENABLE_PREVIEW_GUI |
ON |
Build the live preview window |
TARGET_ARCH |
native |
-march= target (e.g. x86-64, native) |
CMAKE_BUILD_TYPE |
Release |
Release / RelWithDebInfo / Debug |
Release and RelWithDebInfo compile with -Ofast -flto -march=<TARGET_ARCH>.
Debug compiles with -O0 -g -fsanitize=address,undefined.
The binary is written to build/MiTrace.
MiTrace <input.gltf> [options]
# Render cornell box at 1080p, 256 spp, with live preview
./build/MiTrace assets/tests/cornell_box_test/cornell_box.gltf \
-w 1920 -h 1080 -s 256 -b 8 \
-o outputs/cornell.png \
--previewOutput files that are not given an explicit name are auto-generated as outputs/render_<DDMMYYYY_HHMM>.png.
A Blender add-on for exporting scenes to GLTF in a format compatible with MiTrace is located in scripts/blender/mitrace_gltf_exporter/. A pre-packaged .zip for installation via Edit → Preferences → Add-ons → Install is provided at scripts/blender/mitrace_gltf_exporter.zip.
- Break up the golf scene to be uploaded as 2 files (size limit)
- Proper low-roughness non-metals
- Add skybox loading from GLTF file
- Generalize the Texture class
- Test the Blender exporter
- Skybox export
- Lights export
- Add mesh-level BVH
- Add multiple light types
- Improve the light selection algorithm
- Add bidirectional path tracing
- Add alpha (non-physical) transparency
- Add light bending on transparency
- Integrate OpenImageDenoise
- Move the tracer back to the tracer directory
- Add camera selection
- Add GLTF scene selection
- Add skyboxes
- Fix the light radius problem
- Add debug render modes
- Intersections: primary and total BVH and triangle tests
- Material: albedo, metallic/roughness, geometric normal, shading normal
- Contributions: direct only, indirect only, emission
- Random color: per mesh, per triangle, per bounding volume
- Other: bounces, depth, first-hit Fresnel/BRDF/PDF, reflected direction, pixel standard deviation


