Gaussian Splatting From Zero · Episode 06

Spherical Harmonics & View-Dependent Color

Spherical Harmonics & View-Dependent Color is Episode 06 of Gaussian Splatting From Zero, a MasterAllArts free interactive lesson for artists learning creative 3D on the web.

Part of the MasterAllArts Creative 3D Roadmap .

Episode 06 · Gaussian Splatting From Zero

Until now every splat has had one fixed color. That's why our planet looks like a painted globe and not a photographed one: real surfaces change color as you move. A wet street throws a glare that slides with your head; chrome shows you a different world from every angle; even matte paint shifts subtly. 3D Gaussian Splatting captures this by making each splat's color a function of viewing direction, stored as a handful of numbers called spherical-harmonic coefficients. Turn the "SH degree" slider up in the demo and watch a sun-glint come alive on the oceans as the planet turns.

0 fps
drag to orbit · scroll to zoom
SH degree 3 · 45k splats
Sharp view-dependent specular on the oceans. As the planet turns, the glint slides — like real water.

Why a single color isn't enough

A splat sits on a surface and is seen from many camera positions during a capture. From head-on it might look deep blue; at a grazing angle it catches the sky and looks bright white. If you store one average color, you lose that — the splat looks like flat paint. To be photoreal, the splat has to remember "blue from here, white from there" — a whole little function defined over the sphere of possible viewing directions.

Storing an arbitrary function-over-a-sphere would take infinite numbers. Spherical harmonics are the trick that makes it finite: they're the "Fourier series for the surface of a sphere." Any smooth function over directions can be approximated as a weighted sum of a few fixed basis functions — and you only store the weights.

The SH ladder: degree 0 to 3

The basis functions come in bands of increasing frequency. The more bands you keep, the sharper the view-dependent detail you can represent — and the more coefficients you store per color channel, per splat:

DegreeBands keptCoeffs / channelCaptures
0just the constant1flat average color (the "DC" term)
1+ 3 linear4broad directional sheen
2+ 5 quadratic9softer specular lobes
3+ 7 cubic16tight, glossy highlights

Degree 3 is what the original 3DGS paper uses. That's 16 coefficients × 3 channels = 48 floats of color per splat — far more than the position (3) and shape (7) combined. Color is the heaviest thing a splat carries, which is why compression (Episode 12) goes after the SH coefficients first.

The DC term and the 0.28209 you'll see everywhere

The degree-0 coefficient is the splat's base, view-independent color — the average over all directions. In a real .ply it's stored in the fields f_dc_0, f_dc_1, f_dc_2, and to turn it into an actual RGB color you apply the constant SH basis value C0 = 0.28209 and a bias:

// degree-0 (DC only) reconstruction — the minimum viable SH
const C0 = 0.28209479;            // the 0th SH basis function, a constant
rgb = 0.5 + C0 * f_dc;            // per channel; clamp to [0,1]

If you've ever loaded a splat and gotten a uniformly grey blob, you forgot this — you rendered the raw coefficient instead of decoding it. Every loader does this conversion; Episode 07 wires it into ours.

Evaluating the higher bands

For the view-dependent part you evaluate the basis functions at the direction from the splat to the camera, multiply each by its stored coefficient, and add them to the DC color. The degree-1 band, for a unit view direction d = (x, y, z), looks like this:

// add the degree-1 view-dependent term (3 coeffs per channel)
const float C1 = 0.48860251;
vec3 d = normalize(cameraPosition - splatCenter);   // view direction
color += C1 * (-d.y * sh1 + d.z * sh2 - d.x * sh3);  // sh1..3 are vec3 coeffs
// ...degree 2 adds 5 more terms, degree 3 adds 7 more...

The pattern continues for degrees 2 and 3 with longer (but still fixed) formulas. It's a lot of multiply-adds, but it's branch-free and runs per-splat in the vertex shader, so the GPU eats it for breakfast.

Honesty note for this demo. Carrying 48 real SH floats per splat through instanced attributes would bloat this single-file demo, so below we fake the effect with a classic specular highlight (reflect the light around the surface normal, raise to a power) and let the "SH degree" slider control its sharpness. The phenomenon is identical — color that depends on view direction, sharper with more bands — and the code above is exactly how a real loader decodes the genuine article. Episode 07 parses real SH from a real buffer.

What the slider is showing you

Degree 0 is the flat painted globe from the last three episodes — turn the slider there and the oceans go matte and dead. Bump to 1 and a broad soft sheen appears across the water. By degree 3 it's a tight, bright sun-glint that slides realistically across the oceans as the planet rotates, while the matte continents stay put. That difference — dead paint vs living, view-aware surface — is the single biggest reason splat captures read as "real" and not as "3D models." It's the same reason the land (rough) and sea (glossy) look like different materials even though every splat uses the identical shader: the optimizer simply learned bigger SH coefficients for the shiny splats.

Common pitfalls

  • Everything is flat grey. You rendered f_dc directly. Decode it: 0.5 + 0.28209 * f_dc.
  • Colors are weirdly dark or oversaturated. Degree-0-only when the file has higher bands, or a missing/extra gamma step. Match the convention your file was trained with.
  • Highlights don't move when you orbit. You evaluated SH at the surface normal instead of the view direction. View-dependence needs the splat→camera vector, which changes as the camera moves.
  • SH coefficients are in the wrong order. The .ply stores them interleaved in a specific layout (f_rest_0 … f_rest_44, grouped by band then channel). Get the ordering wrong and you get plausible-but-wrong shimmer. Cross-check against a reference loader.
  • Massive memory blowup. 48 floats × millions of splats is hundreds of MB. Many web viewers drop to degree 0 or 1 on mobile. View-dependence is the first thing you trade for download size.

Exercises

  1. Make the highlight color tunable (a warm sun vs a cool skylight) and notice how much "material" you can imply just by changing what the glossy splats reflect.
  2. Drive specular sharpness from each splat's color instead of a global slider: bluer splats glossier, greener ones matte. You've just hand-authored a per-splat SH degree.
  3. Add a second light from the opposite side in a different tint. Real captures bake in the whole environment's lighting — this is a tiny taste of why relighting them (Season 3) is hard.
  4. Implement the real degree-1 evaluation from the snippet above with three random vec3 coefficients per splat and compare its broad, soft look to the specular fake. This is the honest version.

What's next

Episode 07 — Loading Real Splats. We've generated every splat procedurally so far. Now we decode the real thing: the byte-for-byte layout of the .ply and .splat formats, including the SH coefficients we just met. We'll synthesize a real .splat buffer, inspect its bytes, and parse it with the exact loader you'd point at a multi-gigabyte capture.