A C++ offline path tracer inspired by raytracing.github.io.
Current implementation includes deterministic renders with seeds, iterative path solving, JSON scene loading, PNG output, and performance counters for ray/intersection statistics.
- Path tracing renderer
- Configurable resolution, samples per pixel (spp), and max depth (with command line args)
- Iterative solver mode (non-recursive)
- Implemented BVH for faster ray-object intersection
- Scene loading from JSON file (
--scene) - Performance tracking (rays, tests, hits, ratios, speeds)
- Image export to PNG
- Multithreading with OpenMP
- No vtable or heavy use of pointers, data oriented design for better performance
xoshiro256**as RNG for better performance
Install a C++ 20 compiler, xmake, openmp system library, and fmt
Configure the build
$ xmake f -m release --perf_tracking=y --use_iterative_solver=yRun the program
$ xmake run rt --width <width> --height <height> --spp <spp> --max-depth <depth> --output <output_file.png> --scene <path_to_scene_json>For example,
$ xmake run rt --width 1920 --height 1080 --spp 1000 --max-depth 50 --output output-final.png --scene ../../../../scenes/book1-final.jsonSee examples in scenes/ to understand the scene file format
These images were rendered on a Dell latitude 7490, i5-8350U - 4 cores, 8 threads, 16GB RAM
Click to view detailed stats (First version) 1920x1080; 500SPP; MaxDepth 50
❯ xmake run rt --width 1920 --height 1080 --spp 500 --max-depth 50 --output render.png
Renderer: PathTracer
Samples per pixel (spp): 500
Resolution: 1920x1080
Intersector: LinearIntersector
Max depth: 50
Main seed: 42
Perf tracking: true
Iterative solver: true
50 / 1080 rows ( 4%) 26.92 s
100 / 1080 rows ( 9%) 58.74 s
150 / 1080 rows ( 13%) 1.89 min
200 / 1080 rows ( 18%) 2.72 min
250 / 1080 rows ( 23%) 3.67 min
300 / 1080 rows ( 27%) 4.95 min
350 / 1080 rows ( 32%) 6.34 min
400 / 1080 rows ( 37%) 7.61 min
450 / 1080 rows ( 41%) 9.17 min
500 / 1080 rows ( 46%) 10.84 min
550 / 1080 rows ( 50%) 12.78 min
600 / 1080 rows ( 55%) 14.42 min
650 / 1080 rows ( 60%) 16.25 min
700 / 1080 rows ( 64%) 17.95 min
750 / 1080 rows ( 69%) 20.10 min
800 / 1080 rows ( 74%) 21.78 min
850 / 1080 rows ( 78%) 23.15 min
900 / 1080 rows ( 83%) 24.67 min
950 / 1080 rows ( 87%) 26.25 min
1000 / 1080 rows ( 92%) 27.75 min
1050 / 1080 rows ( 97%) 29.19 min
1080 / 1080 rows (100%) 30.01 min
Render time: 30.01 min
Primary rays: 1036.80 Mray
Secondary rays: 1937.85 Mray
Total rays: 2974.65 Mray
Primary rays speed: 0.58 Mray/s
Secondary rays speed: 1.08 Mray/s
Total rays speed: 1.65 Mray/s
Avg bounces per primary: 1.87
Total hits: 2920.87 Mhits
Total intersection tests: 1446578.50 Mtests
Hit test ratio: 0.0020
Total time: 30.02 min
Click to view detailed stats (After implementing BVH) 1920x1080; 500SPP; MaxDepth 50
❯ xmake run rt --width 1920 --height 1080 --spp 500 --max-depth 50 --output render.png
Renderer: PathTracer
Samples per pixel (spp): 500
Resolution: 1920x1080
Intersector: LinearIntersector
Max depth: 50
Main seed: 42
Perf tracking: true
Iterative solver: true
50 / 1080 rows ( 4%) 708.92 ms
100 / 1080 rows ( 9%) 2.51 s
150 / 1080 rows ( 13%) 6.29 s
200 / 1080 rows ( 18%) 10.49 s
250 / 1080 rows ( 23%) 14.79 s
300 / 1080 rows ( 27%) 19.91 s
350 / 1080 rows ( 32%) 27.28 s
400 / 1080 rows ( 37%) 34.91 s
450 / 1080 rows ( 41%) 44.03 s
500 / 1080 rows ( 46%) 54.03 s
550 / 1080 rows ( 50%) 1.08 min
600 / 1080 rows ( 55%) 1.26 min
650 / 1080 rows ( 60%) 1.42 min
700 / 1080 rows ( 64%) 1.58 min
750 / 1080 rows ( 69%) 1.76 min
800 / 1080 rows ( 74%) 1.93 min
850 / 1080 rows ( 78%) 2.06 min
900 / 1080 rows ( 83%) 2.18 min
950 / 1080 rows ( 87%) 2.31 min
1000 / 1080 rows ( 92%) 2.43 min
1050 / 1080 rows ( 97%) 2.53 min
1080 / 1080 rows (100%) 2.60 min
Render time: 2.60 min
Primary rays: 1036.80 Mray
Secondary rays: 1934.19 Mray
Total rays: 2970.99 Mray
Primary rays speed: 6.65 Mray/s
Secondary rays speed: 12.41 Mray/s
Total rays speed: 19.06 Mray/s
Avg bounces per primary: 1.87
Total hits: 2014.89 Mhits
Total intersection tests: 72885.86 Mtests
Hit test ratio: 0.0276
Total time: 2.61 min
Render time: 2.61 min
Click to view detailed stats 1920x1080; 10000SPP; MaxDepth 50
xmake run rt --width 1920 --height 1080 --spp 10000 --max-depth 50 --output render.png --scene ../../../../scenes/book2-final.json
Loaded 9 textures, 10 materials, 3409 shapes
Renderer: PathTracer
Scene file: ../../../../scenes/book2-final.json
Samples per pixel (spp): 10000
Resolution: 1920x1080
Intersector: BVHIntersector
Max depth: 50
Main seed: 42
Perf tracking: true
Iterative solver: true
50 / 1080 rows ( 4%) 2.83 min
100 / 1080 rows ( 9%) 5.37 min
150 / 1080 rows ( 13%) 8.08 min
200 / 1080 rows ( 18%) 11.13 min
250 / 1080 rows ( 23%) 14.76 min
300 / 1080 rows ( 27%) 19.43 min
350 / 1080 rows ( 32%) 31.83 min
400 / 1080 rows ( 37%) 52.34 min
450 / 1080 rows ( 41%) 71.62 min
500 / 1080 rows ( 46%) 91.74 min
550 / 1080 rows ( 50%) 109.41 min
600 / 1080 rows ( 55%) 119.42 min
650 / 1080 rows ( 60%) 129.35 min
700 / 1080 rows ( 64%) 141.29 min
750 / 1080 rows ( 69%) 165.10 min
800 / 1080 rows ( 74%) 197.88 min
850 / 1080 rows ( 78%) 226.75 min
900 / 1080 rows ( 83%) 249.83 min
950 / 1080 rows ( 87%) 271.43 min
1000 / 1080 rows ( 92%) 287.61 min
1050 / 1080 rows ( 97%) 302.65 min
1080 / 1080 rows (100%) 310.78 min
Render time: 310.78 min
Primary rays: 20736.00 Mray
Secondary rays: 84415.96 Mray
Total rays: 105151.96 Mray
Primary rays speed: 1.11 Mray/s
Secondary rays speed: 4.53 Mray/s
Total rays speed: 5.64 Mray/s
Avg bounces per primary: 4.07
AABB hits: 3794499.16 Mhits
AABB tests: 6843367.36 Mtests
AABB hit ratio: 0.5545
Intersection hits: 412317.42 Mhits
Intersection tests: 916702.58 Mtests
Intersection hit ratio: 0.4498
Total hits: 4206816.58 Mhits
Total tests: 7760069.94 Mtests
Total hit ratio: 0.5421
Total time: 310.79 min
Render time: 310.79min
Click to view detailed stats 1920x1080; 500SPP; MaxDepth 50
$ xmake run rt --width 1920 --height 1080 --spp 500 --max-depth 50 --output render-checkered.png
Renderer: PathTracer
Samples per pixel (spp): 500
Resolution: 1920x1080
Intersector: BVHIntersector
Max depth: 50
Main seed: 42
Perf tracking: true
Iterative solver: true
50 / 1080 rows ( 4%) 591.38 ms
100 / 1080 rows ( 9%) 2.14 s
150 / 1080 rows ( 13%) 5.22 s
200 / 1080 rows ( 18%) 8.84 s
250 / 1080 rows ( 23%) 12.44 s
300 / 1080 rows ( 27%) 16.70 s
350 / 1080 rows ( 32%) 22.58 s
400 / 1080 rows ( 37%) 28.51 s
450 / 1080 rows ( 41%) 35.45 s
500 / 1080 rows ( 46%) 43.25 s
550 / 1080 rows ( 50%) 51.16 s
600 / 1080 rows ( 55%) 59.90 s
650 / 1080 rows ( 60%) 1.14 min
700 / 1080 rows ( 64%) 1.27 min
750 / 1080 rows ( 69%) 1.43 min
800 / 1080 rows ( 74%) 1.56 min
850 / 1080 rows ( 78%) 1.67 min
900 / 1080 rows ( 83%) 1.76 min
950 / 1080 rows ( 87%) 1.85 min
1000 / 1080 rows ( 92%) 1.95 min
1050 / 1080 rows ( 97%) 2.05 min
1080 / 1080 rows (100%) 2.12 min
Render time: 2.12 min
Primary rays: 1036.80 Mray
Secondary rays: 1992.48 Mray
Total rays: 3029.28 Mray
Primary rays speed: 8.15 Mray/s
Secondary rays speed: 15.66 Mray/s
Total rays speed: 23.80 Mray/s
Avg bounces per primary: 1.92
AABB hits: 36441.41 Mhits
AABB tests: 66357.47 Mtests
AABB hit ratio: 0.5492
Intersection hits: 2077.22 Mhits
Intersection tests: 6887.71 Mtests
Intersection hit ratio: 0.3016
Total hits: 38518.63 Mhits
Total tests: 73245.18 Mtests
Total hit ratio: 0.5259
Total time: 2.13 min
Render time: 2.13 min
Click to view detailed stats 600x600; 10000SPP; MaxDepth 50
❯ xmake run rt --width 600 --height 600 --spp 10000 --max-depth 50 --output cornell-box.png --scene ../../../../scenes/cornell-with-boxes.json
Loaded 4 textures, 4 materials, 18 shapes
Renderer: PathTracer
Scene file: ../../../../scenes/cornell-with-boxes.json
Samples per pixel (spp): 10000
Resolution: 600x600
Intersector: BVHIntersector
Max depth: 50
Main seed: 42
Perf tracking: true
Iterative solver: true
50 / 600 rows ( 8%) 1.20 min
100 / 600 rows ( 16%) 3.05 min
150 / 600 rows ( 25%) 5.33 min
200 / 600 rows ( 33%) 7.49 min
250 / 600 rows ( 41%) 9.66 min
300 / 600 rows ( 50%) 11.77 min
350 / 600 rows ( 58%) 13.95 min
400 / 600 rows ( 66%) 16.13 min
450 / 600 rows ( 75%) 18.06 min
500 / 600 rows ( 83%) 20.08 min
550 / 600 rows ( 91%) 21.87 min
600 / 600 rows (100%) 22.78 min
Render time: 22.78 min
Primary rays: 3600.00 Mray
Secondary rays: 20743.51 Mray
Total rays: 24343.51 Mray
Primary rays speed: 2.63 Mray/s
Secondary rays speed: 15.18 Mray/s
Total rays speed: 17.81 Mray/s
Avg bounces per primary: 5.76
AABB hits: 271574.06 Mhits
AABB tests: 405733.53 Mtests
AABB hit ratio: 0.6693
Intersection hits: 25157.91 Mhits
Intersection tests: 158365.44 Mtests
Intersection hit ratio: 0.1589
Total hits: 296731.97 Mhits
Total tests: 564098.97 Mtests
Total hit ratio: 0.5260
Total time: 22.78 min
Render time: 22.78 min



