3D Vision

A photo keeps the direction to each point and loses the distance. Getting 3D back starts with a choice: how to store a shape. On this ring at 64 cells across, a voxel grid stores 4,096 cells and answers “inside?” in one lookup. The 252 surface points take 504 numbers and cannot answer at all.

Pick a way to store the ring, set the detail and move the probe. Read what each one stores and what it can answer. Then we build each one, from a single pixel to a radiance field you train from photos.

You need what a neural network layer is and basic vectors. We build the rest from zero.

Follows the 3D Vision lecture of Stanford CS 231n. It leads to NeRF and 3D Gaussian Splatting and Multi-View Geometry.

Store one ring five ways

64 across

Illustrative 2-D slice: a ring of centre radius 0.75 and half-thickness 0.22 in a box 2.4 wide. Detail sets the cell size (2.4 divided by the count). Points and mesh vertices sit one cell apart; Gaussians sit two cells apart and store 6 numbers each. You can also drag the probe on the picture. In 3-D the grid grows as N³ and the surface as N², so the gap widens.

Chapter 0

One Photo Gives a Ray, Not a Point

Slide a point along its ray and watch its pixel refuse to move

A robot arm must grasp a mug. Its camera returns a grid of colours, and the handle sits at pixel column 100. The arm needs the distance to the handle in centimetres. The photo does not hold it.

A camera keeps the direction to each point and loses the distance. Every point on one line from the lens lands on the same pixel. That line is a ray. A small mug up close and a big mug far away make the same picture.

So inverse graphics, getting the 3-D scene back from images, is hard. Rendering goes forward: scene in, one image out. Going backward has many answers. We need more: a second view, a depth sensor, or a learned sense of which shapes are likely.

Slide along the ray

Top view. Camera A (yellow) sees the point at one pixel. Drag the depth. Then switch on camera B, half a metre to the right, and drag again.

2.00 m

Illustrative pinhole, exact geometry: focal length 500 px, no lens distortion. The point stays on camera A's ray through pixel 100, so its offset is always 0.2 times its depth. Camera B sits 0.5 m to the right of A, facing the same way.

Call the lens's focal length f, in pixels. Call the point's sideways offset from the lens axis X and its depth along the axis Z, both in metres. The pixel column where it lands is u.

Say it aloud

u equals f times X over Z.

u
u the pixel column, counted from the image centre.
f
f the focal length in pixels: 500 here.
X
X the point's sideways offset from the lens axis, in metres.
Z
Z the point's depth along the lens axis, in metres.
In plain words

Divide the offset X by the depth Z, then multiply by f. The result is the pixel u. Only the ratio of X to Z survives, so scaling both by the same factor leaves u where it was.

With numbers

A point 0.4 m right and 2 m deep: u = 500 × 0.4 / 2 = 100 px. A point 0.8 m right and 4 m deep: u = 500 × 0.8 / 4 = 100 px again. Two different points, one pixel.

A second camera breaks the tie. Camera B sits 0.5 m to the right, so it sees the offset X minus 0.5. At 2 m deep it reads −25 px; at 4 m it reads +37.5 px. Now each depth has its own pixel pair. Chapter 9 uses this with many views to train a whole scene.

The idea of the lesson. A photo gives rays. 3-D vision picks a way to store shape, then fits it to rays from many views, or to a prior learned from many shapes.
Failure: depth from one photo with no prior. Symptom: a toy car on a desk reads as a real car far away. Measure: put an object of known size in view and compare its estimated distance with a tape measure. Fix: add a second view, a depth sensor, or a known-size reference.

The road

  1. Explicit shapes: points and meshes store the surface itself.
  2. Implicit shapes: a distance function answers “inside?” at once.
  3. Grids and views: voxels hit a cubic wall; octrees and 2-D views get around it.
  4. PointNet: a network that does not care about point order.
  5. Deep implicit functions: a network becomes the distance function.
  6. Volume rendering: turn densities along a ray into one pixel.
  7. Sharp detail: positional encoding and smarter samples.
  8. Gaussian splatting: blobs projected onto the screen.
  9. Showcase: train a radiance field from photos, here.
  10. Field guide: the numbers, the trade-offs, the code.
Why can one photo not tell how far away a point is?

Chapter 1

Points and Meshes Store the Surface

Ask a point cloud and a mesh whether a probe is inside, and count the work

The most direct way to store a shape is to store its surface. That is an explicit representation: you keep points that lie on the surface. Asking for a surface point is free, because you already have a list of them.

A point cloud is an unordered set of 3-D points, each an (x, y, z), sometimes with a colour or a surface direction. A LiDAR scanner and a depth camera produce exactly this. It is simple and compact, but it has nothing between its points: no surface, no inside, no outside.

A triangle mesh adds the missing glue. It keeps a list of vertices, the 3-D points, and a list of faces, each a triple of vertex numbers. The triangles tile a surface. Games, films and CAD tools all draw meshes.

Ask “inside?”

Drag the probe on the picture. With the mesh, a ray runs to the right and every edge it crosses lights up. Then break one edge and try again.

20

Illustrative 2-D shape: an outer loop and a hole, each a polygon. In 2-D a mesh face is an edge; in 3-D it is a triangle and the same crossing count works with a ray against triangles.

The mesh answers “inside?” by casting a ray. Count the edges the ray crosses: an odd count means inside, even means outside. The answer is right, but it costs a test against every edge. The point cloud cannot answer at all.

Memory is easy to count. A closed triangle mesh with no holes through it has about twice as many faces as vertices; Euler's rule gives faces = 2 × vertices − 4. One million vertices at 3 floats of 4 bytes is 12 MB. The 1,999,996 faces at 3 integers of 4 bytes are 24 MB. That is about 36 MB for a detailed scan.

A third explicit form is the parametric surface: a formula that turns two numbers into a 3-D point. A sphere of radius R is (R sin φ cos θ, R sin φ sin θ, R cos φ). Sampling means evaluating the formula. Splines glue many such patches together.

Failure: a mesh with a hole in its skin. Symptom: some points far outside the shape test as inside. Measure: check that every edge is shared by exactly two faces (a watertight mesh). Fix: close the gaps before any inside test, or switch to an implicit form (Chapter 2).
What does a mesh need to answer “is this point inside?”

Chapter 2

A Distance Function Answers “Inside?” at Once

Store a function of space, read its sign, and pull the surface out with a grid

Flip the idea. Do not store the surface. Store a function you can ask at any point in space. Its sign says inside or outside, and the surface is wherever it equals zero. That is an implicit representation.

The most useful one is the signed distance function (SDF). At each point it gives the distance to the nearest surface point, negative inside and positive outside. Take a sphere. Call its centre c, its radius r and a query point x. The SDF is d.

Say it aloud

d of x equals the length of x minus c, minus r.

d(x)
d of x the signed distance at the query point x: negative inside, zero on the surface, positive outside.
‖ x − c ‖
the length of x minus c the straight-line distance from the centre c to the query point x.
r
r the sphere's radius.
In plain words

Measure how far x is from the centre c. Subtract the radius r. The result d tells you how far x is from the skin and, by its sign, which side it is on.

With numbers

Centre at the origin, r = 1. At x = (2, 1, 2) the length is 3, so d = 3 − 1 = 2: outside, 2 from the skin. At x = (0.3, 0.4, 0) the length is 0.5, so d = −0.5: inside, half a unit deep.

Shapes combine with one operation each. The union of two SDFs is their minimum; the intersection is their maximum; A minus B is the maximum of A and minus B. This is constructive solid geometry (CSG), the way CAD tools cut a pipe from two cylinders. A smooth minimum blends shapes like two drops merging.

Combine two shapes

Teal is inside, blue is outside, brighter near the skin. The warm line is the surface pulled from the grid; the dashed line is the exact one. Pick an operation, drag the probe, and coarsen the grid.

12 × 12

Illustrative 2-D field: a circle of radius 0.5 and a square box of half-width 0.38. Marching squares pulls out the surface, with straight-line interpolation along each cell edge. The smooth blend uses a polynomial smooth minimum of width 0.25.

Testing a point is now one evaluation. Getting the surface back is the hard part. Marching cubes samples the function on a grid. Each cube has 8 corners, each inside or outside: 28 = 256 patterns, which symmetry reduces to 15 cases. Each case has a fixed set of triangles, placed by interpolating where the sign flips. The device runs the 2-D version, marching squares, with 16 patterns.

Failure: an implicit function that is not a distance. Symptom: a ray marcher that steps by the function value jumps through thin walls. Measure: at x = (2, 1, 2), the sphere function x² + y² + z² − 1 gives 8, while the true distance is 2. Fix: use a true SDF, or step by a fraction of the value.
An SDF reads −0.2 at a point. What do you know?

Chapter 3

Grids Hit a Cubic Wall

Count the cells a voxel grid wastes, and refine only where the surface is

Images are grids of pixels, and convolutional networks love grids. So the first idea for learning 3-D was a grid of voxels, volume pixels, each marked full or empty. Slide a 3 × 3 × 3 filter through it and you have a 3-D convolutional network.

The price is cubic. A grid with N cells per side has N³ cells: 32,768 at 32, 2,097,152 at 128, and 16,777,216 at 256. That last one is 67 MB as 4-byte floats, for one shape. Most of those cells are empty air or solid inside. The shape's detail lives in a thin shell at the surface, and the shell grows only as N².

Refine only the surface

The same circle, stored as a uniform grid or as a quadtree. Raise the depth and compare the cell counts.

32 across

Illustrative 2-D quadtree on a circle of radius 0.45 in a unit box: a cell splits into 4 while it touches the outline. The 3-D numbers in the read-out count a sphere of radius 0.45 the same way. There, an octree stores 8 children for every cell that touches the surface.

An octree fixes the waste. Start with one cube. Split a cube into 8 only if it touches the surface, and repeat. Empty and solid regions stay as big blocks. For a sphere at 256 per side, the octree holds about 773,000 nodes against 16.8 million uniform cells, 22 times fewer. Double N and the octree grows 4 times, the grid 8 times.

A second escape skips 3-D grids. A multi-view CNN renders the shape from 12 directions and runs an ordinary image network on each picture. Then it takes the element-wise maximum of the 12 feature vectors. On the 40-class ModelNet40 benchmark, Su et al. (2015) reached 89.9% accuracy, against 77.3% for the voxel network 3D ShapeNets. The image network had first learned from millions of photos.

Failure: a 3-D grid at image resolution. Symptom: the network runs out of GPU memory, or the shapes come out blocky. Measure: N³ times the bytes per cell times the channels. Fix: an octree or sparse grid that stores only occupied cells, or a representation without a grid (Chapters 4 and 5).
You double a voxel grid from 128 to 256 per side. What happens to memory, and what to an octree of the same surface?

Chapter 4

A Network That Ignores Point Order

Run one small network on every point, then keep the largest value of each feature

A LiDAR scan arrives as a list of points. The list has an order, but the order means nothing: shuffle it and the shape is the same. A plain network that reads the points as one long vector gives a different answer for every shuffle. N points have N! orders, so you cannot teach it all of them.

We need a function whose answer does not change when you reorder the inputs. That is permutation invariance. Sum, mean and maximum all have it. PointNet (Qi et al., 2017) builds a network around the maximum.

Call the points x1 to xN. Call the small network run on each point f; it is the same network, with shared weights, for every point. Call the network that reads the pooled vector g. The output is h.

Say it aloud

h of x-one to x-N equals g of the max over i of f of x-i.

h(x1, …, xN)
h of x-one to x-N the network's answer for the whole set of points, for example class scores.
g
g a small network that reads the pooled vector and gives the answer.
maxi
the max over i for each feature separately, the largest value over all N points.
f(xi)
f of x-i the shared network applied to point x-i alone: a feature vector of length K.
In plain words

Run f on each point x-i by itself. For every feature, keep the largest value over all points. Feed that one vector to g. Reorder the points and every maximum stays the same, so h stays the same.

With numbers

With made-up numbers: points (1, 0), (0, 2) and (−1, 1), and a toy f(p) = (px + py, py − px). The features are (1, −1), (2, 2) and (0, 2). The max is (2, 2) in any order. With g = the sum, h = 4.

Shuffle the points

Each row is one point's feature vector from the shared network f. The bottom row is the pooled vector. Shuffle the rows, then switch the pooling to an order-dependent reader and shuffle again.

Illustrative: 8 points in 2-D, a fixed random f with 6 ReLU features, and no training. “Ordered” weights row i by a different number for each position, the way a plain network would read a list.

The real PointNet maps each point through shared layers of width 64, 64, 64, 128 and 1024, max-pools to one 1024-long vector, and classifies it. It reached 89.2% on ModelNet40. The points that win at least one maximum are its critical points: they alone decide the answer, so a sparse skeleton is enough.

For labelling each point, PointNet glues the pooled vector back onto each point's own features and runs a per-point classifier. Its weakness is that points meet only at the final max. PointNet++ applies PointNet inside small neighbourhoods first, then repeats on the results, like a convolution.

Failure: reading the points as an ordered vector. Symptom: the same scan gets different labels after a re-sort. Measure: shuffle a test cloud 10 times and count label changes. Fix: a symmetric pool such as max, after a shared per-point network.
Why does PointNet give the same answer after the points are shuffled?

Chapter 5

A Network Becomes the Distance Function

Feed a point and a shape code to one network, and fill in the half you never saw

Voxels cost N³. Point clouds have no surface. Meshes are hard for a network to output, because it must choose both the points and how they connect. Chapter 2 offers a way out: a function of space. Let a network be that function.

DeepSDF (Park et al., 2019) trains one network for a whole family of shapes, such as chairs. Its input is a query point and a short vector, the latent code, that says which chair. Its output is the signed distance. The network has eight fully connected layers of 512 units, and every shape shares its weights.

Call the network fθ with weights θ. Call the code of shape i zi, a query point x and its true distance s. A clamp limits both distances to plus or minus δ.

Say it aloud

L equals the sum over shapes i and samples x and s, of the absolute value of clamp of f-theta of x and z-i, minus clamp of s.

L
L the training loss: the total distance error.
Σi Σ(x, s)
the sum over shapes i and samples x and s add one term for every sampled point of every training shape.
clamp
clamp of cut a distance to the range minus delta to plus delta. DeepSDF uses delta = 0.1.
fθ(x, zi)
f-theta of x and z-i the network's predicted distance at point x for the shape with code z-i.
s
s the true signed distance at x, measured from the training mesh.
In plain words

For each sample, ask the network for the distance at x, given the shape's code z-i. Clamp the prediction and the truth s to delta. Add up the gaps. Training lowers L by changing both the weights theta and every code z-i.

With numbers

With made-up numbers and delta 0.1: predicted 0.35, true 0.50. Both clamp to 0.1, so the gap is 0: far from the skin, close enough. Predicted 0.03, true 0.05: gap 0.02. Predicted −0.02, true 0.04: gap 0.06, the wrong side of the skin.

The clamp spends the network's effort near the surface, where shape detail lives. There is no encoder. Each training shape's code is a free variable, found by gradient descent with the weights. This is an auto-decoder. For a new scan, freeze θ and search only for the code that best fits the observed points.

Fit a code to half a scan

Yellow dots are the scan: points seen on the target's surface. Fit the code and watch the purple shape grow. Narrow the scan, or pick a target the family never contained.

40%

Illustrative. The “trained decoder” is a fixed hand-made function in place of the network. Code z1 blends a circle into a rounded square; code z2 sets the size. The fit runs 80 steps of gradient descent on the clamped loss with delta 0.1.

Occupancy networks (Mescheder et al., 2019) predict the chance that a point is inside, trained with cross-entropy. An encoder maps an image or a scan to the code in one pass. Either way, a mesh comes out by evaluating the network on a grid and running marching cubes.

Failure: a target outside the family. Symptom: the fit is smooth and confident but has the wrong shape. Measure: the loss on the observed points stays high after the fit. Fix: train on a family that covers the target, or fit more freedom than a code.
At test time, DeepSDF sees a new partial scan. What does it change?

Chapter 6

Volume Rendering Turns Density Into a Pixel

March along one ray and add each sample's colour, weighted by the light that reaches it

DeepSDF learns from 3-D meshes, which are expensive to collect. Photos are cheap. Learning from photos needs a renderer that lets gradients flow from each pixel back to the model: differentiable rendering.

NeRF (Mildenhall et al., 2020) stores a scene as a network. In: a 3-D position and a viewing direction. Out: a colour and a density σ, how strongly that point blocks light per unit length. Colour also depends on direction, so a highlight can move as you walk past.

To draw one pixel, take samples along its ray. Sample i stands for a stretch of length δi with density σi. The share of light it stops is its opacity αi.

Say it aloud

Alpha-i equals one minus e to the minus sigma-i delta-i.

αi
alpha-i the opacity of sample i: the share of arriving light it stops, from 0 to 1.
e
e to the minus the exponential: e to the minus (sigma-i delta-i) is the share that gets through.
σi
sigma-i the density at sample i, per unit length.
δi
delta-i the length of ray that sample i stands for.
In plain words

Multiply the density sigma-i by the stretch length delta-i. Take e to the minus that: the share of light that passes. One minus it is alpha-i, the share stopped.

With numbers

With made-up numbers and delta 0.5: density 2 gives alpha = 1 − e−1 = 0.632. Density 4 gives 1 − e−2 = 0.865. Density 0, empty air, gives alpha 0.

Add the samples front to back. The transmittance Ti is the light still left at sample i. Sample i adds its colour ci, weighted by Ti times αi, to the pixel colour C.

Say it aloud

C equals the sum over i of T-i alpha-i c-i, where T-i is the product over j before i of one minus alpha-j.

C
C the colour of the pixel.
Σi
the sum over i add one term for each sample, front to back.
Ti
T-i the transmittance: the share of light that reaches sample i. It starts at 1.
αi
alpha-i the opacity of sample i, from the equation above.
ci
c-i the colour the model gives at sample i.
Πj<i
the product over j before i multiply one factor for each earlier sample j.
In plain words

Walk the samples in order. Each one takes the share alpha-i of the light T-i that is still left and paints it with its colour c-i. Then T shrinks by the factor one minus alpha-i. Add the paint. That is C.

With numbers

The three samples above, front to back: air, clay at density 2, sea at density 4. Weights: 0, then 1 × 0.632 = 0.632, then 0.368 × 0.865 = 0.318. The 0.050 left goes to the background. The pixel is 63% clay, 32% sea and 5% background.

Render one ray

Pink bars are each sample's weight, T times alpha; the dashed line is T. Raise the clay blob's density, then cut the samples to 4.

2.0
8

Illustrative 1-D scene, 4 units long: clay from 1.0 to 1.5, sea of density 4 from 2.5 to 3.0, grey background. Each sample reads the density at its midpoint. At 8 samples the stretch is 0.5, as in the worked example.

Every step is a multiply, an add or an exponential, so gradients flow back to every density and colour. NeRF trains on posed photos with the squared pixel error. Occlusion comes for free: once T falls near zero, everything behind gets no weight.

Failure: too few samples. Symptom: a thin object flickers or vanishes. Measure: render with N and 2N samples and compare. Fix: more samples, or samples where the surface is (Chapter 7).
A dense blob sits in front of a bright one on the same ray. Why does the bright one barely show?

Chapter 7

Sharp Detail Needs Fast Waves

Rewrite each coordinate as sines and cosines, then spend samples where the surface is

A network fed raw (x, y, z) draws blurry scenes. Trained by gradient descent, networks learn smooth, slowly changing functions first. This tendency is called spectral bias. Bricks, text and leaves change fast across space.

NeRF's fix is positional encoding. Before the network sees a coordinate p, replace it with sines and cosines at doubling frequencies. Call the number of frequencies L and the frequency index k. The encoding is γ(p).

Say it aloud

Gamma of p equals the sine and cosine of two to the k, times pi, times p, for k from zero to L minus one.

γ(p)
gamma of p the encoded coordinate: a list of 2L numbers.
sin, cos
sine and cosine two waves a quarter turn apart, so together they pin the phase.
2k
two to the k the frequency: 1, 2, 4, 8 and so on. Each step doubles it.
p
p one coordinate, x, y or z, scaled to the range 0 to 1 here.
k = 0, …, L − 1
k from zero to L minus one L frequencies in all. NeRF uses L = 10 for position and 4 for direction.
In plain words

For each k from 0 to L minus 1, multiply p by pi and by 2 to the k. Take the sine and the cosine. List all 2L numbers. Do it for x, y and z separately and feed the list to the network.

With numbers

p = 0.3 and L = 3. For k = 0: sin(0.3π) = 0.809, cos = 0.588. For k = 1: 0.951 and −0.309. For k = 2: −0.588 and −0.809. NeRF's position encoding has 3 × 2 × 10 = 60 numbers.

Fit a sharp signal

The dashed line is the signal: square steps with a fast ripple. The purple line is a small network learning it, live. Set L to 0 (raw input) and train, then try 4.

4

Illustrative and seeded; it runs in your browser. The network has 2 hidden layers of 32 ReLU units, trained by Adam at learning rate 0.01 on 128 points, full batch. L = 0 feeds the raw coordinate; L above 0 feeds the 2L encoded numbers. The signal’s variance is 0.27.

The second trick saves work. Most of a ray is empty air. NeRF first takes Nc = 64 even samples with a coarse network. It reads their weights Tiαi as a map of where the surface is. It then draws Nf = 128 more samples there and runs all 192 through a fine network.

The cost is still large. Each ray needs 64 + 192 = 256 network queries. An 800 × 800 image has 640,000 rays, so about 164 million queries per frame. The NeRF paper reports about 30 seconds per frame on one V100 GPU, and 1 to 2 days of training per scene.

Failure: frequencies the views cannot support. Symptom: crisp training views but speckle and floating blobs in new views. Measure: score a held-out view, not a training view. Fix: fewer frequencies, more views, or add high frequencies gradually during training.
Why does a NeRF without positional encoding look blurry?

Chapter 8

Gaussian Splatting Throws Blobs at the Screen

Project fuzzy ellipses onto the image, sort them by depth, and composite front to back

NeRF asks a network hundreds of times per pixel. 3D Gaussian Splatting (Kerbl et al., 2023) stores the scene as a few million explicit, fuzzy blobs and draws them onto the screen. Each 3-D Gaussian has a centre, an opacity and a colour that can change with the view direction. A 3 × 3 covariance sets its size and tilt.

To render, project each Gaussian onto the image. A 3-D Gaussian lands as a 2-D Gaussian with covariance J W Σ WT JT. Here W turns world axes into camera axes, and J is the local stretch of the perspective. Then sort the splats by depth and composite them with Chapter 6’s rule.

Only the opacity changes. Call splat i’s opacity oi, its projected centre μ′i, its projected covariance Σ′i, and the pixel p. Its opacity at that pixel is αi(p).

Say it aloud

Alpha-i of p equals o-i times e to the minus one half, p minus mu-prime-i transpose, Sigma-prime-i inverse, p minus mu-prime-i.

αi(p)
alpha-i of p how much of pixel p splat i covers, from 0 to 1.
oi
o-i the splat’s learned opacity at its centre.
p − μ′i
p minus mu-prime-i the gap from the splat’s projected centre to the pixel, in pixels.
Σ′i−1
Sigma-prime-i inverse the inverse of the splat’s 2-D covariance: it measures the gap in units of the splat’s own width along each axis.
In plain words

Measure the gap from pixel p to the centre mu-prime-i, in units of the splat’s width given by Sigma-prime-i. Square it, halve it, and take e to the minus that. Multiply by the opacity o-i.

With numbers

With made-up numbers: a round splat 2 px wide (covariance 4 px²), a pixel 2 px from its centre, opacity 0.8. The exponent is −½ × 4 / 4 = −0.5, and e−0.5 = 0.607. So alpha = 0.8 × 0.607 = 0.485.

Composite the splats

Three splats: clay in front, then sea, then a grey one at the back. Drag the probe pixel. Stretch and turn the front splat, then switch off the depth sort.

30°
2.2×

Illustrative 2-D splats with opacities 0.8, 0.9 and 0.9. With the sort off, the splats composite in storage order, back one first.

Training starts from the sparse 3-D points that camera calibration (structure from motion) already produced: one Gaussian per point. The loss is 0.8 times the L1 pixel error plus 0.2 times a structural error term (D-SSIM). Every 100 iterations it densifies. It clones small Gaussians where detail is missing and splits large ones into two, with their scale divided by 1.6. It removes nearly transparent ones.

After 30,000 iterations the paper’s scenes hold 1 to 5 million Gaussians and render at 30 frames per second or more at 1080p. The price is memory: millions of blobs in place of one small network.

Failure: compositing without a depth sort. Symptom: background splats paint over the object in front. Measure: switch the sort off in the device and read the shares at one pixel. Fix: sort by depth every frame; the paper sorts on the GPU per screen tile.
Why is Gaussian Splatting fast where NeRF is slow?

Chapter 9

Showcase: Train a Radiance Field From Photos

Fit a grid of density and colour to flat photos, and watch one view fool you

Here is the whole method in a flat world. Two coloured disks sit in a square. Cameras around them each take a photo: a row of 32 pixels. The model is a 17 × 17 grid of numbers holding density and colour, with no network, like the Plenoxels method. Chapter 6’s rule renders the grid into photos, and the optimiser Adam nudges every number to shrink the squared pixel error.

Train with one camera first. The training photo matches almost perfectly. Then look at the held-out camera, one the model never trained on. Density has smeared along the training rays, like the point that slid along its ray in Chapter 0. Switch to 3 cameras, then 12, and train again.

Train from photos

Left: the true scene and the training cameras (yellow). Middle: the learned grid, drawn with its own density and colour. Bottom: the held-out camera’s photo, true above and rendered below. Pick the views, then train.

Illustrative, deterministic, and it runs in your browser. Disks of radius 0.30 and 0.22 with density 12 sit in a 2 by 2 square. Cameras sit on a circle of radius 1.7 with a 71° field of view and take 48 samples per ray. The grid stores a density value and three colour values at each of its 289 corners, read by bilinear interpolation; Adam at learning rate 0.08. Shape overlap is the overlap of learned density above 3 with the true disks, on a 64 × 64 check grid.

Read the scores as PSNR, peak signal-to-noise ratio: 10 times the base-10 log of 1 over the mean squared pixel error. Higher is better; 20 dB means a typical error of a tenth of full brightness. With 1 view the training photo scores 57.2 dB, yet the held-out views score 10.9 dB and the shape overlap is 23%. With 3 views: 13.7 dB and 39%. With 12 views the held-out views reach 27.2 dB and the overlap 90%.

This is Chapter 0’s problem, solved the only honest way: more rays through the same point. Real NeRF and splatting systems need dozens to hundreds of photos for the same reason.

Failure: judging a 3-D model by its training photos. Symptom: near-perfect training scores and a broken shape from any new angle. Measure: PSNR on held-out views, here 57.2 dB on training against 10.9 dB held out with one camera. Fix: more views, spread around the object.
With one training camera the model matches its photo almost perfectly. Why is the held-out view still wrong?

Chapter 10

Field Guide

Keep the equations, the trade-offs, the numbers and the code in one place

A photo gives rays. Explicit forms store the surface and make sampling cheap; implicit forms store a function and make “inside?” cheap. Grids cost N³, so octrees, point networks and networks-as-functions avoid them. Volume rendering makes a scene trainable from photos, and splatting makes it fast to draw.

QuantityFormulaNumbers from this page
Projectionu = f X / Z0.4 m at 2 m and 0.8 m at 4 m: both 100 px
Sphere SDFd(x) = ‖x − c‖ − r(2, 1, 2): d = 2; (0.3, 0.4, 0): d = −0.5
VoxelsN³ cells256: 16.8 million; an octree about 0.77 million
PointNeth = g(maxi f(xi))features (1, −1), (2, 2), (0, 2): max (2, 2)
DeepSDF lossΣ |clamp(fθ(x, z)) − clamp(s)|delta 0.1: 0.35 vs 0.50 costs 0
Opacityα = 1 − e−σδσ 2, δ 0.5: 0.632
PixelC = Σ Tiαici63% clay, 32% sea, 5% background
Encodingsin, cos(2kπp)L = 10: 60 numbers per position
Splatα(p) = o · exp(−½ dTΣ′−1d)2 px off a 2 px splat, o 0.8: 0.485

Choose a representation

RepresentationCheapCostlyLearned by
Point cloudstoring, samplingno surface, no insidePointNet, PointNet++
Meshdrawing, editinginside test; outputting connectivitydeforming a template mesh
Voxelsinside test, 3-D convolutionN³ memory, blocky edges3-D CNNs, octree networks
SDF or occupancy netinside test, any resolutiona grid pass to get a meshDeepSDF, occupancy networks
Radiance fieldlearning from photoshundreds of queries per pixelNeRF, Instant-NGP
Gaussiansreal-time drawing, editingmillions of blobs in memory3D Gaussian Splatting

Checklist

  1. Decide which question must be cheap: sampling, “inside?”, drawing or learning. Pick the representation from that.
  2. For a mesh inside test, check the mesh is watertight first.
  3. For an implicit function, check it is a true distance before you step by its value.
  4. Count memory before you build a grid: N³ times bytes times channels.
  5. Feed point sets through a shared network and a symmetric pool, never as an ordered vector.
  6. For radiance fields, score held-out views, never only training views.
  7. Sort splats by depth every frame.
pythonimport numpy as np

def sdf_sphere(x, c, r):
    return np.linalg.norm(x - c, axis=-1) - r           # negative inside

def pointnet(points, f, g):
    feats = np.stack([f(p) for p in points])          # (N, K), same f for every point
    return g(feats.max(axis=0))                       # order cannot matter

def render_ray(sigma, color, delta, background):
    alpha = 1.0 - np.exp(-sigma * delta)                 # (S,)
    T = np.cumprod(np.concatenate([[1.0], 1.0 - alpha]))   # (S+1,), T[0] = 1
    w = T[:-1] * alpha                                  # weight of each sample
    return (w[:, None] * color).sum(0) + T[-1] * background

def encode(p, L):
    k = 2.0 ** np.arange(L) * np.pi                          # 1, 2, 4, ... times pi
    return np.concatenate([np.sin(k * p), np.cos(k * p)])

# the page's numbers: air, clay at sigma 2, sea at sigma 4, delta 0.5
print(render_ray(np.array([0., 2., 4.]), np.eye(3), 0.5, np.zeros(3)))   # [0. 0.632 0.318]

Keep going

References

The takeaway. Choose the representation by the question that must be cheap, and judge any 3-D model by a view it never trained on.
A robot must test thousands of points per second for collision with an object. Which representation fits best?

Now press Present or Teach and rebuild it from memory. Cover the ray, the SDF sign, the cubic wall and the max pool. Then cover the clamped loss, the pixel sum, the encoding and the splat. Then go back to the ring, put the probe in the hole, and say which representations get it right and what each one paid.

Credit

Follows the 3D Vision lecture of Stanford CS 231n, rebuilt on Engineermaxxing. Published numbers name their paper; every toy number on this page carries the word illustrative.

CS 231n · 3D Vision: From Pixels to Geometry
Next: NeRF and 3D Gaussian Splatting · Back to Gleams