Gaussian Splatting From Zero · Episode 02
From Points to Splats
From Points to Splats is Episode 02 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 .
Last episode we had 60,000 hard, opaque dots. This episode we turn each one into a soft, glowing blob — a little camera-facing card with a Gaussian falloff painted on it — and switch on additive blending. The exact same point positions, with this one change, stop looking like a screensaver and start looking like a photograph of a galaxy. Orbit the demo and flip from "hard" to "soft." That single toggle is the most important ten lines in the series.
The problem with a million draw calls
To give every splat a shape, each one needs to be a little quad — two triangles — that we can paint a falloff onto. Naively that's a million tiny meshes, a million draw calls, and a dead GPU. The fix is instancing: upload one quad, plus a compact per-splat data buffer, and tell the GPU "draw this quad N times, and here's the unique data for each copy." One draw call, a million splats.
In Three.js that's InstancedBufferGeometry with
InstancedBufferAttributes. The base quad's corners live in the normal
position attribute; everything that varies per-splat — center, color,
size, opacity — is an instanced attribute:
// one quad, corners in [-1,1] (we only use x,y)
const quad = new THREE.InstancedBufferGeometry();
quad.setIndex([0,1,2, 0,2,3]);
quad.setAttribute('position', new THREE.Float32BufferAttribute(
[-1,-1,0, 1,-1,0, 1,1,0, -1,1,0], 3));
// per-splat instanced attributes (filled procedurally)
quad.setAttribute('iCenter', new THREE.InstancedBufferAttribute(centers, 3));
quad.setAttribute('iColor', new THREE.InstancedBufferAttribute(colors, 3));
quad.setAttribute('iScale', new THREE.InstancedBufferAttribute(scales, 1));
quad.setAttribute('iOpacity', new THREE.InstancedBufferAttribute(opacits, 1));
Set mesh.frustumCulled = false on instanced splats. Three.js computes
the bounding sphere from the base quad (a 2×2 card at the origin), so it
will happily cull your entire million-splat cloud the moment the origin leaves the
frame. This wrong-bounding-box vanish is the #1 "my splats disappeared" bug.
A camera-facing billboard, the cheap way
We want each quad to always face the camera (a "billboard"). There's a beautiful
trick: do the billboarding in view space. After you multiply the
splat's center by the modelViewMatrix, the camera is at the origin looking
down −Z. So offsetting the center in view-space X and Y moves the quad in a plane that
already faces the camera — no lookAt math required:
// VERTEX SHADER (isotropic billboard)
attribute vec3 iCenter;
attribute vec3 iColor;
attribute float iScale;
attribute float iOpacity;
uniform float uSizeMul;
varying vec2 vQuad; // local quad coord, in "sigma" units
varying vec3 vColor;
varying float vOpacity;
void main() {
vColor = iColor;
vOpacity = iOpacity;
vQuad = position.xy; // −1..1
vec4 mv = modelViewMatrix * vec4(iCenter, 1.0);
mv.xy += position.xy * iScale * uSizeMul; // billboard in view space
gl_Position = projectionMatrix * mv;
}
Because we offset after the model-view transform but before the projection, the quad is a fixed size in world units that still shrinks correctly with distance under perspective — we get Episode 01's depth-sizing for free, and it's perfectly smooth.
The Gaussian: where "Gaussian splat" gets its name
Now the payoff. In the fragment shader, instead of a flat disc, we paint a
2D Gaussian — bright in the center, fading smoothly to nothing at the
edge. That's the bell curve exp(−½·d²), evaluated on the quad:
// FRAGMENT SHADER
uniform int uMode; // 0 = hard disc, 1 = gaussian
varying vec2 vQuad;
varying vec3 vColor;
varying float vOpacity;
void main() {
float r2 = dot(vQuad, vQuad); // distance² from center
if (r2 > 1.0) discard; // clip the quad to a circle
float alpha;
if (uMode == 1) {
// quad half-width spans 3 sigma → sigma-dist² = 9·r2
alpha = exp(-0.5 * 9.0 * r2) * vOpacity;
} else {
alpha = vOpacity; // hard disc, for contrast
}
gl_FragColor = vec4(vColor, alpha);
}
That exp() is the entire difference between Stage 1 and Stage 2 in the
demo. A hard disc has a visible edge; overlap a thousand of them and you see a thousand
edges. A Gaussian has no edge — it melts into its neighbors. Overlap a thousand
and you get smooth, continuous light. That smoothness is why splats can stand in
for a real surface.
Additive vs alpha — two ways to combine light
The last knob is the blend mode — how each splat's color combines with what's already on screen.
| Mode | Formula | Looks like | Order-dependent? |
|---|---|---|---|
| Additive | dst += src·α | Glow, fire, stars, nebulae — light that adds up | No — addition commutes |
| Alpha ("over") | dst = src·α + dst·(1−α) | Solid, opaque surfaces — paint that covers | Yes — and that's Episode 05's whole problem |
For a glowing galaxy, additive is perfect and — crucially — it
doesn't care what order the splats are drawn in, because a + b = b + a. In
Three.js it's one line:
material.blending = THREE.AdditiveBlending;
material.transparent = true;
material.depthWrite = false; // don't let splats occlude each other in the depth buffer
Toggle the demo to Stage 3 ("alpha, unsorted") and watch it go slightly wrong — muddy, with faint dark seams where far splats incorrectly paint over near ones. That murk is the sound of draw order mattering. Real opaque captures use alpha blending and must be sorted back-to-front; we'll build that sort in Episode 05. For tonight's nebula, additive sidesteps the whole problem and looks fantastic.
Why depthWrite = false?
If a splat writes to the depth buffer, it tells later splats "I'm a solid wall here, don't draw behind me." For thousands of overlapping transparent blobs that's catastrophic — they'd punch opaque holes in each other. So transparent splats test depth (so a real opaque mesh can still hide them) but don't write it. Forgetting this gives you a harsh, bitten-looking cloud with chunks missing. It's the second-most-common splat bug, right after the frustum-cull vanish.
Stage 4 — see the individual splats
Crank "splat size" up and drop to Stage 4 (fewer, bigger splats). Now you can see the individual Gaussians — soft, round, overlapping cards. This is the atom of everything that follows. It has exactly one flaw left for this season's first act: it's round. A round blob is great for a star or a wisp of dust, but terrible for a flat wall or a sharp edge. To represent a surface, a splat needs to be able to stretch and tilt — to become an ellipse. Giving it that power is the single biggest idea in splatting, and it's all of Episode 03.
Common pitfalls
- The whole cloud vanishes when you orbit. Frustum culling on a
bad bounding sphere.
mesh.frustumCulled = false. - Harsh holes / bitten edges. You left
depthWriteon. Transparent splats must not write depth. - Blown-out white blob. Additive blending with high opacity and lots of overlap saturates to white fast. Lower per-splat opacity (0.1–0.4 is normal for additive) — there are thousands of them stacking up.
- Square splats. You forgot the
if (r2 > 1.0) discard;circle clip, or yourvQuadisn't the −1..1 corner. - Splats are screen-aligned rectangles that don't rotate with the camera
right. You billboarded in world space instead of view space. Offset
mv.xyafter the model-view multiply, as above. - Everything is one flat color. Your
iColorinstanced attribute isn't bound, or you're readingcolor(the built-in) instead of youriColor. Instanced attribute names must match exactly.
Exercises
- Make the Gaussian sharper or softer by changing the
9.0inexp(-0.5 * 9.0 * r2). Bigger = tighter core, smaller = foggier. What value makes the nebula look most like a photo? - Add a subtle per-splat twinkle: pass a
uTimeuniform and multiply alpha by0.8 + 0.2*sin(uTime + iCenter.x*10.0). Stars should breathe. - Give the core splats higher opacity than the arm splats (you have the radius in the generator). A bright dense core sells the "galaxy" read enormously.
- Switch the base quad from 4 verts to a single triangle that circumscribes the unit circle. You'll draw 3 verts instead of 4 per splat — a real optimization libraries use.
What's next
Episode 03 — Anisotropy: the Covariance Matrix. We give each splat a 3-axis scale and a rotation, turning round blobs into oriented ellipsoids, and we do the math that projects a 3D ellipsoid onto the screen as a 2D ellipse. This is the heart of 3D Gaussian Splatting — the step that lets a pile of blobs reconstruct a crisp surface. Our nebula becomes a planet.