Neural rendering: NeRF, Instant-NGP and 3D Gaussian splatting
Three ways to fit one 3D scene from posed photos and render new views of it: a network queried along rays (NeRF), hash-grid features that train in minutes (Instant-NGP), and millions of blended Gaussians (3DGS).
What runs in CodeSplash
- VIS018Neural Radiance Fields (NeRF, original) Explained here
- VIS019Instant-NGP multiresolution hash encoding Explained here
- VIS0203D Gaussian Splatting (original) Explained here
You will be able to
- Compute a pixel's color by volume rendering along a ray
- Explain what a multiresolution hash encoding stores and why it is fast
- Describe a scene made of 3D Gaussians and how it is drawn
- Judge a fitted scene on held-out views and on geometry, not on training views
Fit a scene, not a model
ReadTake a hundred photos walking around an object, recover each camera's position and direction (structure from motion), and fit a representation of that one scene that reproduces every photo. Then render it from viewpoints no photo was taken from.
That's different from everything earlier in this track. Nothing is pretrained and nothing transfers: each scene gets its own fit, often millions of numbers describing one room or one statue.
NeRF: color along a ray
ReadA neural radiance fieldNeural radiance field (NeRF)A network fitted to one scene that maps a 3D point and view direction to density and color, rendered by volume rendering. is an MLP that takes a 3D point and a viewing direction and returns a density (how much stuff is there) and a color. To draw a pixel, cast its ray, sample points along it and combine them by volume renderingVolume renderingColoring a pixel by walking along its ray and adding each sample's color, weighted by how much light still gets through.: each sample's weight is the light still arriving there times the share it stops.
The program samples red, green and blue points along one ray. Their weights are 0.139, 0.388 and 0.238; the remaining 0.235 goes to the background, so everything sums to one.
The compositing rule
ReadTraining compares rendered pixels with the photos and backpropagates through this sum into the network's weights.
import numpy as np
sigma = np.array([0.3, 1.2, 0.7]) # density at each sample
delta = np.array([0.5, 0.5, 1.0]) # distance to the next sample
rgb = np.eye(3) # red, green, blue samples
alpha = 1 - np.exp(-sigma * delta) # share each sample stops
trans = np.exp(-np.r_[0, np.cumsum(sigma * delta)[:-1]]) # light still arriving
weights = trans * alpha
background = np.exp(-np.sum(sigma * delta))
print(weights, background, weights @ rgb + background) # white backgroundsigma <- c(0.3, 1.2, 0.7) # density at each sample
delta <- c(0.5, 0.5, 1.0) # distance to the next sample
rgb <- diag(3) # red, green, blue samples
alpha <- 1 - exp(-sigma * delta) # share each sample stops
trans <- exp(-c(0, head(cumsum(sigma * delta), -1))) # light still arriving
weights <- trans * alpha
background <- exp(-sum(sigma * delta))
print(list(weights, background, as.vector(weights %*% rgb) + background))A wall in front
PredictPredict first
The first sample along a ray has a very large density. What color does the pixel get?
Reveal
Almost only the first sample's color. It stops nearly all the light, so the samples behind it get transmittance near zero. Occlusion falls out of the rendering rule; nobody programs it.
Instant-NGP: store features, not knowledge
ReadOriginal NeRF took a day per scene: every sample ran a deep MLP. Instant-NGP moves most of the work into a multiresolution hash encodingMultiresolution hash encodingLearned feature vectors stored in hash tables at several grid sizes, looked up and interpolated for each 3D point.: learned feature vectors sit at the corners of grids of several sizes, stored in hash tables. A point looks up the corners around it at each size, interpolates, concatenates, and a tiny MLP does the rest.
In the program a point is looked up on a coarse and a finer grid, giving four features: 0.602, 0.665, 0.305 and 0.367. Hash collisions are allowed; training sorts them out. Scenes fit in minutes.
3D Gaussian splatting: no network at all
Read3D Gaussian splatting3D Gaussian splattingA scene stored as millions of colored, semi-transparent 3D Gaussians, projected and blended onto the image in depth order. stores the scene as millions of small Gaussians, each with a position, a shape (a covariance from a scale and a rotation), an opacity and a view-dependent color. To render, project every Gaussian to an ellipse on the image, sort by depth and blend front to back with the same rule as NeRF.
In the program one projected ellipse has covariance entries 0.43 and 1.26 on the diagonal; at a pixel off its center it contributes 0.67 of its opacity. Rendering is rasterization, so it runs in real time.
Pretty views, wrong shape
ReadAll three are judged by how well they reproduce views, which is not the same as getting the geometry right. Hold out some photos and score renders of those, and check depth or surface quality separately where it matters. Shiny, transparent or moving things, and sparse viewpoints, produce floating blobs that look fine from training cameras.
Check: neural rendering
CheckpointCheck yourself
What does a NeRF's network take in and give back?
Show the answer
Answer: a
The network describes the scene point by point. Images come only from rendering many points along rays.
Check yourself
Along a ray, the weights of the samples plus the background share always add up to what?
Show the answer
Answer: a
Transmittance starts at one and each sample removes a share of what's left, so the shares and the remainder sum to one.
Check yourself
You fit a NeRF to photos of your kitchen. Can you use it to render your neighbor's kitchen?
Show the answer
Answer: b
A NeRF is a scene representation, not a pretrained model. A new scene needs its own photos, poses and fit.
Check yourself
Why does Instant-NGP fit a scene so much faster than the original NeRF?
Show the answer
Answer: a
A table lookup and interpolation are cheap; a deep MLP per sample is not.
Check yourself
Two distant points hash to the same table entry. What happens?
Show the answer
Answer: b
Collisions are tolerated by design: points rarely collide at every resolution, and gradients from busy regions dominate.
Check yourself
Which of these is NOT stored for each Gaussian in 3D Gaussian splatting?
Show the answer
Answer: d
There is no network at render time: the scene is the list of Gaussians, which is why it renders in real time.
Check yourself
How are overlapping Gaussians combined into a pixel?
Show the answer
Answer: a
Front-to-back blending makes near, opaque Gaussians hide what's behind them.
Recap
Recap- These methods fit one scene from posed photos; nothing transfers to another scene.
- NeRF renders a pixel by weighting samples along its ray by transmittance times opacity.
- Instant-NGP stores detail in multiresolution hash-grid features and needs only a tiny network.
- 3D Gaussian splatting blends projected Gaussians in depth order, with no network, in real time; judge all three on held-out views and geometry.
Concepts in this lesson