- the volume rendering sum that turns densities and colors along a ray into a pixel color,
- the positional encoding that lets a small network represent fine detail,
- hierarchical sampling, which spends network evaluations where the ray actually stops,
- a fitted field for the Mip-NeRF 360 garden scene, with camera poses from Structure from Motion.
Code
Code
From the plenoptic function to a radiance field
The plenoptic function records the light that travels through every point of space in every direction. Chapter 1 of the book sets it aside because it is too large to measure. A radiance field is a version of it that you can fit. It assigns to each point and viewing direction two quantities: The color is the light that the point sends toward direction . It depends on the direction, so a shiny surface can look different from different sides. The density measures how much matter sits at . It depends only on the point, because a surface is either there or not, whichever way you look at it. A NeRF stores as a multilayer perceptron. Like the SIREN image, the network has no grid. You can query it at any point, and the network weights are the scene.Volume rendering
A camera pixel looks along a ray that leaves the camera center . Think of the density as the rate at which the ray hits a particle: over a short step the chance of a hit is . Let be the probability that the ray travels from the near bound to without a hit. It falls at a rate set by the density, is called the transmittance. The ray stops in with probability : it must survive up to and then hit something. The pixel color is the color at the stopping point, averaged over that distribution: To compute the integral, split the ray at sample points with gaps , and assume and are constant on each gap. The integral of over gap is then exact, and the color becomes a weighted sum: is the probability that the ray stops inside gap given that it reached it, and is the probability that it stops there at all. The weights sum to . They are a probability distribution over where the ray stops, plus the leftover chance that it passes through everything. The same weights give an expected depth, . The cell below draws one ray through a density with two bumps: a faint haze near and a solid surface near .Code
Code
Positional encoding
A plain MLP fed with raw coordinates learns smooth functions first and fine detail very slowly. NeRF passes each coordinate through a fixed map before the network, with for positions and for directions. The book links this to the positional encodings of transformers. The purpose here is different: the high-frequency sines let the network build sharp changes from a few combinations of its inputs. Tancik et al. analyze this effect (Tancik2020-hy). The experiment fits the same network to a 1D signal made of a slow sine, a square wave with 12 periods and a fast sine with 30 periods. It fits once on the raw coordinate and once on with .Code
Code
Hierarchical sampling
The weights show that a ray only needs samples near where it stops. Evenly spaced samples waste most network evaluations on empty air or on space hidden behind the first surface. NeRF therefore samples each ray twice:- A coarse network is evaluated at points spread evenly with a random jitter (stratified sampling). Its weights give a rough picture of where the ray stops.
- The normalized weights define a piecewise-constant probability density along the ray. more points are drawn from it by inverse transform sampling: draw , find the bin where the cumulative distribution crosses , and interpolate linearly inside that bin.
- A fine network is evaluated at all points, sorted, and the volume rendering sum gives the final color.
Code
Code
The garden scene
The real scene is garden from the Mip-NeRF 360 dataset: 185 photos of a table in a garden, taken while walking around it. The dataset ships with the output of COLMAP, the structure-from-motion program that Structure from Motion explains. COLMAP writes three binary files, described in Structure from Motion at Scale.cameras.bin holds the intrinsics. images.bin holds one pose per photo. points3D.bin holds the sparse point cloud.
You use the copy of the photos reduced 8 times and then halve them again, to pixels, so that a NeRF trains in minutes. Every 8th photo (sorted by name) is held out for testing. Gaussian Splatting uses exactly the same images and split.
Code
Code
Code
Code
Code
Code
An unbounded scene
The photos also show trees and a house far behind the table. Their distance has no useful upper limit, so evenly spaced samples along cannot cover both the table and the background. Mip-NeRF 360 (Barron2021-nb) solves this with a contraction that maps all of space into a ball of radius 2: Inside the unit ball nothing changes. Outside, a point at distance moves to distance , so the whole region from the unit sphere to infinity fits in the shell between radius 1 and 2. The network sees only contracted points. Along each ray you place half the coarse samples evenly in distance up to the unit sphere, and the other half evenly in disparity from the sphere out to . Samples evenly spaced in disparity land roughly evenly spaced in the contracted shell, so the network spends about as much effort on the background as on the table. In code, the samples live in a coordinate . The first half of maps linearly to distance and the second half maps linearly to disparity. Hierarchical sampling also works in .Code
Code
Fitting the field
The field network follows the paper’s layout at a smaller size for the coarse pass. Positions are contracted, divided by 2 so they lie in , and encoded with . The position MLP has a skip connection that feeds the encoding in again halfway. Its last layer gives the density and a feature vector. The color head takes the feature vector and the encoded direction (), so only the color can depend on the direction. A softplus keeps the density non-negative, and a sigmoid keeps the color in . The loss is the paper’s squared error on both renderings for a batch of random rays drawn from all training photos: Each step uses 4096 rays, and , and Adam with a learning rate that decays from to , as in the paper. Quality is measured by the peak signal-to-noise ratio, for colors in . Higher is better, and each 1 dB is about a 21% smaller squared error.Code
Code
Code
Code
Rendering the test views
To render a full image you cast one ray per pixel, with no jitter: the coarse points sit at bin centers and the fine points at evenly spaced values of . The expected distance from the fine weights gives a depth map at no extra cost. The figure shows it as disparity, , so that near objects are bright and the far background is dark.Code
Code
What a radiance field cannot do
A NeRF is fitted to one scene. It holds no knowledge that carries over to a new set of photos, and every new scene starts from random weights. It also depends on the camera poses: if structure from motion gets a pose wrong, the field blurs the content of that photo across space. Rendering is slow. Each pixel costs 192 network evaluations here, which is why one small test image takes the render time printed with the test score. Faster versions replace most of the network with lookup tables, such as the hash grid of Instant-NGP (Müller et al., 2022). The field also has no notion of light sources. Volume rendering lets light leave a point and reach the camera in a straight line, with no bounces. The book makes this point with the rendering equation: shadows, reflections and highlights become part of the fitted color, so you cannot move a light or change a material without fitting again. Gaussian Splatting keeps the rendering weights from this section but replaces the network with millions of explicit 3D Gaussians that start at the sparse COLMAP points (Kerbl et al., 2023). Rendering then needs no network evaluations at all, and it runs in real time.References
- Kerbl, B., Kopanas, G., Leimkühler, T., Drettakis, G. (2023). 3D Gaussian splatting for real-time radiance Field rendering. arXiv [cs.GR]. Link
- Müller, T., Evans, A., Schied, C., Keller, A. (2022). Instant neural graphics primitives with a multiresolution hash encoding. arXiv [cs.CV]. DOI
Found an error on this page? Report an issue.

