Skip to main content
Open In Colab A radiance field stores a scene as a function that you query at any point in space. Neural Radiance Fields fits that function with a network and renders a pixel by sampling it along the pixel’s ray. Gaussian splatting keeps the rendering rule and changes the storage. The scene becomes a list of 3D Gaussians, each with a position, a shape, an opacity and a color, and a pixel is rendered by blending the Gaussians that cover it in depth order (Kerbl et al., 2023). The book’s chapter on radiance fields lists a mixture of Gaussians as one of several ways to parameterize the same field. This section builds that parameterization from the ground up. You write the projection of a Gaussian onto the image, the compositing rule and the training loop yourself, fit the garden scene of the Mip-NeRF 360 dataset, and then check your renderer against gsplat, a reference implementation (Ye et al., 2024).

From samples on a ray to Gaussians on a ray

A NeRF renders the pixel with ray r\mathbf{r} from NN samples at depths t1<⋯<tNt_1 < \dots < t_N. Sample ii has density σi\sigma_i, color ci\mathbf{c}_i and spacing δi=ti+1−ti\delta_i = t_{i+1} - t_i. The rendered color is C(r)=∑i=1Nwi ci,wi=Ti αi,αi=1−e−σiδi,Ti=∏j<i(1−αj).\begin{aligned} C(\mathbf{r}) &= \sum_{i=1}^{N} w_i\, \mathbf{c}_i, \qquad w_i = T_i\, \alpha_i, \\ \alpha_i &= 1 - e^{-\sigma_i \delta_i}, \qquad T_i = \prod_{j<i} (1 - \alpha_j). \end{aligned} αi\alpha_i is the probability that the ray stops in interval ii given that it reached it, and TiT_i is the probability that it reached interval ii at all. The weights wiw_i sum to at most one. Gaussian splatting uses the same sum. The samples are replaced by the Gaussians whose footprint covers the pixel, sorted by the depth of their centers. For Gaussian ii with opacity oio_i and projected 2D density GiG_i, evaluated at pixel p\mathbf{p}, αi=oi Gi(p),wi=αi∏j<i(1−αj).\alpha_i = o_i\, G_i(\mathbf{p}), \qquad w_i = \alpha_i \prod_{j<i} (1 - \alpha_j). Nothing is sampled along the ray. The list of Gaussians plays the role of the samples, and their order along the ray comes from sorting. Sorting by the center is an approximation: two Gaussians that overlap in depth are still blended as if one were entirely in front of the other.

A Gaussian in three dimensions

Each Gaussian has a mean μ∈R3\boldsymbol{\mu} \in \mathbb{R}^3 and a covariance Σ\Sigma, a symmetric 3×33 \times 3 matrix that sets its size and orientation. Gradient descent on the six entries of Σ\Sigma could produce a matrix with a negative eigenvalue, which is not a covariance. The parameterization avoids this. Each Gaussian stores a rotation as a unit quaternion q\mathbf{q} and three log-scales s\mathbf{s}, and the covariance is built from them: Σ=R(q) S S⊤R(q)⊤,S=diag⁡(es1,es2,es3).\Sigma = R(\mathbf{q})\, S\, S^\top R(\mathbf{q})^\top, \qquad S = \operatorname{diag}(e^{s_1}, e^{s_2}, e^{s_3}). For any vector v\mathbf{v}, v⊤Σv=∥S⊤R⊤v∥2≥0\mathbf{v}^\top \Sigma \mathbf{v} = \lVert S^\top R^\top \mathbf{v} \rVert^2 \ge 0, so every parameter value gives a valid covariance. The eigenvectors of Σ\Sigma are the columns of RR, and its eigenvalues are the squared scales. The quaternion is normalized before use, so its length does not matter either. The opacity is o=sigmoid⁡(a)o = \operatorname{sigmoid}(a) for an unconstrained number aa, which keeps it in (0,1)(0, 1). Color may depend on the viewing direction, because a surface can look brighter from one side. Each Gaussian stores the color as a short expansion in spherical harmonics, functions on the sphere of directions. With degree 0 and degree 1 terms, the color seen along the unit direction d=(dx,dy,dz)\mathbf{d} = (d_x, d_y, d_z) from the camera to the Gaussian is c(d)=12+C0f0+C1(−dyf1+dzf2−dxf3),\mathbf{c}(\mathbf{d}) = \tfrac{1}{2} + C_0 \mathbf{f}_0 + C_1 \left( -d_y \mathbf{f}_1 + d_z \mathbf{f}_2 - d_x \mathbf{f}_3 \right), with C0=1/(2π)C_0 = 1/(2\sqrt{\pi}) and C1=3/(4π)C_1 = \sqrt{3/(4\pi)}, clipped below at zero. The vectors f0,…,f3∈R3\mathbf{f}_0, \dots, \mathbf{f}_3 \in \mathbb{R}^3 are learned per Gaussian. f0\mathbf{f}_0 is the view-independent color, and the degree 1 terms add a color that changes linearly with direction. The original method uses degree 3. Degree 1 keeps the parameter count small at this image size.

Projecting a Gaussian onto the image

A camera with rotation WW and translation t\mathbf{t} maps a world point to camera coordinates, x=Wμ+t\mathbf{x} = W \boldsymbol{\mu} + \mathbf{t}. The pinhole model of Camera Modeling then maps x=(x,y,z)\mathbf{x} = (x, y, z) to the pixel π(x)=(fx x/z+cxfy y/z+cy).\pi(\mathbf{x}) = \begin{pmatrix} f_x\, x / z + c_x \\ f_y\, y / z + c_y \end{pmatrix}. The mean of the Gaussian goes to π(Wμ+t)\pi(W\boldsymbol{\mu} + \mathbf{t}). The shape is harder, because a Gaussian pushed through a nonlinear map is no longer Gaussian. Around the mean, the projection is replaced by its first-order Taylor expansion, as in EWA splatting (Zwicker2005-au). The Jacobian of π\pi at x\mathbf{x} is J=(fx/z0−fxx/z20fy/z−fyy/z2).J = \begin{pmatrix} f_x / z & 0 & -f_x x / z^2 \\ 0 & f_y / z & -f_y y / z^2 \end{pmatrix}. A linear map AA sends a Gaussian with covariance Σ\Sigma to one with covariance AΣA⊤A \Sigma A^\top. The map from world coordinates to pixels is approximately A=JWA = J W, so the projected covariance is Σ′=JWΣW⊤J⊤+0.3 I2.\Sigma' = J W \Sigma W^\top J^\top + 0.3\, I_2 . The Taylor expansion is poor for a Gaussian whose center lies far outside the field of view, where x/zx/z or y/zy/z is large. In JJ, these ratios are therefore clamped to a little beyond the image border, 30%30\% of the half field of view past each edge. The mean itself is projected exactly. The term 0.3 I20.3\, I_2 widens every footprint by about half a pixel. It acts as a low-pass filter, so that a Gaussian smaller than a pixel still covers at least one pixel center instead of slipping between them. With u=π(Wμ+t)\mathbf{u} = \pi(W\boldsymbol{\mu} + \mathbf{t}) and d=p−u\mathbf{d} = \mathbf{p} - \mathbf{u} for pixel p\mathbf{p}, the opacity of the Gaussian at that pixel is α=min⁡(0.99,  oexp⁡(−12 d⊤Σ′−1d)).\alpha = \min\left(0.99,\; o \exp\left( -\tfrac{1}{2}\, \mathbf{d}^\top \Sigma'^{-1} \mathbf{d} \right)\right). The cap at 0.990.99 keeps 1−α1 - \alpha away from zero, so the gradient can still reach the Gaussians behind. Values below 1/2551/255 are set to zero, because they cannot change an 8-bit pixel. The footprint is cut off at three standard deviations along its long axis, a radius of 3λmax⁡(Σ′)3\sqrt{\lambda_{\max}(\Sigma')} pixels.

Compositing in depth order

Your renderer follows the formulas directly. It projects all Gaussians, drops those behind the camera or outside the image, sorts the rest by camera depth zz, and evaluates the compositing sum at every pixel. The product TiT_i is an exclusive cumulative product of 1−αj1 - \alpha_j over the sorted list. Evaluating every Gaussian at every pixel would need memory proportional to their product. The image is therefore split into square tiles of 16×1616 \times 16 pixels. A Gaussian is assigned to every tile that its three-sigma square touches, which gives one pair per tile and Gaussian. Sorting the pairs by tile, with a sort that keeps the depth order of equal keys, lists every tile’s Gaussians front to back. Tiles with lists of similar length are then processed together, each list padded to the longest one in its batch. The rasterizer of the original paper does the same computation on the GPU. It builds the same pairs, encodes each as one 64-bit key from the tile index and the depth, and sorts all keys with one radix sort. Each tile is then a contiguous run of the sorted keys. One thread block handles one tile, one thread handles one pixel, and a thread stops as soon as its transmittance falls below 10−410^{-4}. The backward pass walks the same list from back to front. The result is the same image, computed much faster, as the timing at the end of this section shows.
The figure shows four Gaussians in front of a camera. The left panel draws each projected covariance Σ′\Sigma' as its one- and two-sigma ellipses. The right panel is the output of the renderer. Where the orange Gaussian passes in front of the blue one, the blue one shows through only as far as TiT_i allows.
Left: four projected Gaussians drawn as solid one-sigma and dashed two-sigma ellipses in blue, orange, green and pink on a 160 by 120 pixel image plane. Right: the renderer's image of the same four Gaussians, soft colored blobs on black, with the orange one in front of the blue one.

The garden scene

The scene is the garden of the Mip-NeRF 360 dataset: 185 photos of a table with a vase, taken on a circle around it, together with the camera poses and sparse 3D points that Structure from Motion recovered from them. You read the three binary files of that reconstruction directly: the camera intrinsics, one pose per image, and the 3D points with their colors. The photos are used at one sixteenth of their full width, 324×210324 \times 210 pixels, with the intrinsics scaled to match. Every eighth image, in name order, is held out for testing, and the rest are used for training. Neural Radiance Fields uses the same images and the same split, so the test scores of the two pages compare directly.

Starting from the sparse points

Fitting Gaussians from random positions works poorly, because a Gaussian far from any surface receives almost no gradient. The sparse points of structure from motion already lie on the surfaces, so each point becomes one Gaussian. Its mean is the point, its color is the point’s color, its opacity is 0.10.1, and it starts as a sphere whose radius is the mean distance to its three nearest neighbors. Dense regions get small Gaussians and sparse regions get large ones, so the scene starts out roughly covered. The figure shows the sparse points projected into a training view next to the photo, and the image that the initial Gaussians render from the same camera.
Three panels for one training camera of the garden scene: the photo of a round table with a vase on a lawn; the sparse 3D points projected into the view as colored dots that trace the table, vase and background; and the blurry image rendered from the initial spherical Gaussians.

The loss

Training compares the rendered image I^\hat{I} with the photo II from the same camera. The loss mixes a per-pixel error with a structural one: L=(1−λ) ∥I^−I∥1+λ(1−SSIM⁡(I^,I)),λ=0.2.\mathcal{L} = (1 - \lambda)\, \lVert \hat{I} - I \rVert_1 + \lambda \left( 1 - \operatorname{SSIM}(\hat{I}, I) \right), \qquad \lambda = 0.2 . The ℓ1\ell_1 term is the mean absolute difference over pixels and channels. SSIM, the structural similarity index, compares local means, variances and covariances of the two images inside a Gaussian window of standard deviation 1.51.5 pixels. For local statistics mm, s2s^2 and s12s_{12}, SSIM⁡=(2m1m2+k1)(2s12+k2)(m12+m22+k1)(s12+s22+k2),\operatorname{SSIM} = \frac{(2 m_1 m_2 + k_1)(2 s_{12} + k_2)}{(m_1^2 + m_2^2 + k_1)(s_1^2 + s_2^2 + k_2)}, averaged over the image, with k1=0.012k_1 = 0.01^2 and k2=0.032k_2 = 0.03^2. It rewards renders whose edges and textures line up with the photo even where the absolute colors differ slightly.

Adding and removing Gaussians

The initial Gaussians are too few in some places and too many in others. Every 100 steps, training changes the set itself. The rule uses the gradient of the loss with respect to each projected mean ui\mathbf{u}_i. A large gradient means that the Gaussian keeps being pulled to cover an area that it cannot cover alone. Each step adds ∥∂L/∂ui∥\lVert \partial \mathcal{L} / \partial \mathbf{u}_i \rVert to a running sum for every visible Gaussian, with the gradient expressed in normalized image coordinates, where the image spans [−1,1][-1, 1]. When the average exceeds 0.00020.0002, the Gaussian is changed:
  • If its largest scale is at most 1%1\% of the scene extent, it is cloned. The copy starts at the same place and moves apart under later gradients. This fills regions that are under-reconstructed.
  • If it is larger, it is split into two Gaussians drawn from the original as a distribution, each with its scales divided by 1.61.6. This breaks up large Gaussians that cover detail they cannot represent.
The total number of Gaussians is capped at 120,000. Gaussians whose opacity falls below 0.0050.005 are removed. One third of the way through training, every opacity is reset to at most 0.010.01. Gaussians that matter recover their opacity within a few hundred steps, and the rest fall below the threshold and are removed. After the reset, Gaussians larger than 10%10\% of the scene extent are removed too. Splitting and cloning stop after 60%60\% of the steps, so the final set is refined without changing size.

Training

Each step picks one training view at random, renders it, and takes one Adam step on all parameters. The learning rate of the means decays exponentially by a factor of 100 over training, so that the positions settle at the end. The training loop takes the renderer as an argument, which lets you run it later with a different rasterizer.
Left: the training loss falling over the training steps, raw values faint and a moving average solid. Right: the number of Gaussians over the steps, rising to the cap of 120,000 by about step 700, dipping briefly after the opacity reset marked by a dashed line, then staying at the cap. The test views were never used for training. The figure compares three of them with the renders from the trained Gaussians. Two rows of three images. Top: held-out photos of the garden table from three viewpoints. Bottom: the renders of the trained Gaussians from the same cameras, each titled with its PSNR in decibels. The compositing weights along one pixel’s ray make the link to NeRF concrete. For a pixel on the table, the figure lists the Gaussians that cover it in depth order, with their αi\alpha_i, the transmittance TiT_i in front of each, and the weights wi=Tiαiw_i = T_i \alpha_i. The weights concentrate on the few Gaussians at the surface, just as NeRF’s weights concentrate on the samples where the ray stops. Bar chart over the Gaussians that cover one pixel, in depth order: blue bars for alpha, orange bars for the weight T times alpha, and a green line for the transmittance T, which starts at one and drops to near zero after a few Gaussians where the weights are concentrated.

Checking the renderer against gsplat

gsplat implements the tiled rasterizer of the paper in CUDA (Ye et al., 2024). Given the same Gaussians and the same camera, it should produce the same image as your renderer. It projects with the same clamped Jacobian, adds the same 0.3 I20.3\, I_2 and uses the same 1/2551/255 cutoff. Two details differ. gsplat stops compositing a pixel once its transmittance falls below 10−410^{-4}, while your renderer adds every remaining Gaussian, and the two add their terms in a different order in floating point. The mean difference stays far below one gray level of an 8-bit image, and the largest is a few gray levels.
Three panels for one test camera: the image from the page's renderer, the image from gsplat with the same Gaussians, and a heat map of their per-pixel absolute difference with a color bar; the difference is near zero almost everywhere.

The same training with a tiled CUDA rasterizer

The training loop runs unchanged with gsplat as the renderer: same initial Gaussians, same loss, same density control, same number of steps. Only the rasterizer differs, so any difference in training time comes from it.
The two runs reach similar test scores, because they optimize the same model with the same rule. The tiled CUDA rasterizer is what makes splatting fast. It processes all tiles in parallel and stops each pixel early, while your renderer loops over tiles in Python and evaluates every Gaussian in a tile at every pixel. The published method trains for 30,000 steps on full-resolution images with spherical harmonics of degree 3, and reaches real-time rendering at 1080p.

Gaussians and radiance fields compared

Both representations are fitted with the same compositing rule, so the comparison is about what each stores.
  • Rendering speed. A NeRF evaluates a network at every sample on every ray. Gaussians are projected once per frame and blended, which is fast enough for real-time display.
  • Explicit and editable. Each Gaussian is a small object with a position and a color. You can select, delete, move or recolor parts of the scene directly, which a network’s weights do not allow.
  • Memory. A NeRF network is a few megabytes whatever the scene. A Gaussian scene grows with its detail, often to millions of Gaussians and hundreds of megabytes.
  • View-dependent effects. Spherical harmonics of low degree capture gentle changes of color with direction. A NeRF’s network can represent sharper reflections, at the cost of evaluating it everywhere.
  • Empty space. A NeRF must learn that most of space is empty and spends samples there. Gaussians exist only where the scene has content.
Neural Radiance Fields reports its test PSNR on the same images and split, so you can compare the two numbers directly. Before a robot simulator can use a splat scene, the scene has to be placed in the robot’s frame with real units. Registering a Scan to the Robot covers that step.

References

  • Kerbl, B., Kopanas, G., Leimkühler, T., Drettakis, G. (2023). 3D Gaussian splatting for real-time radiance Field rendering. arXiv [cs.GR]. Link
  • Ye, V., Li, R., Kerr, J., Turkulainen, M., Yi, B., et al. (2024). gsplat: An Open-Source Library for Gaussian Splatting. DOI

Found an error on this page? Report an issue.