www.xbdev.net
xbdev - software development
Wednesday February 5, 2025
Home | Contact | Support | Programming.. More than just code .... | Computer Graphics Powerful and Beautiful ...
     
 

Computer Graphics

Powerful and Beautiful ...

 


Path Tracing Lighting Models


Light is made up of colors (e.g., red, green and blue). As rays travel around a scene (akin to real light rays) - they bounce around and mix.

As rays travel through the scene - there are techniques used for calculating the light transport and rendering - each provide pros and cons to manage efficiency and realism.



Comparison of Models


Each model has its strengths and weaknesses, and modern rendering engines often combine them for optimal results.
Model Primary Principle Best For
Additive Accumulates light contributions Explicit light sampling, dark scenes
Multiplicative Attenuates light progressively Physically-based rendering, general use
Combined Additive-Multiplicative Combines attenuation with accumulated contributions Challenging lighting (caustics, indirect light)
Photon Mapping Photon density accumulation Caustics, complex light interactions
Bidirectional Path Tracing Combines additive & multiplicative models Difficult lighting scenarios, indirect and direct paths
Volumetric Models Integrates contributions in media Fog, smoke, water
Metropolis Light Transport Probabilistic path refinement Complex lighting, caustics
Light Tracing Traces from light sources Bright/directional lighting, caustics
Instant Radiosity Virtual point light sampling Approximate global illumination

Additive and multiplicative models are the two most popular models; with white light multiplicative models most commonly used in modern path tracing renderers, as it is more directly aligned with the principles of physically based rendering (PBR). This approach accurately simulates how light interacts with materials, including energy conservation, realistic reflections, and light attenuation. It forms the foundation of most unidirectional path tracers, where rays are traced from the camera and bounce around the scene. Then again, additive models are frequently used in other techniques like bidirectional path tracing (BDPT) or light tracing, where rays are traced both from the camera and from light sources. Additive methods are useful for scenes with difficult lighting conditions, such as caustics or dimly lit areas.

There are also cases when you can combine both additive and multiplicative models in hybrid solutions (like LuxCoreRender or V-Ray) these combined methods are used for specialized cases with challenging lighting conditions.


Example implementation that focuses on global illuminatio using path tracing - with one side using multiplication to combine co...
Example implementation that focuses on global illuminatio using path tracing - with one side using multiplication to combine colors and the other using addition to combine the colors (code/working implementation given in links at the end).



Compare the two main models (additive and multiplicative)
Aspect White Light (Multiplicative) Black Light (Additive)
Initial Light Starts at maximum intensity (white). Starts with zero intensity (black).
Light Interaction Attenuates light by multiplying BRDF. Adds light contributions via BRDF.
Direct Lighting Indirectly simulated. Can explicitly sample light sources.
Indirect Lighting Handled through recursive bounces. Gathered via recursive ray contributions.
Reflection Handling Multiplies reflected light color. Adds reflected light color.
Refraction/Transmission Simulates color filtering via attenuation. Adds transmitted light to the pixel.
Noise Higher noise in dark regions. Better convergence in dark areas.
Performance May require more samples to converge. Potentially faster convergence with MIS.


Path Tracing with White Light (Multiplicative Model)


Starts with a ray of white light (maximum intensity) emitted from the camera and progressively multiplies it by the reflective, transmissive, or emissive properties of surfaces encountered along the path.

C1 C2 C3 C4


When a ray strikes a surface, recursive rays are generated to simulate global illumination. These include reflected rays, which sample light bouncing off nearby surfaces, and refracted rays, which simulate light passing through transparent objects such as glass. Light contributions are categorized into direct and indirect light. Direct light refers to rays that directly hit an emitter, such as a light source or emissive object, while indirect light includes rays that bounce off multiple surfaces before reaching the emitter. This captures subtle effects like color bleeding, where light reflecting from one surface influences the color of others, and soft shadows that add realism to scenes.

Additionally, light tracing accounts for different types of reflections. Specular reflections occur on smooth surfaces like mirrors, where rays reflect in a single direction based on the surface normal, while glossy reflections appear on slightly rough surfaces, scattering rays within a small cone around the ideal reflection vector.

The multiplicative model also simulates refraction and transmission for transparent or translucent materials, using Snell's Law to determine the bending of rays as they pass through. Light intensity diminishes as it travels through materials due to absorption and scattering, as seen in colored glass, which filters specific wavelengths.

This physically accurate modeling of light behavior is advantageous for creating realistic visuals, particularly in scenes with complex interactions between light and materials.

However, challenges remain. As rays bounce off surfaces with low reflectivity or travel through absorbing media, their energy diminishes, making it difficult to trace paths effectively after several interactions. Additionally, achieving noise-free results can require significant computational resources, as many samples per pixel are needed to ensure convergence. This makes light tracing computationally expensive but highly effective for rendering scenes with intricate lighting details, such as caustics, global illumination, and soft reflections.

Pseudo-code example demonstrating the multiplicative model
function path_trace_multiplicative(raydepth):
    if 
depth MAX_DEPTH:
        return 
white_color  // Terminate recursion at max depth
    
    
hit_pointsurface_normalmaterialemitter trace_ray(ray)
    
    if 
hit_point is NULL:
        return 
black_color  // Return black if no hit

    # Direct lighting contribution (from light sources)
    
color sample_direct_light(hit_pointsurface_normalmaterial)

    
# Indirect lighting contribution (reflection or refraction)
    
reflection_ray reflect(rayhit_pointsurface_normal)
    
refraction_ray refract(rayhit_pointsurface_normalmaterial)

    
# Multiply the color by material's reflectance or transmission coefficient
    
color *= material.reflection_coefficient  // Multiply the light intensity

    # Trace the reflection and refraction rays
    
color += path_trace_multiplicative(reflection_raydepth 1)
    
color += path_trace_multiplicative(refraction_raydepth 1)

    return 
color

function sample_direct_light(hit_pointsurface_normalmaterial):
    
direct_light black_color

    
for each light_source in scene_lights:
        
# Calculate light intensity, shadow check, etc.
        
direct_light += compute_light_contribution(hit_pointlight_source)

    return 
direct_light


The key lines to notice are:
• Multiplication of light intensity by material properties (e.g., reflectance, transmission) at each surface interaction (
color *= material.reflection_coefficient
).
• Starts with white light (maximum intensity) and progressively attenuates the intensity as rays interact with materials.
• Recursive reflection/refraction follows the attenuation behavior of light as it bounces off surfaces.


Path Tracing with Black Light (Additive Model)


Starts with black light (zero intensity) at the pixel and adds contributions from light sources as rays gather light along their path. Each interaction with a surface adds the contribution of light reflected, transmitted, or emitted.

C1 C2 C3 C4


In this model, rays are traced backward from the camera, gathering light contributions recursively from reflections, refractions, and emitted sources. To prevent infinite recursion, methods like recursive depth limits or Russian Roulette termination are applied.

Direct light is explicitly sampled by tracing rays toward light sources, such as point, directional, or area lights, allowing efficient simulation of sharp shadows and specular highlights. Indirect light, on the other hand, is calculated by analyzing reflected rays and employing global illumination techniques like photon mapping.

These models handle reflections similarly to traditional multiplicative methods, but instead of attenuating energy, each interaction adds to the light intensity at the pixel level. This approach enhances the overall brightness and visual fidelity of the rendered image.

Refraction and transmission are also handled with precision in these models. Rays traversing transparent materials, like glass or water, add light intensity based on the material's transmission coefficient and the amount of light passing through the medium. This ensures that light contributions are accurately simulated for phenomena like caustics or color filtering.

The advantages of additive models include avoiding the "over-darkening" effect that occurs when light paths lose energy prematurely and excelling in scenarios like Bidirectional Path Tracing (BDPT), where rays are traced from both the camera and light sources. However, challenges remain. Over-bright regions can appear if proper normalization is not applied, and complex scenes with numerous light interactions may demand advanced sampling techniques for efficient convergence. Despite these hurdles, this approach provides robust and realistic results for scenes with intricate lighting, making it a powerful tool for high-quality rendering.

Pseudo-code example demonstrating the additive model
function path_trace_additive(raydepth):
    if 
depth MAX_DEPTH:
        return 
black_color  // Terminate recursion at max depth
    
    
hit_pointsurface_normalmaterialemitter trace_ray(ray)
    
    if 
hit_point is NULL:
        return 
black_color  // Return black if no hit

    # Direct lighting contribution (from light sources)
    
color sample_direct_light(hit_pointsurface_normalmaterial)

    
# Indirect lighting contribution (reflection or refraction)
    
reflection_ray reflect(rayhit_pointsurface_normal)
    
refraction_ray refract(rayhit_pointsurface_normalmaterial)

    
# Add the color contributions from indirect light
    
color += path_trace_additive(reflection_raydepth 1)
    
color += path_trace_additive(refraction_raydepth 1)

    return 
color

function sample_direct_light(hit_pointsurface_normalmaterial):
    
direct_light black_color

    
for each light_source in scene_lights:
        
# Calculate light intensity, shadow check, etc.
        
direct_light += compute_light_contribution(hit_pointlight_source)

    return 
direct_light


The key points about the pseudo code are:
• Accumulation of light at each surface interaction (
color += ...
).
• The function starts with zero intensity (black) and progressively adds light from direct and indirect sources.
• Recursion continues for reflections and refractions, adding light contributions for each bounce.

Examples



Another example of additive/multiplicative color summation from path tracing - but also including color.
Another example of additive/multiplicative color summation from path tracing - but also including color.


Taking it further - and to show more details - implement half the screen with add/mult (technically we subtract - but let's group add/sub and multiply into two groups - as they create linear or non-linear falloff curves).


Divide the screen with the same scene - left using multiplication and right using addition/subtract for the color summation.
Divide the screen with the same scene - left using multiplication and right using addition/subtract for the color summation.



Resources & Links


Minimal Working Example Additive/Multiplicative Color - Path Tracing/Global Illumination (Indirect Lighting)

Color Path Tracing Additive/Multiplicative

Screen Doubling (Repeating Split Screen) - for Sub/Mult Path Tracing Example

Screen Doubling (Repeating Split Screen) - for Add/Mult Path Tracing Example






















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.