Added: - AOV support for normals, albedo, and depth marked as completed. - New function `normal_unpack` in `BSDF.h`. - New field `esp` in `ray_t` structure in `RayIntersection.h`. Changed: - Updated `normal_ts_to_ws` to accept an additional parameter. - Refactored `weight_nee_light` for clarity. - Modified `RAY_EPSILON` for improved precision. - Updated `path_output` structure to include a `normal` field. - Normalized unpacked normal vector in `normal_unpack` function. - Updated `path_trace` to use closest hit ray intersection. - Updated `render_aov` to utilize closest hit logic. - Modified `ray_create` to initialize `esp` based on ray origin. - Improved accuracy in `offset_ray_origin` calculations. - Updated ray intersection logic in `ray_intersect_triangle` and `ray_intersect_aabb` to include epsilon checks. - Updated `evaluate_bsdf_directional` and `evaluate_bsdf_const_sky` for shadow rays. - Adjusted `sample_bsdf_simple_lit` for incoming light direction calculations. - Enhanced `render_pixel` to manage AOV flags effectively. - Changed camera rotation and light intensity in `scene_setup`. - Simplified texture loading by removing unnecessary sRGB conversion. Modified: - Several binary image files have been updated.
77 lines
3.1 KiB
Markdown
77 lines
3.1 KiB
Markdown
# 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:
|
|

|
|
Sponza rendered with 64 spp and hdri sky only:
|
|

|
|
|
|
## 🔧 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
|