An experimental real-time hybrid renderer leveraging a traditional rasterization pipeline for primary visibility alongside a Monte Carlo path-tracing compute pipeline for global illumination and advanced shading.
The renderer implements a 5-stage hybrid graphics pipeline powered by ModernGL. In computer graphics, rendering 3D scenes generally falls into two primary paradigms: Rasterization and Ray Tracing. A hybrid approach seeks to unify the strengths of both methodologies.
Rasterization is exceptionally fast, though its lighting and shading models rely on fundamental approximations. While advanced techniques—such as Disney's BRDF/BSDF models and texture sampling—enable rasterization to achieve Physically Based Rendering (PBR), reflections, refractions, and transmission, it cannot inherently compute Global Illumination (GI). Achieving GI in a purely rasterized pipeline necessitates precomputed lighting methods (e.g., Lightmaps, Light Probes, Irradiance Volumes, Voxel Cone Tracing, Radiosity) or screen-space approximations like Screen Space Global Illumination (SSGI).
Ray Tracing, conversely, models the physical behavior of light more accurately. By simulating the trajectory of light rays, ray tracing naturally achieves GI alongside numerous physically accurate optical effects. Advancing beyond basic ray tracing introduces Spectral Rendering, an even more precise simulation of light physics. This project synthesizes the performance of rasterization for primary visibility with the physical accuracy of ray tracing for illumination.
- 1. Geometry Pass (Rasterization): Rather than calculating primary ray intersections—a computationally expensive process—standard rasterization is employed to efficiently render the scene into a G-Buffer (Geometry Buffer). This G-Buffer functions as a multi-layered render target, storing precise surface attributes such as Global Position, Normal vectors, Albedo (base color), and Tangents, instead of final pixel colors.
- 2. Shading Pass (Compute Shader Ray Tracing): Leveraging the surface data preserved in the G-Buffer, Monte Carlo Ray Tracing is utilized to compute scene illumination. Rays are traced through the environment using a Shader Storage Buffer Object (SSBO)-backed Bounding Volume Hierarchy (BVH). While the camera remains stationary, the renderer accumulates sequential frames of these traced rays to resolve physically accurate soft shadows, reflections, and global illumination.
- 3. Denoising Pass: Due to real-time constraints limiting the number of rays traced per pixel per frame, the raw output exhibits significant stochastic noise. This is mitigated through a fast, multi-pass compute À-Trous edge-avoiding filter, which intelligently smooths the noise while preserving high-frequency geometric details and sharp edges.
- 4. Post-Processing Pass: To emulate real-world optical characteristics, several post-processing effects are applied. Temporal Anti-Aliasing (TAA) mitigates aliasing artifacts by accumulating historical frame data, Chromatic Aberration simulates lens color fringing, and Khronos PBR Neutral Tonemapping compresses the High Dynamic Range (HDR) lighting into a standard display color space.
- 5. Composite Pass: The finalized, post-processed frame is subsequently presented to the display.
- Advanced PBR Shading: The renderer implements a Principled BSDF material model (inspired by Disney's shading research) to accurately simulate light-matter interactions. This Physically Based Rendering (PBR) approach ensures that materials react realistically to lighting based on intuitive parameters such as Roughness, Metallic, Transmission (for dielectrics like glass), and Emissivity.
- Lighting System: Scenes are illuminated using a combination of analytic Point Lights and image-based HDRI Environment Maps. To optimize performance, the engine employs Importance Sampling. By calculating Probability Density and Cumulative Distribution Functions (PDF/CDF), the renderer prioritizes ray allocation toward dominant light sources, significantly reducing variance and computation time.
- Acceleration Structure (LBVH): As evaluating ray intersections against millions of triangles is computationally prohibitive for real-time applications, a Linear Bounding Volume Hierarchy (LBVH) is utilized. By assigning 30-bit Morton Codes (Z-Order curves) to each geometric primitive, 3D spatial data is mapped into a sorted 1D array. This enables rapid CPU-side construction of the BVH, which the GPU subsequently traverses to minimize ray-primitive intersection tests.
- Scene & Geometry Processing: The engine leverages
PyAssimpfor parsing standard 3D asset formats (e.g., FBX, OBJ). The ingestion pipeline automatically transforms meshes into world-space, computes missing Tangent vectors (essential for detailed normal mapping), and packs the geometry into an interleaved,std430-aligned Shader Storage Buffer Object (SSBO) for optimal GPU memory access. - AI-Powered High-Quality Denoising: In addition to the real-time À-Trous filter, users can invoke Intel Open Image Denoise (OIDN). This integration feeds the unresolved noisy image—supplemented with Albedo and Normal feature buffers—into a machine learning model to generate a pristine, artifact-free final render.
- Hardware Optimizations: On Windows systems equipped with hybrid graphics architectures (e.g., NVIDIA Optimus), Python applications frequently default to the integrated GPU. To circumvent this, the engine explicitly interfaces with the
nvapi64.dlldriver, heuristically prompting the operating system to allocate the high-performance discrete NVIDIA GPU.
- W, A, S, D, Q, E: Move Camera
- Arrow Keys: Rotate Camera
- 0: Path Tracing Mode (Default)
- 1-4: G-Buffer Debug Modes (Albedo, Normal, Position, Tangent)
- I: Denoise current frame with Intel OIDN
- Python 3.10+
- ModernGL, ModernGL Window, NumPy, Pyrr, OpenCV, PyOIDN, PyAssimp





