LightSim3D implements a complete rendering pipeline to load OBJ files, build an efficient BVH (Bounding Volume Hierarchy) for acceleration, and perform real-time path tracing using CUDA. The project features physically based rendering (PBR), direct light sampling, and interactive controls—all integrated with OpenGL for display.
- GPU-Accelerated Monte Carlo Path Tracing: Leverages NVIDIA CUDA to perform efficient Monte Carlo integration. By recursively tracing rays with random sampling (e.g., cosine-weighted hemisphere for diffuse surfaces and perfect mirror reflection for specular surfaces), the GPU handles complex global illumination effects—such as soft shadows, indirect lighting, and reflections—at interactive speeds.
- BVH Acceleration: Utilizes a bounding volume hierarchy for efficient ray-primitive intersection tests.
- Environment Lighting: Includes an encompassing environment sphere for realistic global illumination.
- Direct Light Sampling: Uses next-event estimation to directly sample emissive triangles, reducing noise and improving convergence when calculating direct illumination.
- Physically Based Rendering (PBR): Supports materials with adjustable albedo, metallicity, and emission.
- Rendering Effects: Switch between different material effects (e.g., metal, matte, default) via command-line arguments.
- Interactive Controls:
- Camera Movement: Use W/A/S/D keys to move, Space/Left Shift for vertical movement.
- Mouse Rotation: Rotate the scene with the mouse. Press Escape to unlock the cursor and Left Mouse Button to re-lock.
The demos below showcase a single scene composed of three cubes
rendered with different material effects, though users are free to render any objects of their choice. Notice how the matte rendering effectively mimics shadowing from occlusions, while the metallic surface is purely specular and fully reflects the environment lighting.
Matte Rendering Effect | Metallic Rendering Effect |
---|---|
![]() ![]() |
![]() ![]() |
- Prerequisites
- CUDA Toolkit: Ensure you have a CUDA-compatible NVIDIA GPU with the appropriate CUDA toolkit installed.
- OpenGL Libraries: Updated drivers and libraries to support OpenGL rendering.
- GLEW & GLFW: Required for context creation and window management.
- C++ Compiler: Supporting C++11 or later.
- Make: The project uses a Makefile for building in a Windows environment. Note: You may need to adjust local paths, particularly those related to the device compiler (nvcc), the host C++ compiler, and the CUDA Toolkit installation.
- Build
- Clone the repository:
git clone https://github.com/ron-che-debugger/LightSim3D.git cd LightSim3D
- Then simply run:
make
- (Optional) Use precompiled executable:
If you prefer not to build from source, you can use the providedexecutable
in a Windows environment.
- Clone the repository:
- Pre-rendering asset preparation
- LightSim3D employs global emission rendering—through its environment sphere—to deliver realistic lighting. To ensure accurate light contribution, all object faces must be outward-oriented.
The provided
fix_obj_normals.py
script pre-processes your OBJ files by:- Computing the object centroid.
- Determining face normals using fan triangulation.
- Flipping inward-facing faces to align with global emission sources.
Usage:python fix_obj_normals.py input.obj output.obj
- LightSim3D employs global emission rendering—through its environment sphere—to deliver realistic lighting. To ensure accurate light contribution, all object faces must be outward-oriented.
The provided
- Launch raytracer
- Launch with the required OBJ file path. Optionally, specify the window resolution and desired material effect:
./raytracer path/to/model.obj <width> <height> <effect>
- width and height: Set the window resolution (default is 800x600).
- effect: Choose the rendering effect—options include:
- metal: Fully metallic surfaces for a shiny appearance.
- matte: Purely diffuse surfaces with high roughness for a chalky look.
- not specified(default): A balanced material leaning toward metallic.
- Launch with the required OBJ file path. Optionally, specify the window resolution and desired material effect:
This project is licensed under the MIT License. See the LICENSE
file for details.