Gaussian Splatting From Zero · Episode 04
Color, Opacity & Alpha Blending
Color, Opacity & Alpha Blending is Episode 04 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 .
In Episode 03 we faked a solid planet with a cheat: opaque splats and a depth buffer, where the nearest splat simply wins each pixel. Real Gaussian splats don't work that way. They're semi-transparent — each one contributes a little color and a little coverage, and the final pixel is thousands of them blended over each other. Get that blend right and you have a photograph. Get it wrong and you get popcorn: a crawling, sparkling mess that's the signature failure of every first splat renderer. This episode is about the blend. Toggle the demo's stages and meet the popcorn.
Opacity: the fourth dimension of a splat
Every splat carries an opacity in [0, 1] — its peak alpha at
the very center, fading to zero at the rim via the Gaussian. A wall splat might be
0.9 (nearly solid); a wisp of smoke might be 0.05. The final
per-pixel alpha is the opacity times the Gaussian falloff we built in Episode 02:
// FRAGMENT SHADER
float r2 = dot(vQuad, vQuad); // sigma² from center
float falloff = exp(-0.5 * r2); // 1 at center → 0 at rim
float alpha = falloff * vOpacity * uOpacity;
gl_FragColor = vec4(vColor, alpha);
Crank the demo's opacity slider down and the planet turns to colored glass — you start seeing the splats on the far side through the near ones. That see-through quality is the whole point of splatting, and it's also what makes blending hard: when you can see through everything, the order you paint in suddenly matters enormously.
The "over" operator: painting with translucent paint
Compositing a translucent thing over a background is the "over" operator, the most important equation in all of 2D/3D graphics:
Read it as: "take the fraction src.a of the new color, and keep the
remaining (1 − src.a) of whatever was already there." Apply it splat after
splat, front-to-back or back-to-front, and translucent layers accumulate into a solid
image. In Three.js this is THREE.NormalBlending. The catch is hiding in plain
sight: that (1 − src.a) term doesn't commute. Painting A over
B looks different from B over A. Order is everything.
Stage 1 → 2: meet the popcorn
Flip the demo from Stage 1 (opaque) to Stage 2 (transparent, depthWrite ON)
and orbit. The surface erupts into a crawling, glittery mess — splats blinking in front of
and behind each other as you move. That's popcorn, and its cause is specific: with
depthWrite = true, each transparent splat stamps its depth into the z-buffer,
so a splat drawn slightly nearer rejects the one behind it entirely instead of
blending with it. Thousands of transparent splats fighting over the depth buffer = static.
The rule, burned in once and never forgotten: transparent splats mustdepthTestbut neverdepthWrite. They should be hidden by solid geometry in front of them, but they must not hide each other in the depth buffer — they need to blend, not reject.
Stage 3: depthWrite off — smooth, but still wrong
Stage 3 turns depthWrite off. The popcorn vanishes; the planet is smooth
translucent glass again. But look carefully as you orbit — there's a milky wrongness,
especially where front and back overlap. Continents on the far side bleed through the near
surface at the wrong strength, and the look subtly shifts as you rotate. That's because the
splats are still being blended in array order — the arbitrary order they
sit in memory — not in depth order. The "over" operator is unforgiving: blend in the wrong
order and you get the wrong picture, every time.
Stage 4: premultiplied alpha, the production blend
One refinement libraries always make: premultiplied alpha. Instead of
outputting vec4(color, alpha) and letting the blender multiply, you output the
color already multiplied by alpha — vec4(color * alpha, alpha) — and
set the blend factors to ONE, ONE_MINUS_SRC_ALPHA. Mathematically identical for
a single layer, but it composites correctly through many layers and avoids dark fringes
where soft edges meet. Stage 4 switches to it:
material.blending = THREE.CustomBlending;
material.blendEquation = THREE.AddEquation;
material.blendSrc = THREE.OneFactor; // src already premultiplied
material.blendDst = THREE.OneMinusSrcAlphaFactor;
// fragment outputs: gl_FragColor = vec4(color * alpha, alpha);
It looks almost right now — correct blend math, correct depth behavior. But it's still unsorted, so the residual order errors remain. We have done everything we can at the blend stage. The only thing left is to feed the splats to the GPU in the right order, every frame, as the camera moves. That sort is the entire next episode, and it's the most satisfying fix in the series.
A note on color management
Splat colors are usually stored in a roughly-sRGB space, and your renderer works in
linear light. If captures come out muddy or washed, it's almost always a color-space
mismatch: set renderer.outputColorSpace = THREE.SRGBColorSpace and be
deliberate about whether incoming colors are linear or sRGB. Real .ply splats
store color as spherical-harmonic coefficients in a particular convention (with a
0.28209 scale factor on the DC term) — that's a whole episode of its own,
Episode 06.
Common pitfalls
- Crawling popcorn.
depthWriteis on for transparent splats. Turn it off. This is the bug behind 90% of "my splats look like TV static" posts. - Dark halos around soft edges. You're using straight alpha where you
need premultiplied, or your texture/output color space is wrong. Premultiply and check
outputColorSpace. - The cloud gets darker as you add splats. You blended with the wrong
factors (e.g.
SRC_ALPHA, SRC_ALPHA). "Over" isSRC_ALPHA, ONE_MINUS_SRC_ALPHA(straight) orONE, ONE_MINUS_SRC_ALPHA(premultiplied). - It looks right from one angle and wrong from the opposite side. That's the unsorted-order error, not a blend bug. It's a preview of why Episode 05 exists — no amount of blend tuning fixes it.
- Fully transparent splats still cost you. Even
alpha = 0fragments run the shader and hit the blender.discardwhen alpha is below a small threshold to skip the blend and save fill rate.
Exercises
- Add a
uBackgrounduniform and blend the splats over a colored sky instead of black. Notice how low-opacity splats pick up the background tint — correct "over" behavior, and a good test that your alpha is right. - Implement both straight and premultiplied paths behind a toggle and A/B them at a soft continent edge. The dark-fringe difference is subtle but real.
- Drive each splat's opacity by its color's brightness. Dark ocean splats go more transparent, bright ice caps stay solid — a cheap fake of "more confident where there's more signal."
What's next
Episode 05 — Depth Sorting. We sort all 45,000 splats back-to-front by their distance from the camera, every time you move, and re-feed them to the GPU in that order. The milky wrongness snaps into a crisp, correct image. We'll build a fast counting sort, throttle it so it doesn't tank the framerate, and explain why this is the one piece triangles never need but splats can't live without.