A 3D model of a scene lets you look at it from any side. This lesson shows two ways to build one from ordinary photos, and one way to build one from a text prompt by borrowing a picture-making model. Consumer apps such as Luma AI, Polycam and Scaniverse offer photo capture (as of Oct 2026, check each app).
After this lesson, you will be able to:
Explain how a Neural Radiance Field (NeRF) represents a 3D scene as a tiny neural network, and why volumetric ray marching is what turns that network into a rendered image
Describe 3D Gaussian Splatting as the explicit, fast cousin of NeRF — a scene stored as a cloud of fuzzy ellipsoids that you alpha-blend in screen space
Use Score Distillation Sampling (SDS) to turn any text-to-image diffusion model into a text-to-3D generator — even though no 3D ground truth exists
Pick the right 3D representation (NeRF, Gaussian Splatting, mesh) for a given task, weighing render quality, training time, editability, and downstream tooling
3D generation rides on the same diffusion machinery as images. The key step is to store the scene in a form, called a representation, that a picture model can guide.
Words you need8 terms
Where a camera was and which way it pointed when it took a photo.
A straight line from the camera through one pixel into the scene. One ray is shot per pixel.
How solid a point in space is. High density blocks light; low density lets it pass.
A small neural network that stores a scene. Ask it for a point and a direction, and it returns a colour and a density.
The share of light that reaches a point along a ray without being blocked on the way.
A fuzzy 3D blob with a position, size, colour and opacity. A scene is a cloud of millions of them.
Mixing layers front to back, where each layer covers part of what lies behind it.
Using a frozen picture model as a judge: it says how to nudge a render so that it looks more like the prompt.
Generative 3D divides cleanly along two axes: what representation (implicit NeRF / explicit Gaussian / mesh / point cloud) and how to learn it (per-scene optimization from photos / 2D-diffusion-as-prior via SDS / native 3D diffusion trained on 3D datasets).
A NeRF is a function F_θ : (x, y, z, θ_view, φ_view) → (r, g, b, σ) — given a point in space and a viewing direction, return color and density. This function is a small MLP (typically 8 layers, 256 hidden units).
Volumetric rendering integral. To render a pixel, shoot a ray from the camera through that pixel. Sample N points along the ray. Evaluate the MLP at each point. The pixel's color is a weighted integral of the per-sample colors, where the weights come from accumulated transmittance and per-sample density.
The same path as a picture:
A tiny example. A ray passes two pieces. The first is 50% solid and red. The second is 80% solid and blue. The red piece lets half the light through, so its weight is 0.5. The blue piece gets the other half and takes 80% of it, so its weight is 0.4. The pixel is 0.5 red plus 0.4 blue, and 0.1 passes through to the background. The formula below does this sum for many pieces.
A computer cannot integrate along a ray exactly, so the code adds up N samples instead. The two derivations below show where that sum comes from, where αi=1−e−σiδi comes from, and why the weights form a proper blend.
The weights T_i alpha_i behave like blend fractions, and the next derivation shows how much of the ray they use up.
Move the number of pieces, each piece's density and colour, and the presets Solid wall, Fog and Two surfaces, then switch on the exact-integral toggle. Watch that a pixel colour is a weighted sum along the ray, that dense early pieces drive the weights behind them to zero, and that the weights plus the leftover transmittance add up to exactly 1.
Loading visualization...
Do: Pick the Solid wall, Fog and Two surfaces presets in turn, then turn on the exact-integral toggle.
Notice: A dense early piece pushes the weights behind it to zero. The weights plus the leftover light always add up to 1.
Why: Each piece only gets the light that the pieces in front let through.
Real formula on a made-up ray, no trained network.
Training signal. Photometric loss: render the same pixels you have photographs of, take MSE between rendered pixel and ground-truth pixel, backpropagate through the rendering integral and into the MLP weights. With 30-100 photos taken from different angles, the MLP converges to a coherent 3D scene.
Why it took off: photographs are everywhere; 3D scans are rare. NeRF only needs photos + camera poses (which COLMAP can recover automatically). It produces view-consistent renders with proper occlusion and lighting without extra work.
Why pure NeRF is no longer the usual production choice: the original needed a day or two to train (hash-grid variants such as Instant-NGP cut that to minutes), rendering needs many network queries per pixel and is slow, editing is hard (the scene is locked inside MLP weights — try moving one chair in the scene).
Take ~1M tiny 3D Gaussians, each parameterized by:
Position μ ∈ ℝ³
Anisotropic covariance Σ (encoded via rotation quaternion + scale vector for stability)
Color c ∈ ℝ³ (sometimes spherical harmonics for view-dependent color)
Opacity α ∈ [0, 1]
To render: project each 3D Gaussian onto the 2D screen (becomes a 2D Gaussian via the projection of Σ), sort by depth, alpha-blend front-to-back.
C(p)=i=1∑NciαiGi(p)j=1∏i−1(1−αjGj(p))
The blending formula is the same compositing idea as NeRF, with a Gaussian footprint in place of a ray segment. Open the derivation to see why a one-line loop gives the product form.
The footprint G_i above is a 2D Gaussian whose covariance comes from the 3D one. The formula is Σ′=JWΣWTJT, where W is the camera rotation and J is the slope of the perspective projection.
Adaptive density control. The clever training trick: every few hundred steps, look at the gradient on each Gaussian. If a Gaussian has high gradient (the loss says it should be doing more work), clone or split it. If a Gaussian's opacity drops below a threshold, prune it. Start with a sparse point cloud from COLMAP and end with ~1-5M Gaussians that fully describe the scene.
Why it caught on. Trains in minutes to tens of minutes on a desktop GPU. Renders in real time (the paper reports 100+ FPS at 1080p on a high-end GPU). Easy to ship — the scene is just a list of Gaussians, viewable in a Three.js scene, AR Quick Look, or Unity plugin. Edit-friendly — you can literally grab a subset of Gaussians and move them.
The big problem with native 3D generation: 3D training data is scarce. Objaverse has about 800K assets (its successor Objaverse-XL has over 10M); the internet has billions of images. Could we leverage 2D image generation models (which are amazing) to generate 3D?
Score Distillation Sampling (SDS) is the answer. Take a 3D representation (NeRF or Gaussian Splatting) parameterized by θ. Render a random view to get image x. Pretend x is a sample from a diffusion model and ask: "what is the score (gradient of log p) at this image, conditioned on the text prompt y?" The pretrained diffusion model gives you that gradient — the same score function from the stochastic-calculus / SDEStochastic CalculusStochastic calculus extends derivatives to random processes — Brownian motion, Itô integrals, and stochastic differential equations. The math diffusion models, flow matching, and score-based generative models all live in.Learn more view of diffusion. Backpropagate the gradient through the renderer into θ.
The SDS formula looks like the gradient of the usual diffusion loss, but one factor is missing on purpose. The derivation shows which one, and why the authors drop it.
Variants worth knowing.Magic3D (NVIDIA 2022) — coarse SDS into mesh, then high-res refinement. Fantasia3D (Chen 2023) — disentangles geometry from appearance. ProlificDreamer (2023) — variational score distillation (VSD), which gives sharper, less over-saturated results than vanilla SDS.
Native 3D diffusion is the alternative since 2023. Shap-E (OpenAI 2023) trains a diffusion model directly on 3D representations. LRM (Large Reconstruction Model), Instant3D, One-2-3-45, Zero123, SyncDreamer — feed-forward image-to-3D models that don't require per-asset SDS optimization. Genie 3 (DeepMind, August 2025) is a world model: it generates interactive, explorable environments as video frames, not a 3D asset you can export.
What Do You Think?
You're building a tool that lets a furniture retailer scan a chair from 30 phone photos and serve a 3D viewer in the browser. Which representation do you use?
Gaussian Splatting wins this one — it trains in minutes, runs in real time, and the Three.js / Babylon.js communities both have mature in-browser viewers. NeRF would render more slowly. DreamFusion ignores your actual photos. Classical mesh-based MVS can struggle with reflective or thin surfaces (chair frames!). The retailer can ship the splat directly to customers.
This lesson has two cells. The first trains a small network with torch, so it is a read-only copy for Google Colab. The second runs here in your browser with numpy: a 2-D density grid that learns a disc from ray labels seen by 8 cameras.
PythonRead-only reference
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Copy to Colab (needs torch; it cannot run in the browser)
# Minimal NeRF in PyTorch (illustrative — run on a tiny synthetic scene)
import torch
import torch.nn as nn
class TinyNeRF(nn.Module):
"""Maps (xyz, view_dir) -> (rgb, sigma). Real NeRFs use positional encoding."""
def __init__(self, hidden=128):
super().__init__()
self.mlp = nn.Sequential(
nn.Linear(3 + 3, hidden), nn.ReLU(),
nn.Linear(hidden, hidden), nn.ReLU(),
nn.Linear(hidden, hidden), nn.ReLU(),
nn.Linear(hidden, 4), # rgb + sigma
)
def forward(self, points, view_dir):
x = torch.cat([points, view_dir], dim=-1)
out = self.mlp(x)
rgb = torch.sigmoid(out[..., :3])
sigma = torch.relu(out[..., 3])
return rgb, sigma
def render_ray(model, ray_o, ray_d, n_samples=64, near=0.1, far=4.0):
"""Volume render one ray."""
t = torch.linspace(near, far, n_samples, device=ray_o.device)
pts = ray_o[None, :] + t[:, None] * ray_d[None, :] # (N, 3)
view = ray_d[None, :].expand_as(pts)
rgb, sigma = model(pts, view)
delta = t[1:] - t[:-1]
delta = torch.cat([delta, torch.tensor([1e10], device=t.device)])
alpha = 1.0 - torch.exp(-sigma * delta) # (N,)
T = torch.cumprod(1.0 - alpha + 1e-10, dim=0)
T = torch.cat([torch.tensor([1.0], device=T.device), T[:-1]])
weights = T * alpha
return (weights[:, None] * rgb).sum(dim=0)
# Toy training: 32 random rays from a fake "scene" (one bright sphere)
def fake_pixel_color(ray_o, ray_d):
# Red only if the ray hits the sphere (radius 0.5, at the origin) in FRONT of the camera
a = (ray_d * ray_d).sum()
b = 2 * (ray_o * ray_d).sum()
c = (ray_o * ray_o).sum() - 0.25
disc = b * b - 4 * a * c
t_far = (-b + torch.sqrt(torch.clamp(disc, min=0.0))) / (2 * a)
hit = (disc > 0) and (t_far > 0)
return torch.tensor([1.0, 0.0, 0.0]) if hit else torch.tensor([0.0, 0.0, 0.0])
model = TinyNeRF()
opt = torch.optim.Adam(model.parameters(), lr=1e-3)
torch.manual_seed(0)
for step in range(200):
loss = 0
for _ in range(32):
ray_o = torch.tensor([0.0, 0.0, 2.0])
ray_d = torch.randn(3); ray_d = ray_d / ray_d.norm()
target = fake_pixel_color(ray_o, ray_d)
pred = render_ray(model, ray_o, ray_d, n_samples=32)
loss = loss + ((pred - target) ** 2).sum()
opt.zero_grad(); loss.backward(); opt.step()
if step % 50 == 0:
print(f"step {step:3d} loss {loss.item():.4f}")
print()
print("CHALLENGE:")
print(" 1. Add positional encoding (sinusoidal embedding of xyz) -- fixes blurriness.")
print(" 2. Replace TinyNeRF with a hash-grid (Instant-NGP) -- 1000x faster training.")
print(" 3. Try the same setup with Gaussian Splatting via the gsplat library -- compare wall-clock.")
Now the browser version. It first shows why the old label was wrong: testing the infinite line through the camera marks about half of the red rays as hits even though they point away from the disc. Then it trains a density grid with the volume-rendering rule from this lesson, brightness = 1 minus the leftover transmittance.
pythonplayground.py · Pyodide
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
Tests: Run the script. It should print that about half of the infinite-line 'red' rays point away, then the loss falling, then accuracy on new rays above the 0.92 you get by always answering black, a red recall above 0.7, and a density inside the disc far above the empty ring around it, ending with 'All checks passed'. This is a drawn stand-in for a NeRF: a grid of densities, not a neural network.
Implicit (NeRF) vs explicit (Gaussian Splatting) is the central tradeoff. NeRF stores the scene in MLP weights and queries it per-ray; Gaussian Splatting stores millions of explicit blobs and rasterizes them. Implicit can win on storage and on translucent scenes; explicit wins on training and rendering speed.
Volumetric rendering is the bridge from differentiable graphics to deep learning. NeRF's contribution wasn't a new neural architecture, it was making the volume-rendering integral differentiable so gradient descent could fit it from photographs.
Gaussian Splatting's adaptive density control is what keeps training stable. Clone-and-split where loss is high, prune where opacity is low. This turns gradient descent on millions of parameters into a stable training loop.
Score Distillation Sampling lifts 2D diffusion to 3D. DreamFusion proved you don't need a 3D-trained diffusion model to do text-to-3D. Just borrow gradients from any pretrained 2D model and chain-rule them through your renderer.
Recent work shifted from per-scene optimization to feed-forward 3D models: LRM, Instant3D, Shap-E. Slow SDS can suit bespoke assets; fast feed-forward suits quick drafts. Genie 3 is a different thing, a world model that generates explorable video.
An architecture diagram: boxes are components, arrows show the direction data flows, and moving dots mark the live flow.
Architecture diagram "From photos to a rendered picture" with 7 components (Photos, Camera ray per pixel, Points on the ray, Scene network, Blend front to back, Rendered pixel, Compare with photo) joined by 6 arrows showing how data flows between them.