AILearn AI
LearnGlossarySources
ID/EN
Learn AI — open material for learning AIEvery lesson cites its original sources.
◈Multimodal, Video & 3D
  1. Vision Transformers and CLIP
  2. Multimodal LLMs (Vision-Language Models)
  3. Video Generation
  4. 3D: NeRF, Gaussian Splatting and Text-to-3D
Modules
  1. ◎ AI Foundations
  2. ∿ Classical Machine Learning
  3. ⌬ Neural Networks
  4. ↘ Training Results & Evaluation
  5. ▦ Deep Learning Architectures
  6. ✎ Large Language Models
  7. ◐ Image Generation
  8. ♪ Audio & Speech AI
  9. ◈ Multimodal, Video & 3D
  10. ↻ Reinforcement Learning
  11. ⚙ ML Development & MLOps
  12. ★ Advanced & Frontier Topics
Learn/Multimodal, Video & 3D

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.

Advanced~30 min·5 references
Key terms
NeRF (Neural Radiance Field)3D Gaussian Splatting (3DGS)Diffusion modelText-to-imageClassifier-free guidance (CFG)MLP (Multilayer Perceptron)Positional encoding

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.

≈
Fog in a box vs. a cloud of paint blobs
NeRF imagines the scene as a box filled with coloured fog of varying density; to make a picture you shine a ray through the fog for every pixel and add up what it meets. Gaussian Splatting instead throws millions of soft, semi-transparent, coloured ellipsoid 'paint blobs' into space and, for each view, splats them onto the screen from back to front. Same goal, very different speed.

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) = Σᵢ Tᵢ · (1 − exp(−σᵢ δᵢ)) · cᵢ, Tᵢ = exp( −Σ_{j<i} σⱼ δⱼ )
NeRF's volume-rendering equation for one camera ray.
In words: Walk along the ray from the camera; each sample adds its colour times its own opacity times the fraction of light that got past all earlier samples. Dense samples close to the camera block everything behind them.
Symbols(hover a symbol in the formula)
Ĉ(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
3 samples, δ = 0.5 each; σ = (0, 2, 10); colours blue, red, green Opacities 1 − e^(−σδ): (0, 1 − e⁻¹, 1 − e⁻⁵) = (0, 0.6321, 0.9933) Transmittance: T₁ = 1, T₂ = e⁰ = 1, T₃ = e^(−(0 + 1)) = 0.3679 Weights Tᵢ · αᵢ: 0, 0.6321, 0.3679 · 0.9933 = 0.3654 Ĉ = 0.6321 · red + 0.3654 · green = (0.632, 0.365, 0) in RGB The weights sum to 0.9975: the ray is almost completely blocked by the time it passes sample 3.
γ(p) = ( sin(2⁰πp), cos(2⁰πp), sin(2¹πp), cos(2¹πp), …, sin(2^{L−1}πp), cos(2^{L−1}πp) )
Positional encoding of each coordinate. Without it MLPs are biased towards smooth functions and render blurry scenes. NeRF uses L = 10 for position and L = 4 for direction.
In words: Replace a single coordinate p by sines and cosines of p at frequencies that double each time. The low frequencies tell the MLP roughly where p is; the high ones let it represent sharp changes over tiny distances.
Symbols(hover a symbol in the formula)
γ(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
p = 0.25, L = 3 (frequencies 2⁰, 2¹, 2²): sin(π · 0.25) = 0.7071, cos(π · 0.25) = 0.7071 sin(2π · 0.25) = 1, cos(2π · 0.25) = 0 sin(4π · 0.25) = 0, cos(4π · 0.25) = −1 γ(0.25) = (0.7071, 0.7071, 1, 0, 0, −1): 2 · L = 6 numbers NeRF: 3 coordinates × 2 × 10 = 60 numbers for position, 3 × 2 × 4 = 24 for direction.
Loading interactive…
Walk through one training ray from the photo to the loss, then tap the MLP trunk and the colour head. Notice that the density σ is computed from position alone while the colour also sees the viewing direction, and that the only supervision is the photo's own pixel colour.
python
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
The volume-rendering equation for a single ray in NumPy.
knobPositional-encoding frequencies L
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.
knobSamples per ray
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).

Σ = R · S · Sᵀ · Rᵀ C(pixel) = Σᵢ cᵢ · αᵢ · Π_{j<i} (1 − αⱼ)
A Gaussian's shape from rotation and scale, and how sorted Gaussians are blended into a pixel.
In words: Left: a covariance built as rotation × scale × scale × rotation is always a valid ellipsoid, so the optimizer can change scale and rotation freely without ever producing an invalid shape. Right: a pixel's colour is the front-to-back blend of the depth-sorted Gaussians covering it, each weighted by its opacity and by how much light the Gaussians in front let through.
Symbols(hover a symbol in the formula)
Σ
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
Shape: R = identity, S = diag(2, 1, 0.5) → Σ = diag(4, 1, 0.25): an ellipsoid twice as wide along x and half as thick along z Blending 3 depth-sorted Gaussians at one pixel: α = (0.5, 0.4, 0.9), colours red, green, blue Weights: 0.5; 0.4 · (1 − 0.5) = 0.2; 0.9 · 0.5 · 0.6 = 0.27 C = (0.5, 0.2, 0.27) in RGB; total opacity 0.5 + 0.2 + 0.27 = 0.97 The same maths as NeRF's volume rendering, with Gaussians instead of ray samples.
Loading interactive…
Walk through initialization, rendering and the optimization loop, then tap the 3D Gaussians box to see what each one stores. Notice there is no network: the gradient arrow updates the Gaussians themselves, and density control changes how many there are.
AspectNeRF3D Gaussian Splatting
RepresentationImplicit (MLP weights)Explicit (list of Gaussians)
RenderingRay marching, many MLP queries per pixelTile-based rasterization
SpeedSlow (original); fast variants existReal-time
MemorySmall (a few MB)Large (hundreds of MB for big scenes)
EditingHard (knowledge is spread over weights)Easier (move/delete Gaussians)
knobDensification threshold / number of 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.
knobSpherical-harmonics degree
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.
bash
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.
Reconstructing your own scene from photos with nerfstudio (needs COLMAP and a CUDA GPU).

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 = E_{t, ε} [ w(t) · ( ε̂_φ(xₜ ; prompt, t) − ε ) · ∂x/∂θ ], x = render(θ, random camera)
The Score Distillation Sampling (SDS) gradient used by DreamFusion.
In words: Render the 3-D scene from a random camera, add noise, ask the frozen diffusion model which noise it sees given the prompt, and push the scene's parameters in the direction that shrinks the gap between predicted and actual noise. The diffusion model's own Jacobian is skipped, so the gradient flows only through the renderer.
Symbols(hover a symbol in the formula)
∇_θ 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
One pixel: rendered x = 0.6; noise level with ᾱₜ = 0.5; added noise ε = 0.3 xₜ = √0.5 · 0.6 + √0.5 · 0.3 = 0.4243 + 0.2121 = 0.6364 The diffusion model, seeing the prompt, predicts ε̂ = 0.5: it 'sees' more noise because the pixel doesn't fit the prompt Residual ε̂ − ε = 0.5 − 0.3 = 0.2; with w(t) = 1 and ∂x/∂θ = 1 (θ is this pixel's colour) the gradient is 0.2 Gradient step, learning rate 0.1: θ = 0.6 − 0.1 · 0.2 = 0.58. Thousands of such steps from random views shape the 3-D object.
knobSDS guidance scale
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).
!
Common pitfalls
Bad camera poses ruin everything: blurry or textureless photos, moving objects or changing lighting make COLMAP fail or produce wrong poses, and both NeRF and 3DGS then produce mush. Shoot with lots of overlap, fixed exposure, and walk around the object. Floaters: semi-transparent junk in front of the camera, typical with few views. Evaluating only on training views: always hold out test views (PSNR/SSIM/LPIPS). Text-to-3D quality claims: compare from many angles, not one hero render.
▸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

1.
What does a NeRF's MLP output for a 3D point and viewing direction?
2.
Why does NeRF apply positional encoding γ(p) to its inputs?
3.
What is the main reason 3D Gaussian Splatting renders in real time while the original NeRF does not?
4.
In DreamFusion's Score Distillation Sampling, what is being optimized?
5.
Your text-to-3D object has a face on both its front and back. What is this called, and what helps?
Score: 0/5

References

  1. [1]
    NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis
    PaperMildenhall et al.2020arxiv.org
  2. [2]
    3D Gaussian Splatting for Real-Time Radiance Field Rendering
    PaperKerbl et al.2023arxiv.org
  3. [3]
    DreamFusion: Text-to-3D using 2D Diffusion
    PaperPoole et al.2022arxiv.org
  4. [4]
    Instant Neural Graphics Primitives with a Multiresolution Hash Encoding
    PaperMüller et al.2022arxiv.org
  5. [5]
    Nerfstudio documentation
    DocsNerfstudio teamdocs.nerf.studio
← Previous
Video Generation
Next → · Reinforcement Learning
Reinforcement Learning Basics: Agents, Rewards and Q-learning