3D: NeRF, Gaussian Splatting and Text-to-3D
How neural networks represent and render 3D scenes (NeRF's volume rendering, 3D Gaussian Splatting's real-time rasterization) and how 2D diffusion models are used to create 3D objects from text (DreamFusion's score distillation sampling) and its successors.
Games, film, AR/VR, robotics and e-commerce all need 3D content, which is slow to build by hand. Two breakthroughs changed this: NeRF (2020) showed that a small neural network can store a photorealistic 3D scene reconstructed from ordinary photos, and 3D Gaussian Splatting (2023) made such scenes render in real time. Meanwhile, DreamFusion (2022) showed you can create 3D objects from a text prompt without any 3D training data, by borrowing the knowledge inside a 2D Text-to-image diffusion model.
NeRF: a scene stored in an MLP
A Neural Radiance Field (Mildenhall et al., 2020)[1] is an MLP F_Θ that takes a 3D point (x, y, z) and a viewing direction d and returns a colour c and a volume density σ. Training needs only posed photos of one scene (camera positions are usually estimated with structure-from-motion such as COLMAP). For each pixel, cast a ray, sample points along it, query the MLP, and composite the results with volume rendering; then minimize the squared error to the real pixel. Because rendering is differentiable, gradients flow back into the MLP weights.
- Ĉ(r)
- the rendered colour of ray r (one pixel)
- Σᵢ
- sum over the samples i along the ray, front to back
- Tᵢ
- transmittance: the fraction of light that reaches sample i unblocked
- 1 − exp(−σᵢ δᵢ)
- opacity αᵢ of segment i (0 = empty, 1 = solid)
- exp
- exponential function eˣ
- σᵢ
- density at sample i
- δᵢ
- distance from sample i to the next sample
- cᵢ
- RGB colour at sample i
- Σ_{j<i}
- sum over the samples in front of i
- σⱼ δⱼ
- optical thickness of an earlier segment j
▸Worked example
- γ(p)
- gamma: the encoded vector for coordinate p (2·L numbers)
- p
- one input coordinate (x, y, z or a direction component), normalized to [−1, 1]
- sin
- sine
- cos
- cosine
- π
- pi ≈ 3.1416
- 2^{L−1}
- the highest frequency multiplier
- L
- number of frequency bands (10 for position, 4 for direction)
▸Worked example
import numpy as np
def render_ray(sigmas, colors, deltas):
"""sigmas: (N,) densities, colors: (N, 3) RGB, deltas: (N,) distances between samples."""
alphas = 1.0 - np.exp(-sigmas * deltas) # opacity of each segment
trans = np.cumprod(np.concatenate([[1.0], 1.0 - alphas[:-1]])) # transmittance T_i
weights = trans * alphas # contribution of each sample
rgb = (weights[:, None] * colors).sum(axis=0)
acc = weights.sum() # accumulated opacity, ~1 if the ray hit a surface
return rgb, weights, acc
# A ray through empty space, then a dense red surface:
sig = np.array([0.0, 0.0, 50.0, 50.0])
col = np.array([[0, 0, 1], [0, 0, 1], [1, 0, 0], [1, 0, 0]], dtype=float)
print(render_ray(sig, col, np.full(4, 0.1))[0]) # ~[1, 0, 0]: the red surface wins- What it is
- Number of sine/cosine frequency bands used to encode each input coordinate.
- ↑ If you increase it
- The MLP can represent sharper, higher-frequency detail; too high and it overfits the training views, producing noisy 'floaters' and aliasing in new views.
- ↓ If you decrease it
- Smoother, blurrier reconstructions that generalize between views but miss fine texture.
- Typical values
- 10 for position, 4 for direction (original NeRF). Hash-grid encodings (Instant-NGP) replace this in fast modern NeRFs.
- What it is
- How many points along each camera ray are evaluated by the network.
- ↑ If you increase it
- More accurate rendering of thin structures and sharp surfaces; cost grows linearly (every sample is an MLP query).
- ↓ If you decrease it
- Faster, but thin objects can be skipped entirely and surfaces look banded.
- Typical values
- 64 coarse + 128 fine (hierarchical sampling) in the original NeRF.
Original NeRF took about one to two days to train per scene on a single GPU and rendered far from real time. Instant-NGP (Müller et al., 2022) replaced most of the MLP with a multiresolution hash grid of learned features, cutting training to seconds or minutes.
3D Gaussian Splatting: explicit and real-time
Kerbl et al. (2023)[2] dropped the neural network entirely. The scene is a set of (often millions of) 3D Gaussians, each with a position μ, a covariance Σ (stored as a scale vector and a rotation quaternion so it stays valid), an opacity α and a view-dependent colour encoded with spherical harmonics. Gaussians are initialized from the sparse point cloud produced by structure-from-motion. To render, they are projected to 2D, sorted by depth in screen tiles, and alpha-blended front to back by a fast differentiable rasterizer. During optimization, adaptive density control clones small Gaussians in under-reconstructed areas, splits large ones, and prunes nearly transparent ones. Result: quality comparable to the best NeRFs, minutes-to-an-hour training, and real-time rendering (≥ 30 fps at 1080p).
- Σ
- on the left: the Gaussian's 3×3 covariance matrix (the shape of its ellipsoid)
- R
- 3×3 rotation matrix, stored as a quaternion (4 numbers)
- S
- diagonal scale matrix: 3 scale values, one per axis
- Sᵀ
- S transposed (equal to S, since it is diagonal)
- Rᵀ
- R transposed (its inverse rotation)
- C(pixel)
- the final colour of the pixel
- Σᵢ
- sum over the Gaussians overlapping this pixel, in depth order
- cᵢ
- colour of Gaussian i for this viewing direction (from its spherical harmonics)
- αᵢ
- opacity of Gaussian i at this pixel: its learned opacity times its 2-D falloff
- Π_{j<i}
- product over the Gaussians in front of i
- (1 − αⱼ)
- fraction of light that passes Gaussian j
▸Worked example
| Aspect | NeRF | 3D Gaussian Splatting |
|---|---|---|
| Representation | Implicit (MLP weights) | Explicit (list of Gaussians) |
| Rendering | Ray marching, many MLP queries per pixel | Tile-based rasterization |
| Speed | Slow (original); fast variants exist | Real-time |
| Memory | Small (a few MB) | Large (hundreds of MB for big scenes) |
| Editing | Hard (knowledge is spread over weights) | Easier (move/delete Gaussians) |
- What it is
- How eagerly 3DGS adds Gaussians: Gaussians whose view-space positional gradient exceeds a threshold are cloned or split, at a fixed interval during training.
- ↑ If you increase it
- Lowering the threshold (densifying more) adds Gaussians: finer detail, but more memory, slower training and more floaters if views are sparse.
- ↓ If you decrease it
- Raising the threshold keeps fewer Gaussians: compact files and faster rendering, but blurry fine structures (foliage, hair, text).
- Typical values
- The paper's default gradient threshold is 0.0002, densifying every 100 iterations; scenes end with roughly 1–5 million Gaussians.
- What it is
- How many SH coefficients each Gaussian uses to model colour that changes with viewing angle.
- ↑ If you increase it
- Captures reflections and shiny, view-dependent effects; degree 3 needs 48 numbers per Gaussian, which dominates file size.
- ↓ If you decrease it
- Degree 0 = one constant colour per Gaussian: much smaller files, but shiny surfaces look flat and baked.
- Typical values
- 3 (default); 0–1 for compressed or web delivery.
pip install nerfstudio
# 1) Estimate camera poses from a folder of photos (or a video) with COLMAP
ns-process-data images --data ./my_photos --output-dir ./my_scene
# 2a) Train a NeRF (nerfstudio's fast default method)
ns-train nerfacto --data ./my_scene
# 2b) ...or train 3D Gaussian Splatting
ns-train splatfacto --data ./my_scene
# Both commands open a web viewer where you can fly through the scene while it trains.Text-to-3D: score distillation (DreamFusion)
There is far less 3D data than image data. DreamFusion (Poole et al., 2022)[3] sidesteps this: optimize a NeRF from scratch so that every rendered view looks like a good image of the prompt according to a frozen 2D diffusion model (Imagen). Each step renders the NeRF from a random camera, adds noise to the rendering, asks the diffusion model to predict that noise given the prompt (with view hints such as 'front view' or 'back view'), and uses the prediction error as a gradient for the NeRF. This is Score Distillation Sampling (SDS): the diffusion model acts as a critic that says 'move the pixels this way to look more like the prompt', and no gradient goes through the huge diffusion U-Net.
- ∇_θ L_SDS
- gradient of the score-distillation objective with respect to the 3-D parameters
- θ
- the 3-D parameters: NeRF weights or Gaussian parameters
- E_{t, ε}
- average over random noise levels t and noise samples ε
- w(t)
- a weighting that depends on the noise level
- ε̂_φ(xₜ ; prompt, t)
- the frozen diffusion model's (guided) noise prediction for the noised render; φ are its fixed weights
- xₜ
- the rendering with noise added at level t
- ε
- the noise that was actually added
- ∂x/∂θ
- how the rendered pixels change when θ changes (through the differentiable renderer)
- render(θ, random camera)
- the image x rendered from the current 3-D scene at a random viewpoint
▸Worked example
- What it is
- The classifier-free guidance weight used inside the SDS gradient.
- ↑ If you increase it
- Needed to get a coherent, prompt-matching object at all (DreamFusion used 100, far above the ~7 used for images), but very high values cause oversaturated, cartoonish colours and over-smoothed geometry.
- ↓ If you decrease it
- With image-like values (≈ 7–10) plain SDS produces blurry, washed-out, mode-averaged 3D; improved objectives (e.g. variational score distillation in ProlificDreamer) work with normal scales.
- Typical values
- ≈ 100 for vanilla SDS; 7.5 for VSD-style methods.
- Janus problem: the 2D model favours front views, so objects grow a face on every side. View-dependent prompts, multi-view diffusion models (e.g. MVDream) and view-conditioned models (Zero-1-to-3) reduce it.
- Slow: per-prompt optimization takes on the order of an hour or more. Magic3D (coarse-to-fine with meshes) and DreamGaussian (SDS on 3D Gaussians) speed it up.
- Feed-forward models: newer large reconstruction models predict a 3D representation from one or a few images in seconds, often combined with a multi-view image diffusion model (text → multi-view images → 3D).
▸Go deeper: why SDS works, and the 2D↔3D loop
Recall from the diffusion lesson that ε̂ − ε is (up to scale) the difference between the score of the noisy prompt-conditioned distribution and the noise you added. Pushing a rendering along that residual nudges it towards higher probability under the image model, so SDS is like running the denoising direction of a diffusion sampler, but applying the update to 3D parameters instead of pixels. DreamFusion showed that dropping the U-Net Jacobian from the full gradient makes optimization both cheaper and better behaved[3].
The field now moves fast in both directions: 2D generators are fine-tuned to output consistent multi-view images, which are then reconstructed into NeRFs or Gaussians; and 3D representations are used to make video models more geometrically consistent. Tooling such as nerfstudio[5] and the Instant-NGP paper[4] are good entry points for hands-on work.
Quiz
References
- [1]NeRF: Representing Scenes as Neural Radiance Fields for View SynthesisPaperMildenhall et al.2020arxiv.org
- [2]3D Gaussian Splatting for Real-Time Radiance Field RenderingPaperKerbl et al.2023arxiv.org
- [3]DreamFusion: Text-to-3D using 2D DiffusionPaperPoole et al.2022arxiv.org
- [4]Instant Neural Graphics Primitives with a Multiresolution Hash EncodingPaperMüller et al.2022arxiv.org
- [5]Nerfstudio documentationDocsNerfstudio teamdocs.nerf.studio