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 7: Reflection Models


Reflection models are essential for simulating how light interacts with surfaces, capturing effects like glossiness, roughness, and metallicity to make materials appear realistic. They define the balance between reflected, refracted, and absorbed light, ensuring surfaces respond accurately to lighting in the environment.

Reflection Model Basics


Reflection models describe how light interacts with surfaces and determines the final color at a given point. These models take into account the physical properties of the surface and the incoming and outgoing light directions. A reflection model defines how light is reflected (or transmitted) when it hits a surface, and it influences the appearance of materials, like how shiny, rough, or matte they look.

The reflection equation (also known as the Bidirectional Reflectance Distribution Function, or BRDF) governs how much light is reflected from an incoming direction \(\mathbf{L_i}\) to an outgoing direction \(\mathbf{L_o}\) based on the surface properties:

\[
L_o(\mathbf{p}, \mathbf{\omega_o}) = \int_{\Omega} f_r(\mathbf{p}, \mathbf{\omega_o}, \mathbf{\omega_i}) L_i(\mathbf{p}, \mathbf{\omega_i}) (\mathbf{n} \cdot \mathbf{\omega_i}) d\mathbf{\omega_i}
\]

where:
\(L_o(\mathbf{p}, \mathbf{\omega_o})\) is the outgoing radiance at point \(\mathbf{p}\) in direction \(\mathbf{\omega_o}\),
\(f_r(\mathbf{p}, \mathbf{\omega_o}, \mathbf{\omega_i})\) is the BRDF that describes the reflection properties,
\(L_i(\mathbf{p}, \mathbf{\omega_i})\) is the incoming radiance at point \(\mathbf{p}\) from direction \(\mathbf{\omega_i}\),
\(\mathbf{n} \cdot \mathbf{\omega_i}\) is the cosine term accounting for the angle between the surface normal \(\mathbf{n}\) and the incoming light direction.

Specular Reflection and Transmission


Specular reflection is the perfect mirror-like reflection where the angle of reflection equals the angle of incidence. This is typically used for shiny surfaces such as polished metal, glass, or water.

For specular transmission, the ray passes through the surface, like in transparent materials such as glass or water, but it may change direction due to refraction (Snell's law).

Reflection (Perfect Mirror) Example in JavaScript


function reflect(directionnormal) {
    
// Reflection equation: r = d - 2 * (d . n) * n
    
return subtract(directionscale(normaldot(directionnormal)));
}

// Usage
const rayDir = [1, -10];
const 
normal = [010];
const 
reflectedRay reflect(rayDirnormal);
console.log(reflectedRay);  // Reflected ray direction


Snell's Law for Refraction (Transmission)


\[
\eta_i \sin \theta_i = \eta_t \sin \theta_t
\]

where \(\eta_i\) and \(\eta_t\) are the refractive indices of the two materials, and \(\theta_i\) and \(\theta_t\) are the angles of incidence and refraction, respectively.

Refraction Example in JavaScript


function refract(directionnormaleta) {
    const 
cosi = -dot(directionnormal);
    const 
cost2 1.0 eta eta * (1.0 cosi cosi);

    if (
cost2 0) return null;  // Total internal reflection

    
const scale(directioneta);
    const 
scale(normaleta cosi Math.sqrt(cost2));
    return 
add(tn);  // Refracted ray direction
}

// Usage
const incidentRay = [1, -10];
const 
normal = [010];
const 
eta 1.5;  // For glass, for example
const refractedRay refract(incidentRaynormaleta);


Lambertian Reflection


Lambertian reflection models the behavior of rough, diffuse surfaces. In this model, the light is scattered uniformly in all directions, which makes the surface appear equally bright from any angle.

The Lambertian BRDF is:

\[
f_r(\mathbf{p}, \mathbf{\omega_o}, \mathbf{\omega_i}) = \frac{\rho}{\pi}
\]

where \(\rho\) is the diffuse reflectivity of the surface (i.e., albedo).

Lambertian Reflection Example in JavaScript


function lambertianReflection(normallightDiralbedo) {
    
// The Lambertian reflection is just the cosine of the angle between the light direction and normal
    
const cosTheta Math.max(dot(normallightDir), 0);
    return 
scale(albedocosTheta Math.PI);  // Return the reflected color
}

// Usage
const normal = [010];
const 
lightDir = [01, -1];
const 
albedo = [100];  // Red surface
const reflectedColor lambertianReflection(normallightDiralbedo);
console.log(reflectedColor);  // Reflected light color


Microfacet Models


Microfacet models are used to simulate reflections from rough surfaces, where the surface is made up of tiny facets (microfacets) that reflect light like small mirrors. The reflection depends on the distribution of the microfacets and the shadowing and masking effects.

One common microfacet distribution is the Beckmann distribution, which models how microfacet normals are distributed across a rough surface.

The BRDF for the microfacet model is:

\[
f_r = \frac{D(h) F(\omega_i \cdot h) G(\omega_i, \omega_o)}{4 (\mathbf{n} \cdot \mathbf{\omega_i}) (\mathbf{n} \cdot \mathbf{\omega_o})}
\]

where:
\(D(h)\) is the normal distribution function (NDF) describing the distribution of microfacets,
\(F(\omega_i \cdot h)\) is the Fresnel factor,
\(G(\omega_i, \omega_o)\) is the geometric attenuation factor,
\(h\) is the half-vector between the incoming and outgoing directions: \(h = \frac{\omega_i + \omega_o}{|\omega_i + \omega_o|}\).

Example: Microfacet Reflection in JavaScript (simplified)


function microfacetReflection(wowinormalroughness) {
    const 
halfway normalize(add(wowi));
    const 
cosThetaH Math.max(dot(normalhalfway), 0);

    
// Beckmann distribution (simplified)
    
const Math.exp((cosThetaH cosThetaH 1) / (roughness roughness)) / (roughness roughness Math.PI);

    
// Fresnel term (Schlick approximation)
    
const fresnelSchlick(dot(halfwaywi), 1.00.04);  // assuming a dielectric material

    // Geometry term (simplified)
    
const Math.min(1dot(normalhalfway) * dot(normalwo) / dot(wohalfway));

    return 
/ (dot(normalwi) * dot(normalwo));
}

function 
fresnelSchlick(cosThetaF0F1) {
    return 
F0 + (F1 F0) * Math.pow(cosTheta5);
}


Fresnel Incidence Effects


The Fresnel effect describes how the amount of reflection changes based on the angle of incidence. At normal incidence, surfaces reflect less light than at glancing angles. This is especially important for materials like glass or water, where you can see a mix of reflection and refraction depending on the angle.

The Fresnel equation for dielectrics (non-conductors) is given by:

\[
R(\theta) = R_0 + (1 - R_0)(1 - \cos \theta)^5
\]

where:
\(R_0\) is the reflectance at normal incidence,
\(\theta\) is the angle between the incoming light direction and the surface normal.

Example: Fresnel Term in JavaScript (Schlick's Approximation)


function fresnelSchlickApprox(cosThetaR0) {
    return 
R0 + (R0) * Math.pow(cosTheta5);
}

// Usage
const cosTheta 0.5;  // cosine of the angle between light direction and normal
const R0 0.04;  // Reflectance at normal incidence for glass-like material
const fresnel fresnelSchlickApprox(cosThetaR0);
console.log(fresnel);  // Fresnel reflection term


Fourier Basis BSDFs


Fourier Basis Bidirectional Scattering Distribution Functions (BSDFs) provide a more general way to represent surface interactions by decomposing them into a Fourier series. Instead of using a simple function for reflection, transmission, or absorption, the Fourier basis provides a compact way to represent complex scattering behavior, especially for anisotropic materials (those whose properties vary with direction).

The Fourier BSDF stores scattering data in a frequency domain, enabling the modeling of very complex light interactions efficiently. This approach is particularly useful for realistic materials that have intricate reflectance properties.

However, Fourier BSDFs are typically not directly computed in real-time applications, but precomputed data can be used for rendering. In code, this would usually involve querying from precomputed tables rather than directly implementing Fourier transformations in JavaScript.

Fourier Basis BSDFs are beyond typical real-time JS implementation, but here's a general idea


// Fourier BSDFs would be loaded from a precomputed lookup table
function sampleFourierBSDF(fourierDataincomingDiroutgoingDir) {
    
// Lookup the Fourier coefficients based on the incoming and outgoing directions
    
const coefficients lookupFourierCoefficients(fourierDataincomingDiroutgoingDir);

    
// Perform inverse Fourier transform to get the reflection/transmission value
    
return inverseFourierTransform(coefficients);
}








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.