LightSim3D - Project Details

Overview

LightSim3D is a GPU-accelerated rendering engine that uses CUDA for Monte Carlo path tracing and OpenGL for interactive display. It efficiently manages global illumination, soft shadows, and reflections with a fast BVH for ray-primitive intersection tests.

The engine supports direct light sampling and physically based rendering (PBR), enabling easy switching between effects like metallic and matte finishes. With dynamic camera controls and intuitive object rotation via keyboard and mouse, LightSim3D offers a responsive platform for real-time visualization and experimentation.

Features

Environment Lighting

LightSim3D creates realistic ambient lighting by enclosing the scene within a large sphere. This environment sphere is generated using a UV mapping technique that divides the sphere into horizontal rings and vertical sectors. Each vertex is calculated using spherical coordinates, and these vertices are then connected to form a mesh of triangles.

For every quad on the sphere’s surface, two triangles are produced to ensure complete coverage. The algorithm computes normals for each triangle and inverts them when necessary so that they face inward for accurate light emission. Material properties, such as emission and albedo, are assigned to these triangles, allowing the sphere to act as a natural light source that enhances indirect illumination and overall scene realism.

Environment Sphere Structure

Figure: UV-mapped sphere used as environment light source.

BVH Acceleration

LightSim3D employs a Bounding Volume Hierarchy (BVH) to organize scene geometry and reduce the number of intersection checks required for each ray. During construction, it computes an axis-aligned bounding box (AABB) for every triangle and partitions the scene by splitting along the axis of maximum extent in the centroid distribution. This recursive subdivision places small groups of triangles into leaf nodes and larger groups into internal nodes.

At runtime, ray-scene intersection tests traverse the BVH rather than iterating over all triangles. By quickly ruling out entire subtrees where the ray misses the node’s bounding box, the traversal performs far fewer intersection checks. This significantly boosts performance, especially in scenes with many triangles, by reducing complexity from linear in the number of triangles to approximately logarithmic.

Axis-aligned bounding box structure

Figure: BVH Visualization: Axis-Aligned Bounding Boxes.

Monte Carlo Path Tracing

LightSim3D uses a Monte Carlo path tracer that integrates both diffuse and specular reflection by accumulating the color contributions from many ray simulations per pixel. For each pixel, multiple rays are generated and their computed radiances are averaged to produce the final color. This accumulation over multiple samples reduces variance and converges toward a physically accurate result as the sample count increases.

For diffuse (matte) surfaces, the tracer uses cosine-weighted hemisphere sampling for scattered bounces and incorporates next-event estimation by directly sampling an emissive triangle. This technique minimizes noise in soft shadow regions by explicitly evaluating the contribution of light sources. Before adding the light’s contribution, a shadow (or occlusion) ray is cast from the hit point toward the light sample. If any geometry blocks this ray—detected via BVH traversal—the light contribution is discarded, thereby mimicking realistic shadow effects.

For specular (metallic) surfaces, a perfect mirror reflection model is applied along with Schlick’s approximation to compute Fresnel reflectance, smoothly blending the surface’s base reflectance with its metallic albedo.

Recursive evaluation of each ray—with Russian roulette termination to discard low-contribution paths—ensures that the integration across multiple bounces captures the complex interplay of light in the scene.

Ray reflection of different surfaces

Figure: Ray reflections on diffuse and specular surfaces.

Demo

The demos below present the same three‑cube scene rendered under two different material presets. In the matte view, you’ll notice realistic soft shadows and occlusion‑driven shading as each cube blocks light from its neighbors. In contrast, the metallic rendering treats every surface as a perfect mirror—there are no visible shadows, only crisp reflections of the surrounding environment sphere.

Matte Rendering

Matte Rendering

Metallic Rendering

Metallic Rendering

See the LightSim3D GitHub repository for source code, build instructions, and to try rendering your own custom models or scenes.