# Simple Ray Tracer - A physical-based path tracing in C A high-performance Monte Carlo path tracer written from scratch in pure C, featuring BVH acceleration, multiple importance sampling (MIS), Sobol sequences, and energy-conserving BSDFs. ## ✨ Features - **Pure C implementation** — zero external dependencies beyond Assimp for mesh loading and cglm for math - **BVH Acceleration** — SAH-optimized binary tree with per-ray traversal stats - **Multiple Importance Sampling** — combines BSDF and light sampling using the balance heuristic - **Next-Event Estimation** — direct lighting with directional lights and sky - **HDR Environment Lighting** — MIS-enabled sampling of HDR sky using precomputed CDFs. - **Sobol Quasi-Random Sampling** — fast convergence and low-discrepancy stratification - **Recursive Path Integration** — with Russian Roulette termination for energy conservation - **OBJ Support** — via Assimp for mesh import and material parsing (OpenPBR-compatible) ## 📸 Example Render Sponza rendered with 64 spp: ![preview](readme-assets/preview.png) Sponza rendered with 64 spp and hdri sky only: ![preview-hdri](readme-assets/preview-hdri.png) ## 🔧 Build Instructions ### Requirements - C compiler (GCC, Clang, MSVC) - OpenMP - CMake ### Build You can use the provided CMakeLists.txt to build the project. Just run the following commands in the root directory of the project: ```bash cmake -S . -B build ``` If you have powershell installed, you can run the build.ps1 script in project root directory. ## 🧠 Technical Breakdown ### BVH Acceleration - Built with Surface Area Heuristic (SAH) to reduce average traversal cost. - Debug counters log how many BVH nodes each ray touches, for profiling scene structure. ### Multiple Importance Sampling (MIS) - Balance heuristic weights BSDF and light sampling PDFs. - Supports both directional lights and sky light via next-event estimation. Produce noise-free renders with low sample counts. ### HDR Sky Lighting - Supports importance sampling of environment maps using a hierarchical CDF over solid angles. - Combined with MIS and BSDF sampling for noise-free global illumination, even with strong dynamic ranges. ### Sobol Sampling - 32D low-discrepancy sequences for camera rays, light sampling, and Russian roulette. - Faster convergence and lower variance than pure RNG at 64 spp. ### Materials (BSDFs) - Lambertian, and specular supported. - Designed to align with the OpenPBR material model. ### Path Tracing - Recursive, physically-based integration with energy conservation checks. - Russian Roulette applied adaptively after second bounce. ## 🚧 Roadmap - [x] AOV support (e.g. normals, albedo, depth) - [ ] Support for more complex materials (e.g. glass) - [ ] Standardize light unit - [ ] General speed improvements - [ ] Add GPU backend with CUDA - [ ] Support for glossy microfacet models (GGX) - [ ] Support for better diffuse models (Oren-Nayar) - [ ] Support for volumetric scattering (homogeneous media) - [ ] Light hierarchy for large emitter sets - [ ] Better multithreaded rendering - [ ] GUI frontend with real-time control