Neural SDF: NeRF Explained Simply
Instead of storing a 3D scene as triangles or voxels, a neural network can learn to be the scene: a tiny multilayer perceptron that, given a 3D point, outputs either a signed distance (neural SDF) or a color and density (NeRF). This "implicit neural representation" idea is behind photorealistic scene capture, generative 3D, and modern signed-distance shape modeling. This article demystifies both without assuming a deep learning background.
1. The core idea: networks as functions
A traditional 3D model is explicit: a list of vertices, triangles, or voxels that directly store geometry. An implicit neural representation instead trains a small neural network fθ(x, y, z) → (value) that answers a query about any point in space on demand. The geometry is encoded in the network's weights θ, not in an explicit data structure. Two flavors dominate: neural SDFs encode shape (how far is this point from the nearest surface), and NeRF (Neural Radiance Fields) encodes appearance (what color and density does this point in space have, viewed from this direction).
Explicit mesh
Fixed vertex count, easy rasterization, hard to represent smooth thin structures or view-dependent effects.
Neural SDF
Continuous, infinite resolution, smooth gradients for free (useful for sphere tracing and physics).
NeRF
Captures view-dependent color (specular highlights, reflections) that meshes struggle with.
2. Neural SDF: a network that measures distance to a surface
A classic SDF for a sphere is a one-line formula: length(p) -
radius. A neural SDF replaces that formula with a small
MLP trained so that its output approximates the true signed distance
for an arbitrary, complex shape — a scanned statue, a CAD part, or a
shape interpolated between two others in latent space.
f_θ(x) ≈ SDF(x), trained so that:
f_θ(x) = 0 on the surface
|∇f_θ(x)| ≈ 1 (Eikonal constraint — keeps it a true distance field)
sign(f_θ(x)) tells inside (−) vs outside (+)
The Eikonal loss term |∇f_θ(x)| − 1|² is what separates a well-behaved neural SDF from an arbitrary occupancy network — it forces the gradient magnitude to stay near 1 everywhere, so ray marching / sphere tracing through the field still converges correctly, and surface normals fall out for free as ∇f_θ(x).
// A tiny neural SDF as pseudocode — a 4-layer MLP with sine activations (SIREN)
function neuralSDF(p, weights) {
let h = sin(matmul(weights.w0, p) + weights.b0);
h = sin(matmul(weights.w1, h) + weights.b1);
h = sin(matmul(weights.w2, h) + weights.b2);
return matmul(weights.w3, h) + weights.b3; // scalar distance
}
Because it is differentiable everywhere, this network can be sphere-traced exactly like a hand-written SDF shader — replace the analytic distance function in a WebGL ray marcher with a forward pass through a tiny MLP baked into a texture of weights, and the surface renders identically.
3. NeRF: radiance fields and the volume rendering equation
NeRF (Mildenhall et al., 2020) represents an entire scene as a function Fθ(x, d) → (color c, density σ): given a 3D point x and a viewing direction d, it predicts the emitted color and the volume density at that point. Rendering a pixel means marching a ray through the field and integrating color weighted by accumulated density — exactly the classical volume rendering equation from medical imaging and cloud rendering.
C(r) = ∫ T(t)·σ(r(t))·c(r(t), d) dt
T(t) = exp(−∫₀ᵗ σ(r(s)) ds) — accumulated transmittance
Discretized (used in practice): C ≈ Σᵢ Tᵢ·(1−exp(−σᵢδᵢ))·cᵢ
Training minimizes the photometric error between rendered pixels and a set of real photographs of the scene from known camera poses — no 3D ground truth is needed, only 2D images and their camera parameters (from structure-from-motion, e.g. COLMAP).
4. Positional encoding: why raw coordinates fail
Feeding raw (x, y, z) coordinates directly into a standard MLP produces blurry, low-frequency results — networks with ReLU activations are biased toward learning smooth, low-frequency functions ("spectral bias"). NeRF's fix is to lift each coordinate into a high-dimensional Fourier feature space before the MLP sees it:
γ(p) = (sin(2⁰πp), cos(2⁰πp), sin(2¹πp), cos(2¹πp), …, sin(2^(L−1)πp), cos(2^(L−1)πp))
Typical L = 10 for position, L = 4 for view direction
This single trick — mapping coordinates through sinusoids of increasing frequency before the network — is why NeRF can reproduce sharp edges and fine texture instead of a smoothed-out blob. The same idea (Fourier features / SIREN's sine activations) reappears in neural SDFs for exactly the same reason.
5. Training loop: rays, samples, photometric loss
for (const image of trainingImages) {
for (const ray of sampleRaysFromCameraPose(image.pose)) {
const samples = stratifiedSample(ray, 64); // coarse pass
const { colors, densities } = mlp(samples.map(positionalEncode));
const predicted = volumeRender(colors, densities, samples.t);
const loss = mse(predicted, image.pixelAt(ray));
backprop(loss); // gradient descent on MLP weights
}
}
The original NeRF used a coarse-then-fine two-network hierarchy (coarse network guides where to place more samples for the fine network), taking hours to a day per scene on a single GPU — a major reason later work focused entirely on speeding up this loop.
6. Making it fast: hash grids and instant-NGP
Instant Neural Graphics Primitives (Müller et al., 2022) replaced pure positional encoding with a multi-resolution hash grid of small learned feature vectors, looked up and interpolated per point, then fed into a much smaller MLP. This moved most of the representational capacity into fast GPU memory lookups instead of large matrix multiplies, cutting training time from hours to seconds for a scene of comparable quality.
| Method | Training time | Key idea |
|---|---|---|
| Original NeRF (2020) | ~1–2 days | Positional encoding + large MLP |
| Instant-NGP (2022) | ~5–60 sec | Multi-resolution hash grid + tiny MLP |
| 3D Gaussian Splatting (2023) | ~minutes | Explicit Gaussians, not implicit MLP, rasterized directly |
7. Practical uses in interactive simulations
For real-time browser simulations, the practical takeaway is not "train a NeRF in WebGL" (still too heavy for most devices) but the underlying pattern: a small neural network baked as a texture of weights can replace a hand-written SDF for organic, scanned, or procedurally-blended shapes, evaluated per-pixel in a fragment shader via a handful of matrix-vector multiplies. Sphere tracing against a neural SDF works exactly like tracing an analytic one — the smoothness guarantees from the Eikonal constraint keep the marching stable.