skip to content

In a microfacet PBR shader, an artist's rough gold material goes dark at grazing angles; how do you find out whether the BRDF is losing energy, and fix it?

level: seniorimportance: should knowfreq 40%

answer

  1. does it grow with roughness?
  2. a uniform white environment
  3. the sphere should disappear
  4. light the geometry term throws away
  5. scale by the missing albedo

basics

~20 s

Run a white furnace test: spheres with F0 = 1 under uniform white light should vanish. Single-scattering GGX darkens rough spheres, worst at grazing, because Smith masking discards light that would bounce again; a multiple-scattering compensation factor restores it.

solid answer

~50 s

First separate physics from a bug. Thin black pixels along silhouettes at every roughness usually point at a `dot(n, v)` that reaches zero or below and divides the specular term; a smooth darkening that grows with roughness is energy loss. Confirm it with a **white furnace test**: render spheres from roughness 0 to 1 with `F0 = 1` under a uniform environment of radiance 1. An energy-preserving BRDF integrates to 1, so each sphere vanishes into the background. Single-scattering Cook-Torrance leaves dark rims on rough spheres, because the Smith term removes light blocked by neighbouring facets that in reality would reflect again and escape. The fix is **multiple-scattering compensation**: precompute the single-scattering albedo `E(dot(n,v), roughness)` with `F = 1`, which a split-sum lookup table already provides as the sum of its scale and bias, and scale specular by `1 + F0 * (1/E - 1)`.

code

pseudocode · 17 lines
pseudocode
// offline: single-scattering albedo with F = 1, tangent space with n = (0, 0, 1)
function E_ss(NdotV, roughness, N):
    v = (sqrt(1 - NdotV * NdotV), 0, NdotV)
    sum = 0
    for i in 0 .. N - 1:
        h = sample_ggx_half_vector(i, N, roughness)   // pdf over h = D(h) * dot(n, h)
        l = 2 * dot(v, h) * h - v
        if l.z > 0:
            NdotH = max(h.z, 0.0001)
            VdotH = max(dot(v, h), 0)
            sum += G_smith(l.z, NdotV, roughness) * VdotH / (NdotH * NdotV)
    return sum / N

// run time, per light or environment sample
spec = cook_torrance(n, v, l, F0, roughness)
E    = lookup(E_ss_table, dot(n, v), roughness)
spec = spec * (1 + F0 * (1 / E - 1))

go deeper

for a junior

Recall that a surface may not reflect more light than it receives, and that rough surfaces in a single-bounce model come out darker than they should.

for a middle

Explain directional albedo, why a normalised distribution keeps highlights honest, and why the Smith term throws light away instead of letting it bounce again.

for a senior

Separate an energy problem from a division bug by its pattern, run a white furnace test against a reference, and apply a compensation factor consistently to lights and environment.

for a principal

Weigh the cost of an extra table fetch and per-pixel factor against visible rough-metal darkening across all materials, and decide which reference the team validates shading against.

## What energy conservation means for a BRDF A surface cannot reflect more light than it receives. For a BRDF `f`, the **directional albedo** `E(v)` is the integral of `f(l, v) * dot(n, l)` over every incoming direction `l`: the fraction of uniform incoming light reflected toward `v`. **Energy conservation** requires `E(v) <= 1` for every view direction; a model with no absorption should reach exactly 1. In a PBR shader the requirement shows up in three places: - the **normalised distribution**: narrowing a GGX lobe raises its peak instead of creating light; - the **diffuse and specular split**: light reflected at the surface is not available for diffuse scattering, so many shaders weight diffuse by roughly `(1 - F)` and drop it entirely for metals; - the **specular lobe itself**, which is where a rough gold goes wrong. ## Where single scattering leaks energy Cook-Torrance models exactly one bounce. Its Smith term `G` removes light whose path into or out of a facet is blocked by another facet. In reality that light hits the other facet, reflects again (scaled by Fresnel) and much of it escapes after two or more bounces. The single-scattering model drops it. The loss is negligible on smooth surfaces and grows with roughness, and it is largest at grazing angles, where masking is heaviest. Gold reflects nearly all red light at every bounce, so the light the model discards would mostly have come back; the gap shows as a dark, dull rim. ## Triage: physics or a bug | Symptom | Likely cause | First check | |---|---|---| | Smooth darkening that grows with roughness, strongest at grazing | single-scattering energy loss | white furnace test | | Thin black or flickering pixels on silhouettes at any roughness | `dot(n, v)` reaching zero or below and dividing the specular term, often from normal-mapped normals facing away | output `dot(n, v)` as a colour; clamp it to a small positive value | | Whole material too dark at every angle | metallic below 1, or a roughness or metallic map decoded as colour data | inspect the raw texture values | | No brightening at grazing even when smooth | environment specular multiplied by `F0` alone, without the table's bias term | compare with a brute-force reference | With metallic at 1, gold has no diffuse term, so apart from a wrong metallic value every one of these lives in the specular path. ## The white furnace test 1. Replace all lighting with a uniform environment of radiance 1 in every direction: no lights, no shadows, exposure fixed and output read as raw linear values. 2. Set `F0 = 1`, so Fresnel cannot hide anything, and turn the diffuse term off. 3. Render a row of spheres with roughness from 0 to 1. 4. Read the result: each pixel now shows `E(v)` for its view angle. Spheres that vanish preserve energy; darker rims lose it; brighter rims create it. 5. Run the same scene through a brute-force sampler of the same BRDF as a reference, so a bug in the prefiltered environment is not mistaken for a BRDF property. A Lambert term with albedo 1 passes on its own, since the integral of `dot(n, l) / pi` over the hemisphere is exactly 1, which makes it a quick check that the test rig itself is right. ## Multiple-scattering compensation An exact multiple-scattering lobe can be derived, but a cheaper approximation scales the single-scattering specular: `f_ms = f_ss * (1 + F0 * (1 / E_ss - 1))` - `E_ss(dot(n,v), roughness)` is the single-scattering albedo with `F = 1`, precomputed into a 2D table. In the common split-sum layout it is the sum of the table's scale and bias values, so a renderer with split-sum environment lighting already stores it. - Check against the furnace: with `F0 = 1`, the albedo becomes `E_ss * (1 / E_ss) = 1`, so the spheres vanish. - The added energy is tinted by `F0`, because light that bounced off gold several times is coloured by gold at each bounce; more exact versions saturate the colour further. - Apply the same factor to analytic lights and to environment light, or the two disagree. ## Fixes that are not fixes - **Dropping `G`**: the BRDF then gains energy, and with `4 * dot(n,l) * dot(n,v)` in the denominator it blows up near grazing angles. - **Lowering the gold's roughness or brightening its base colour**: it tunes one view and one sky, changes the highlight shape and breaks elsewhere. - **An ad-hoc rim term**: it brightens edges whatever the roughness, so smooth materials gain energy they never lost.

  • Why is the compensation tinted by F0 instead of adding white light?
    The missing light left the surface after two or more facet reflections, and each reflection off gold keeps mostly red and yellow and loses blue. So the recovered energy is coloured, and more saturated than one bounce. Multiplying by F0 is a cheap stand-in; formulations using the average Fresnel over the hemisphere saturate the colour more and match references better.
  • Why not just drop the geometry term to brighten the grazing angles?
    G is what keeps the specular term finite and below one. Without it, D * F / (4 * dot(n,l) * dot(n,v)) grows without bound as either cosine approaches zero, so grazing pixels blow out and the furnace spheres glow brighter than the background. The darkening comes from the energy G discards, so the fix returns that energy rather than removing the term.
  • Does adding a Lambert diffuse to the specular term keep a dielectric energy-conserving?
    Not automatically. Each term may pass the furnace alone, yet their sum exceeds one wherever the specular lobe reflects a meaningful share, most of all at grazing angles. Weighting diffuse by roughly one minus the specular albedo keeps the total near one; weighting by one minus F per light is a cheaper approximation of the same idea.

  • Single-scattering GGX is energy-preserving, so a dark rim must come from the lighting.
  • Dropping the geometry term is a safe fix for dark grazing angles.
  • A white furnace test needs a real HDR sky to be meaningful.
  • Energy conservation only means the diffuse and specular weights add up to one.
  • Clamping dot(n, v) at zero is enough to keep the specular term finite.