PAJAMA / RELIGHT

05 / 08 · RELIGHTING

Use SH for light, not just appearance

Understand lighting coefficients, transfer and TranSplat.

Same basis, different functions

Appearance SH maps outgoing viewing direction to captured RGB. Lighting SH maps incoming direction to environment radiance. Both can use Yₖ, but coefficients represent different functions. Each RGB channel is evaluated separately, then combined for display.

Our BRDF v points from surface to camera. Some GS appearance code uses camera-to-Gaussian instead. Negating a direction changes odd SH band signs: never copy coefficients without checking direction, normalization and basis ordering.

Lenv(ω)≈∑kℓkYk(ω),ℓk=∫S2Lenv(ω)Yk(ω) dωL_{\rm env}(\boldsymbol\omega)\approx\sum_k\boldsymbol\ell_kY_k(\boldsymbol\omega),\qquad \boldsymbol\ell_k=\int_{\mathbb S^2}L_{\rm env}(\boldsymbol\omega)Y_k(\boldsymbol\omega)\,d\omega

Turn the integral into a dot product

Define transfer K(ω)=V(ω)max(n·ω,0). Expand light and transfer in the same orthonormal real SH basis. Multiply their sums and integrate. Different basis pairs integrate to zero, matching pairs to one. Only matching coefficient products remain.

For unoccluded diffuse light the cosine kernel is smooth. Bands l=0,1,2 give 1+3+5=9 coefficients per channel, often a good approximation of irradiance. Sharp shadows and mirror reflections need more directional detail. Moving geometry changes K even with a fixed environment.

E=∫LenvK dω≈∑i,jℓiKj∫YiYj dω⏟δij=∑kℓkKk,Ld=ρπEE=\int L_{\rm env}K\,d\omega\approx\sum_{i,j}\boldsymbol\ell_iK_j\underbrace{\int Y_iY_j\,d\omega}_{\delta_{ij}}=\sum_k\boldsymbol\ell_kK_k,\quad L_d=\frac{\rho}{\pi}E

Why an irradiance ratio can help

In a purely diffuse thought experiment, with unchanged normals and visibility, old color is proportional to ρEold and new color to ρEnew. Dividing cancels ρ. The ratio fails when old irradiance is tiny, shadows change, or specularity violates the assumption. A denominator floor prevents numerical explosion; it does not recover missing information.

TranSplat (ICCP 2026) transfers trained oriented 2D Gaussian surfels using source/target environment maps, with separate specular treatment. Its official code was released in July 2026. It is a useful reproduction target, not a direct conversion of this STG-Lite asset. This simple ratio explains an intuition, not the complete method.

cnew≈cold⊙Enewmax⁡(Eold,ε)\mathbf c_{\rm new}\approx\mathbf c_{\rm old}\odot\frac{\mathbf E_{\rm new}}{\max(\mathbf E_{\rm old},\varepsilon)}

Predict it, then run it

Open this experiment →

The formula meets actual code

This excerpt is extracted from the repository during the site build. SH environment lighting and inverse training are future extensions; their chapters point to the current direct-light/data boundary, not an implemented trainer.

src/relight.wgsl · L24–54
fn masking(cosine: f32, a2: f32) -> f32 {
    return 2.0 * cosine / max(cosine + sqrt(a2 + (1.0-a2)*cosine*cosine), 1e-6);
}
fn shade(s: Splat) -> vec3<f32> {
    let n = normalize(s.normal.xyz);
    let v = normalize(g.eye.xyz - s.center.xyz);
    let l = g.light.xyz;
    let mode = u32(g.material.z);
    if mode == 3u { return n * 0.5 + 0.5; }
    if mode == 4u { return s.base.xyz; }
    let nl = max(dot(n,l), 0.0);
    let nv = max(dot(n,v), 0.0);
    if nl <= 0.0 || nv <= 0.0 { return vec3(0.0); }
    let h = normalize(l+v);
    let nh = max(dot(n,h), 0.0);
    let vh = max(dot(v,h), 0.0);
    let a = g.material.x * g.material.x;
    let a2 = a*a;
    let denominator = nh*nh*(a2-1.0)+1.0;
    let d = a2 / (3.14159265359 * denominator * denominator);
    let f0 = mix(vec3(0.04), s.base.xyz, g.material.y);
    let fresnel = f0 + (1.0-f0)*pow(1.0-vh, 5.0);
    let geometry = masking(nl,a2)*masking(nv,a2);
    let specular = d*fresnel*geometry / max(4.0*nl*nv, 1e-6);
    let diffuse = (1.0-fresnel)*(1.0-g.material.y)*s.base.xyz/3.14159265359;
    var brdf = diffuse+specular;
    if mode == 1u { brdf = diffuse; }
    if mode == 2u { brdf = specular; }
    // One white distant light, no occlusion, no indirect illumination.
    return brdf * nl * g.light.w;
}

Check your understanding

Can nine lighting SH coefficients accurately reproduce a tiny sharp highlight?

Reveal the reasoning

Usually no. Low-order SH loses high-frequency detail. Specular IBL commonly uses prefiltered environment maps and a BRDF lookup, or more expensive integration.

Primary references for this chapter

TranSplat · ICCP 2026 ↗