www.xbdev.net
xbdev - software development
Friday February 20, 2026
Home | Contact | Support | Computer Graphics Powerful and Beautiful ...
     
 

Physically-Based
Rendering

Lights and Rays ...

 



[TOC] Chapter 15: Light Transport III: Bidirectional Methods


Bidirectional methods are an advanced class of algorithms for simulating global illumination in ray tracing. These methods aim to efficiently compute light transport, especially in complex scenes where light paths are difficult to capture with simple techniques like path tracing.

In this section, we explore bidirectional methods, including the Path-Space Measurement Equation, Stochastic Progressive Photon Mapping, Bidirectional Path Tracing, and Metropolis Light Transport.

The Path-Space Measurement Equation


The Path-Space Measurement Equation (PSME) generalizes light transport by representing it as an integral over all possible light paths. It can be considered a more general form of the rendering equation, where we integrate over paths rather than points or rays.

The PSME is expressed as:

\[
I = \int_{\mathcal{P}} f(x_0, x_1, \dots, x_n) d\mu(x_0, x_1, \dots, x_n)
\]

where:
\( I \) is the measured light (radiance) from the scene.
\( \mathcal{P} \) is the space of all possible light paths.
\( f(x_0, x_1, \dots, x_n) \) is the measurement contribution function, which describes how light interacts along the path \( (x_0, x_1, \dots, x_n) \).
\( d\mu(x_0, x_1, \dots, x_n) \) is the differential measure on the space of paths, which considers how paths are sampled.

Intuition


Path-based methods aim to find contributions to the image by evaluating how light travels from light sources, through the scene, to the camera.

The PSME captures this process by considering all light paths and their associated contribution to the final image.

Example: Path Integral Sampling


function pathIntegralSampling(scenecameramaxDepth) {
    
let radiance 0;

    for (
let i 0maxDepthi++) {
        
// Generate a random light path from the light source
        
let lightPath sampleLightPath(scenei);

        
// Generate a path from the camera to the scene
        
let eyePath sampleEyePath(camerascenei);

        
// Compute contribution for this path
        
radiance += computePathContribution(lightPatheyePath);
    }

    return 
radiance maxDepth;
}


This function performs a basic path integral sampling, where we generate light paths and camera paths, then compute their contributions to the final image. This is the basis for more advanced bidirectional algorithms.


Stochastic Progressive Photon Mapping (SPPM)


Stochastic Progressive Photon Mapping (SPPM) is an extension of photon mapping, which uses stochastic (random) methods to progressively refine the photon map with each iteration. It is especially efficient for scenes with caustics, complex light interactions, or participating media.

SPPM Algorithm

1. Photon Tracing: Photons are emitted from the light sources and traced through the scene. They store their positions, directions, and flux in the photon map.
2. Photon Gathering: During rendering, rays are traced from the camera, and for each surface intersection, the nearby photons are gathered and used to estimate the incoming radiance.
3. Progressive Refinement: After each iteration, the photon density estimate is progressively refined, converging to the true light transport solution.

Example: Basic Photon Tracing


function tracePhotons(scenelightnumPhotons) {
    
let photonMap = [];

    for (
let i 0numPhotonsi++) {
        
let photon light.emitPhoton();

        while (!
photon.terminated) {
            
let hit scene.intersect(photon);

            if (
hit) {
                
photonMap.push({
                    
positionhit.point,
                    
directionphoton.direction,
                    
fluxphoton.flux
                
});

                
photon.scatter();
            } else {
                
photon.terminated true;
            }
        }
    }

    return 
photonMap;
}


In this example, we trace photons from the light source and store them in a photon map. Each photon interacts with the scene, and we store its position and flux at each intersection.


Bidirectional Path Tracing (BDPT)


Bidirectional Path Tracing (BDPT) combines ideas from both path tracing and photon mapping. In BDPT, we trace paths from both the light sources and the camera, then connect them to form complete light paths. This improves efficiency in capturing indirect lighting, particularly for challenging light paths such as caustics and specular-diffuse-specular interactions.

BDPT Algorithm


1. Light Path Sampling: A path is traced from the light source.
2. Camera Path Sampling: A path is traced from the camera.
3. Path Merging: The light and camera paths are connected at various points, forming a complete light path.
4. Contribution Calculation: The contribution of the connected path is calculated and added to the final image.

BDPT Path Contribution



The contribution \( C \) of a bidirectional path is:

\[
C = \frac{W_e(x_0, x_1) W_c(x_{n-1}, x_n)}{p(x_0, x_1, \dots, x_n)}
\]

where:
\( W_e(x_0, x_1) \) is the emission term from the light source.
\( W_c(x_{n-1}, x_n) \) is the camera importance term.
\( p(x_0, x_1, \dots, x_n) \) is the probability of generating the path.

Example: BDPT Light Path Tracing


function bidirectionalPathTracing(scenecameralightmaxDepth) {
    
let radiance 0;

    for (
let depth 1depth <= maxDepthdepth++) {
        
// Trace path from the light
        
const lightPath sampleLightPath(lightscenedepth);

        
// Trace path from the camera
        
const cameraPath sampleCameraPath(camerascenedepth);

        
// Merge paths and compute contribution
        
const pathContribution computePathContribution(lightPathcameraPath);

        
// Accumulate radiance
        
radiance += pathContribution;
    }

    return 
radiance;
}


This function traces paths from both the light and camera, then connects them to form complete light paths, calculating the contribution of each path.


Metropolis Light Transport (MLT)


Metropolis Light Transport (MLT) is a powerful method for solving the light transport problem by using a Markov Chain Monte Carlo (MCMC) algorithm to explore the path space. MLT excels at sampling difficult light paths, such as those involving multiple bounces, caustics, or intricate interactions between lights and geometry.

MLT works by mutating existing paths to generate new ones, ensuring that important areas of the scene are sampled more frequently.

MLT Algorithm


1. Initial Path Sampling: Start by generating an initial set of light paths using a standard path tracing method.
2. Path Mutation: Mutate the existing paths by slightly perturbing one or more vertices, creating a new path.
3. Acceptance or Rejection: Use the Metropolis-Hastings algorithm to decide whether to accept or reject the new path, based on its contribution to the final image.
4. Path Contribution Accumulation: Accumulate the contributions of accepted paths to the image, focusing more sampling effort on regions of higher contribution.

Example: MLT Path Mutation


function metropolisLightTransport(scenecameralightnumSamples) {
    
let radiance 0;

    
// Start with an initial path
    
let currentPath sampleInitialPath(cameralightscene);

    for (
let i 0numSamplesi++) {
        
// Propose a new path by mutating the current one
        
let newPath mutatePath(currentPath);

        
// Compute the acceptance probability
        
let acceptanceRatio computeAcceptanceRatio(currentPathnewPath);

        
// Accept or reject the new path
        
if (Math.random() < acceptanceRatio) {
            
currentPath newPath;
        }

        
// Accumulate contribution from the current path
        
radiance += computePathContribution(currentPath);
    }

    return 
radiance numSamples;
}


This example demonstrates the MLT algorithm, where we generate an initial path and then mutate it to create new paths. Each new path is accepted or rejected based on its contribution, and the final image is progressively refined.











Ray-Tracing with WebGPU kenwright WebGPU Development Cookbook - coding recipes for all your webgpu needs! WebGPU by Example: Fractals, Image Effects, Ray-Tracing, Procedural Geometry, 2D/3D, Particles, Simulations WebGPU Games WGSL 2d 3d interactive web-based fun learning WebGPU Compute WebGPU API - Owners WebGPU & WGSL Essentials: A Hands-On Approach to Interactive Graphics, Games, 2D Interfaces, 3D Meshes, Animation, Security and Production Kenwright graphics and animations using the webgpu api 12 week course kenwright learn webgpu api kenwright programming compute and graphics applications with html5 and webgpu api kenwright real-time 3d graphics with webgpu kenwright webgpu for dummies kenwright webgpu api develompent a quick start guide kenwright webgpu by example 2022 kenwright webgpu gems kenwright webgpu interactive compute and graphics visualization cookbook kenwright wgsl webgpu shading language cookbook kenwright WebGPU Shader Language Development: Vertex, Fragment, Compute Shaders for Programmers Kenwright wgsl webgpugems shading language cookbook kenwright WGSL Fundamentals book kenwright WebGPU Data Visualization Cookbook kenwright Special Effects Programming with WebGPU kenwright WebGPU Programming Guide: Interactive Graphics and Compute Programming with WebGPU & WGSL kenwright



 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2025 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.