Projet C++ minimal mais complet contenant :
- un ray tracer (ombrage direct avec ombres dures)
- un path tracer (Monte Carlo avec rebonds)
- primitives sphere + triangle
- BVH pour accelerer les intersections
- multithreading CPU sur les lignes d'image
- backend GPU OpenCL (modes ray et path, optionnel selon machine)
- antialiasing via
--samplessur ray et path - sortie PPM et PNG
- CMake >= 3.20
- Compilateur C++17 (MSVC, clang, gcc)
- Runtime OpenCL installe (pilote GPU) pour activer
--backend gpu
cmake -S . -B build
cmake --build build --config ReleaseRay tracing direct :
.\build\Release\ray_tracer.exe --mode ray --width 1280 --height 720 --samples 8 --threads 12 --backend auto --output ray.pngPath tracing :
.\build\Release\ray_tracer.exe --mode path --width 1280 --height 720 --samples 128 --depth 16 --threads 12 --output path.pngPath tracing GPU force :
.\build\Release\ray_tracer.exe --mode path --width 1280 --height 720 --samples 64 --depth 8 --backend gpu --output path_gpu.pngRay tracing GPU force :
.\build\Release\ray_tracer.exe --mode ray --backend gpu --output ray_gpu.pngImage de sortie au format PPM ou PNG (PNG actif sur Windows).
Options principales :
--threads <int>: nombre de threads CPU--backend <auto|cpu|gpu>: selection backend--samples <int>: antialiasing / samples per pixel (ray + path)--output <fichier.ppm|fichier.png>
include/rt/: coeur math/geo/camera/materialssrc/ray_tracer.cpp: rendu ray tracersrc/path_tracer.cpp: rendu path tracersrc/gpu_ray_tracer_opencl.cpp: rendu GPU OpenCL (ray + path)src/scene.cpp: scene de demosrc/main.cpp: CLI
- Le backend GPU est optimise avec contexte OpenCL persistant et generation des rayons cote kernel.
- Le mode
pathest multithread CPU et plus couteux en temps de rendu. - Le BVH est applique avant rendu pour reduire le cout des tests d'intersection.
- La scene de demo contient maintenant des triangles en plus des spheres.
Script de benchmark:
powershell -ExecutionPolicy Bypass -File .\scripts\benchmark.ps1 -Threads 12Options utiles du script:
-Runs 5(ou plus) pour moyenne + ecart-type-OutDir .\bench_outputs
Sorties:
- Images dans
bench_outputs/ - CSV dans
bench_outputs/benchmark_results.csvavecavg_ms,std_ms,min_ms,max_ms,speedup_vs_cpu
Remarque importante:
- Sur cette scene de demo, le backend GPU peut etre plus lent que le CPU a cause des transferts host/device et d'un kernel encore simple.