Explaining NeRF volume rendering
NeRF models volumetric density and view-dependent color per 3D point, rendering color by integrating density-weighted emitted radiance along camera rays. It approximates this integral via sampled points, with an MLP outputting density and RGB, using positional encoding of inputs through multi-scale sine/cosine functions to capture high-frequency details and reduce spectral bias.
A Neural Radiance Field is not a mesh or a collection of surface elements, it is an implicit volumetric function. The basic ingredients are
- a density field (\sigma(\mathbf{x})\geq 0) that tells you how “opaque” space is at a point (\mathbf{x}),
- an emitted radiance (c(\mathbf{x},\mathbf{d})) that tells you what colour would be emitted from that point if you looked at it from direction (\mathbf{d}).
Given those two fields, synthesising an image reduces to the standard volume rendering problem: shoot a ray (\mathbf{r}(t)=\mathbf{o}+t,\mathbf{d}) from the camera origin (\mathbf{o}) along direction (\mathbf{d}), and integrate all of the radiance along that ray, attenuated by how much density you have traversed. In continuous form, the colour of that pixel is
[
C(\mathbf{r}) = \int_{t_\text{near}}^{t_\text{far}} T(t),\sigma(\mathbf{r}(t)),c(\mathbf{r}(t),\mathbf{d}),\mathrm{d}t,
]
with the accumulated transmittance
[
T(t) = \exp!\left(-\int_{t_\text{near}}^{t} \sigma(\mathbf{r}(s)),\mathrm{d}s\right)
]
representing the probability that light travels from (t_\text{near}) to (t) without being absorbed. In practice NeRF evaluates the fields at a finite number of depths ({t_i}) and approximates these integrals with a quadrature rule:
[
\hat{C}(\mathbf{r}) = \sum_{i=1}^N \left( \exp!\Big(-\sum_{j<i}\sigma_i,\Delta t_j\Big)\right),\left(1-\exp(-\sigma_i,\Delta t_i)\right),c_i,
]
where (\sigma_i = \sigma(\mathbf{r}(t_i))), (c_i = c(\mathbf{r}(t_i),\mathbf{d})) and (\Delta t_i=t_{i+1}-t_i). The exponential factors implement the same transmittance as the continuous expression.
In NeRF these fields are not stored explicitly. A single multilayer perceptron is trained to approximate ((\sigma,c)) at any query point. The network takes a 3‑D location (\mathbf{x}) and a 2‑D viewing direction (\mathbf{d}) as input; one branch of its output produces a scalar (\sigma), and another branch produces an RGB vector (c). The view direction dependence allows it to model specularities and other view‑dependent effects.
Plain MLPs have a “spectral bias”: they tend to learn smooth, low‑frequency functions of their inputs. Real scenes, however, have high‑frequency structure such as sharp edges and fine textures. NeRF overcomes this by applying a positional encoding to the raw inputs before feeding them to the MLP. Each coordinate is mapped to a higher‑dimensional vector of sine and cosine at multiple frequencies, e.g.
[
\gamma(x) = (\sin(2^0\pi x),\cos(2^0\pi x),\sin(2^1\pi x),\cos(2^1\pi x),\ldots,\sin(2^{L-1}\pi x),\cos(2^{L-1}\pi x)),
]
and similarly for (y,z) and the viewing angles. By presenting the network with these Fourier features, you give it access to basis functions at a range of spatial frequencies. The MLP only has to learn linear combinations of these pre‑specified oscillations, which makes it much easier to fit high‑frequency detail than trying to synthesise those oscillations from low‑frequency inputs alone.