This is a great question about rendering and ray tracing. Let me break down BRDF and the specific models mentioned.
BRDF (Bidirectional Reflectance Distribution Function)
The BRDF describes how light is reflected off a surface in different directions. It's fundamental to ray tracing and physically-based rendering.
Definition
The BRDF f_r(ω_i, ω_o) is defined as the ratio of reflected radiance in direction ω_o to the incident irradiance from direction ω_i:
f_r(ω_i, ω_o) = dL_o(ω_o) / (dE_i(ω_i))
Or more practically, for a point on a surface:
f_r(ω_i, ω_o) = dL_o(ω_o) / (L_i(ω_i) cos(θ_i) dω_i)
Properties:
- Reciprocity: f_r(ω_i, ω_o) = f_r(ω_o, ω_i)
- Energy conservation: The total reflected energy cannot exceed incident energy
- Dimensionality: 1/steradians typically
Lambertian Diffuse BRDF
The simplest and most common diffuse model:
f_diffuse = ρ_d / π
Where:
- ρ_d is the diffuse albedo (0 to 1)
- The division by π comes from energy normalization
Characteristics:
- Isotropic (same in all directions)
- Appears equally bright from all viewing angles
- Light reflects uniformly in all directions
- No dependence on view direction or light direction
- The cosine term in the rendering equation naturally provides the directional falloff
- Examples: matte paint, unpolished concrete, chalk
Cook-Torrance Microfacet BRDF
A physically-based specular model treating surfaces as randomly oriented microfacets. The total reflectance combines diffuse and specular components:
f_cook_torrance = f_diffuse + f_specular
Where the specular term is:
f_specular = (D(h) * F(h, ω_i) * G(ω_i, ω_o)) / (4 * cos(θ_i) * cos(θ_o))
The specular component depends on three key functions: D(h) describes how microfacets are oriented, F(h, ω_i) accounts for Fresnel effects at different angles, and G(ω_i, ω_o) handles geometric shadowing and masking between microfacets.
For the Normal Distribution Function, Beckmann and GGX are standard choices, with a roughness parameter α controlling highlight sharpness from smooth (0) to rough (1). The Fresnel term determines how reflectivity changes with viewing angle, while the geometry function—often implemented via Schlick-GGX—prevents microfacets from blocking incident and outgoing light rays.
The denominator's 4 * cos(θ_i) * cos(θ_o) factor ensures energy conservation through normalization and projection. The Fresnel effect is particularly important: at normal incidence, light mostly refracts into the surface, but at grazing angles, reflection dominates. The Fresnel-Schlick approximation provides an efficient way to model this behavior.
F(θ) = F_0 + (1 - F_0) * (1 - cos(θ))^5
Here θ represents the angle between the half-vector and either the view or light direction, while F_0 captures the reflectance at perpendicular viewing. For dielectrics like water, glass, and plastic, F_0 ranges from roughly 2-5%, whereas metals exhibit higher and spectrally-colored F_0 values, with gold showing notably warm tones.
The full Fresnel-Cauchy equation provides greater accuracy by accounting for both incident and transmitted angles along with polarization effects. As surfaces approach grazing angles, the (1 - cos(θ))^5 term drives reflectance toward 100% regardless of material type—this explains why reflections become nearly perfect on water or polished surfaces when viewed at shallow angles, creating that characteristic shiny appearance at object edges.
Lambertian diffuse rendering is computationally simple and adequate for matte surfaces, but it ignores view-dependence and material properties, resulting in flat, unrealistic appearance. Cook-Torrance offers physical accuracy with proper specular highlights and grazing angle behavior, though it demands more computation and parameter tuning compared to the simpler diffuse approach.
In ray tracing, I integrate these models by sampling light directions for direct illumination and recursively tracing random directions for indirect light. The rendering equation uses Monte Carlo integration, where I importance-sample according to the BRDF—concentrating samples around the reflection direction for specular surfaces and using cosine-weighted or uniform sampling for diffuse ones, then weighting each sample to minimize variance.
BRDF in Ray Tracing
BRDF Fundamentals
The Bidirectional Reflectance Distribution Function describes how a surface reflects light:
fr(ωi,ω
In ray tracing's rendering equation:
Lo(p,ωo
Key properties:
- Reciprocity: fr(ωi,ωo
Lambertian Diffuse BRDF
Formula:
fdiffuse=πρd
Characteristics:
- Isotropic: Same reflection in all directions
- View-independent: Brightness unchanging regardless of viewing angle
- Simple: Just one albedo parameter ρd
- Cosine normalization: The π factor ensures energy conservation when integrated
Visual result: Matte surfaces—chalk, unfinished concrete, flat paint
Pseudocode:
vec3 lambertian(vec3 albedo, vec3 normal, vec3 lightDir) {
float cosTheta = max(dot(normal, lightDir), 0.0);
return (albedo / PI) * cosTheta;
}
Problem: Unrealistic—real surfaces show specular highlights and Fresnel effects.
Cook-Torrance Microfacet BRDF
A physically-based model treating surfaces as arrays of randomly oriented microfacets:
fspecular=4
Complete BRDF: fr=fdiffuse+f
Component 1: Normal Distribution Function (NDF)
Describes microfacet slope distribution. GGX (most popular):
D(h)=π[(n⋅h)2(α
Where α is roughness (0=mirror-smooth, 1=very rough).
float DistributionGGX(float NdotH, float roughness) {
float a = roughness * roughness;
float a2 = a * a;
float denom = NdotH * NdotH * (a2 - 1.0) + 1.0;
return a2 / (PI * denom * denom);
}
Component 2: Geometry Function
Models self-shadowing of microfacets. Schlick-GGX:
G(ωi,ωo)=G
float GeometrySchlickGGX(float NdotV, float roughness) {
float r = (roughness + 1.0);
float k = (r * r) / 8.0;
return NdotV / (NdotV * (1.0 - k) + k);
}
float GeometrySmith(float NdotL, float NdotV, float roughness) {
return GeometrySchlickGGX(NdotL, roughness) *
GeometrySchlickGGX(NdotV, roughness);
}
The Fresnel Term: The Star of the Show
What is Fresnel?
Physical principle: Reflectivity depends on viewing angle. Light refracts into surfaces at normal incidence but reflects off at grazing angles—this is the Fresnel effect.
Fresnel-Schlick Approximation
F(θ)=F0+(1−F
Where:
- θ = angle between half-vector h and incident direction
- F0 = reflectance at normal incidence (0°)
vec3 fresnelSchlick(float cosTheta, vec3 F0) {
return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
}
F0 Values: Material Signatures
| Material | F0 | Meaning |
|---|
| Water | 0.02 | 2% reflection at normal incidence |
| Glass | 0.04 | 4% reflection |
| Skin | 0.05 | ~5% reflection |
| Copper | (0.95, 0.64, 0.54) | Colored, metallic |
| Gold | (1.0, 0.86, 0.57) | Warm, metallic |
Metals: Use per-channel F0 values (RGB).
Dielectrics: Use 0.04 as default, or compute from IOR:
F0=
Grazing Angle Behavior: Why Reflections Get Away
As θ→90° (grazing angle):
cosθ→0⟹(1−cosθ
Result: F→1 for ALL materials at grazing angles.
Visual effects:
- Nearly perfect mirror reflections at shallow angles
- Wet roads appear shiny when viewed from distance
- Edges of curved objects appear bright/reflective
- Caustics vanish at surface boundaries
// Grazing angle effect demonstration
vec3 F0_plastic = vec3(0.04);
float grazing = fresnelSchlick(0.0, F0_plastic); // ~0.04, mostly refracted
float normal = fresnelSchlick(0.5, F0_plastic); // ~0.25
float steep = fresnelSchlick(0.1, F0_plastic); // ~0.95, mostly reflected
Side-by-Side Comparison
| Property | Lambertian | Cook-Torrance |
|---|
| Specular highlights | None | ✓ Sharp to diffuse |
| View dependence | ✗ None | ✓ Through Fresnel |
| Fresnel effects | ✗ None | ✓ Full grazing angle behavior |
| Roughness support | ✗ N/A | ✓ Via NDF parameter |
| Metallic materials | ✗ Poor | ✓ Excellent |
| Computational cost | Low | Medium-High |
| Realism | Poor | High (physically-based) |
Complete Ray Tracing Example
vec3 cookTorrance(vec3 normal, vec3 lightDir, vec3 viewDir,
vec3 albedo, float roughness, vec3 F0) {
vec3 halfDir = normalize(lightDir + viewDir);
float NdotV = max(dot(normal, viewDir), 0.0);
float NdotL = max(dot(normal, lightDir), 0.0);
float NdotH = max(dot(normal, halfDir), 0.0);
float HdotV = max(dot(halfDir, viewDir), 0.0);
// Fresnel
vec3 F = fresnelSchlick(HdotV, F0);
// Normal Distribution
float D = DistributionGGX(NdotH, roughness);
// Geometry
float G = GeometrySmith(NdotL, NdotV, roughness);
// Specular contribution
vec3 kS = F;
vec3 kD = (vec3(1.0) - kS) * (1.0 - metallic);
vec3 specular = (D * F * G) / (4.0 * NdotV * NdotL + 0.001);
vec3 diffuse = (kD * albedo) / PI;
return (diffuse + specular) * lightIntensity * NdotL;
}
Key Takeaway
The Fresnel term is the most perceptually important component—it explains why surfaces look reflective at grazing angles (like mirrors), regardless of material. This single phenomenon elevates a render from flat to photorealistic.