3D vision: voxels, point clouds and NeRF
A photo is one 2D grid. With 3D you first have to choose how to store it: as cells, as points, as triangles, or as one function. Start by stepping through how NeRF makes the color of one pixel, one sample at a time.
Short answer. 3D can be stored as voxels (3D cells), a point cloud (a list of points), a mesh (triangles) or a function (an implicit representation), and each form needs a different kind of network. Voxels let you use convolution in 3D as it is, but they grow with the cube of the resolution. In a point cloud the order of the points means nothing, so the points are combined with an operation that ignores order (PointNet). NeRF stores a scene as one function and makes each pixel by combining the colors of points along a ray with volume rendering.
The square on the left is the pixel, and the gray arrow is the ray going from the pixel into the scene. The circles are samples on the ray (darker means more opaque), and the orange arrow is what this step's sample adds to the pixel. Under each sample, the left bar (gray) is the light Tᵢ that survived everything in front of it, and the right bar (in the sample's color) is its share Tᵢαᵢ. The same numbers are in the two rows under the bars. The opacities and colors are made up. They are not output from a trained NeRF, so this is a schematic.
Try this. 1) In "fog, then a wall", press "Next" to the end: the two fog samples add 0.2 and 0.24, and the wall (α 0.9) adds 0.504. Sample 7 behind the wall has α 0.7, but only 0.056 of the light reaches it, so it adds just 0.039. The light left at the end is 0.017. 2) In "wall in front", sample 3 (α 0.95) takes 0.95, and the two behind it add only 0.03 and 0.018. 3) In "thin fog only", every α is 0.15, yet the shares shrink: 0.15, 0.128, ... , 0.048, and 0.272 of the light is left at the end. The same fog shows less the further back it is.
Definitions
The text below explains with the small set of points and the single ray in the lab. Here are the definitions of the ideas this page uses.
- voxel
- One cell of a grid (a voxel grid) that splits 3D space into cubes of the same size. Each cell holds a value such as "full" or "empty". With N cells on a side, there are N³ cells.
- point cloud
- A collection of the coordinates of n points taken from an object's surface. The points are not connected, and the order in which they are written has no meaning.
- permutation invariance
- The property that a function gives the same value whatever permutation π reorders the input points. PointNet keeps this property by applying the same layer h to every point and combining them with max pooling, which picks the largest value in each entry.
- NeRF (neural radiance field)
- One scene stored in one fully connected neural network F. Given a position x in space and a viewing direction d, it outputs the volume density σ at that place and the color c seen from that direction.
- volume rendering
- The computation that combines the density and color of N samples on a ray into one pixel color C. The opacity αᵢ of sample i comes from its density σᵢ and the distance δᵢ to the next sample, and it is multiplied by the transmittance Tᵢ (with T₁ = 1), the light that survives all earlier samples to reach sample i, before adding up.
- 3D Gaussian splatting
- A method that stores a scene as many 3D Gaussians instead of a neural network and draws them by stamping them onto the screen. Training alternates between controlling the density of Gaussians (adding and removing them) and optimizing each Gaussian's anisotropic covariance (a shape that spreads by a different amount in each direction).
1. Ways to store 3D
A photo is always a width × height grid. 3D has no single shape like that, so you first pick a form.
- Depth map: a 2D grid like a photo, but each cell holds the distance from the camera instead of a color.
- Voxel: a 3D pixel. Space is cut into equal cubes, and each cube holds a value such as "full" or "empty". The whole thing is a voxel grid.
- Point cloud: a list of points (x, y, z) taken from the surface of an object. The points are not connected.
- Mesh: a list of corners (vertices) and triangles (faces) that join three corners. The surface is connected.
- Implicit representation: instead of cells or points, you store a function that answers "what is at this spot?". In NeRF that function is a neural network.
| Form | What it stores | Memory | Easy | Hard |
|---|---|---|---|---|
| Depth map | distances in a grid, from one viewpoint | one image (width × height) | it is a 2D grid, so 2D convolution works as is | only the surface the camera sees. Nothing behind it |
| Voxel grid | values in N × N × N cells | N³, the cube of the resolution (section 2) | neighbors are fixed, so 3D convolution works as is | hard to raise the resolution. Empty cells take space too |
| Point cloud | (x, y, z) of n points | n × 3, as many points as you took | taken in directly, no conversion. Only surface points | no fixed order or neighbors, so grid convolution does not apply directly (section 3) |
| Mesh | corners and triangle faces | as many as the corners and faces | the surface is connected, so it is easy to draw (render) | the number of corners and how they connect differ per object, which makes it awkward as network input |
| Implicit (NeRF and others) | one function (the network's weights) | as many as the weights, separate from any cell count | you can ask about any spot (continuous) | drawing one image takes a huge number of function calls (section 4) |
2. Voxels: 3D convolution as is, memory cubed
In convolution, the kernel is a small window of weights that slides across the image left to right and top to bottom. A voxel grid is also a grid, so you make the kernel a 3 × 3 × 3 cube and slide it in width, height and depth. That is 3D convolution, and the ideas of kernels and pooling carry over from 2D unchanged.
The problem is size.
cells = N × N × N = N³
memory = N³ × (values per cell) × (bytes per value)
N: cells along one side (the resolution).values per cell: how many numbers each cell holds. After a convolution layer this is the number of channels.bytes per value: 4 bytes for float32.
| N | cells N³ | one float32 per cell |
|---|---|---|
| 32 | 32,768 | 128 KiB |
| 64 | 262,144 | 1 MiB |
| 128 | 2,097,152 | 8 MiB |
| 256 | 16,777,216 | 64 MiB |
Doubling each side gives 2³ = 8 times the cells. The table is for one input with one value per cell, and when layers add channels it multiplies again. On top of that, every empty cell away from the surface takes up space. The PointNet paper also says that turning point clouds into voxel grids makes the data needlessly large.
3. Point clouds and PointNet: same answer in any order
A point cloud is a list of points. The same object can list its points in any order, and the order means nothing. According to the PointNet paper (Qi et al.), point clouds have an irregular format, so most earlier work turned them into voxel grids or collections of images, which makes the data needlessly large. PointNet takes the point cloud directly and respects permutation invariance of the input points, which means reordering the points does not change the answer. It also uses one architecture for object classification, part segmentation and scene semantic parsing (segmentation).
The idea that makes it ignore order: give every point the same small network (an MLP) on its own to get features, then combine those features with max pooling, which picks the largest value in each slot. The largest value is the same whatever order you look in, so the result is the same too.
g({p₁, p₂, …, pₙ}) = max( h(p₁), h(p₂), …, h(pₙ) ) (max in each slot)
h(p) = ReLU(W p + b) (the h in this page's experiment)
pᵢ: the coordinates of point i. In the experiment, two numbers (x, y).n: the number of points.h: the layer used the same way for every point (a shared MLP). It takes one point and gives one feature vector.W,b: that layer's weight matrix and bias.W pis a linear transformation. In the experiment W = [[1, 0], [0, 1], [−1, 1]] and b = 0, so the features are (x, y, max(0, y − x)).ReLU: the activation function that turns negatives into 0.max: the largest value in each slot across the feature vectors. The result is a vector of the same length.g: one vector for the whole set of points. A classifier goes on top of it.
| Order | Point (x, y) | Features h = (x, y, max(0, y − x)) |
|---|
Try this. 1) In the first order, max pooling gives (5, 5, 3). The three largest values come from three different points: (5, 3), (4, 5) and (1, 4). 2) Press "Shuffle" once: #1 becomes (3, 2), and the start of the concatenated list changes from 1, 4, 3 to 3, 2, 0. Max pooling stays (5, 5, 3). 3) Shuffle as often as you like: the points and blue tags on the plane never move, only the orange numbers change. It is the same set of points, so it should give the same answer, and max pooling does. Six points, one layer and three features are a toy cut down so you can follow it by hand. In a real model h is several trained layers.
4. NeRF: a whole scene in one function
The NeRF (neural radiance field) paper (Mildenhall et al.) stores one scene in one fully connected network. The network represents the scene as a continuous function. Give it a 3D position and a viewing direction, and it returns the volume density at that spot and a color that depends on the viewing direction.
F(x, d) = (σ, c)
F: the network that holds the scene (fully connected). One is trained per scene.x: a position in space (x, y, z).d: the direction you look at that spot from. The same spot can have a different color from a different direction.σ(sigma): volume density. How thickly something that blocks light fills that spot. 0 means empty.c: the color (r, g, b) you see at that spot from that direction.
One image is drawn like this.
- For each pixel, shoot one ray from the camera into the scene.
- Pick several points (samples) along the ray.
- Call F at each sample to get σ and c.
- Combine the samples' colors and densities into one pixel color with classic volume rendering (section 5, experiment 1).
Training. This rendering is differentiable from start to end. So you can adjust F's weights until the rendered pixels match the pixels in the photos, and all you need is a set of photos and each photo's camera pose: where it was taken from and which way it faced. After training you can draw the scene from angles that no photo had, which is called novel view synthesis.
The NeRF paper expands the position and direction into many sine and cosine values before feeding them to F (positional encoding). This page does not cover that part.
5. Volume rendering by hand
Volume rendering is really an integral along the ray. Cut the ray into samples and add them up, and you get the sum below. Build it up from the front (the pixel side), one sample at a time.
- One sample. With opacity α₁ its color shows by α₁:
C = α₁c₁. The rest of the light, 1 − α₁, passes behind it. - Two samples. Only the surviving light 1 − α₁ reaches the second sample, so its share is
(1 − α₁)α₂c₂. - Sample i. Only the product of all the (1 − α) in front reaches sample i. That value is called the transmittance Tᵢ. The share is
Tᵢαᵢcᵢ. - Add them all. The sum of the shares is the pixel color. Adding all the shares Tᵢαᵢ and the light left at the end always gives 1 (checked on all three scenes in the experiment).
αᵢ = 1 − exp(−σᵢ δᵢ)
Tᵢ = (1 − α₁)(1 − α₂) … (1 − αᵢ₋₁), T₁ = 1
C = T₁α₁c₁ + T₂α₂c₂ + … + T_N α_N c_N
i: the sample number. The one nearest the pixel is 1.N: the number of samples on one ray. 8 in the experiment.σᵢ: the volume density at sample i (what NeRF's F returns).δᵢ(delta): the distance from sample i to the next sample.αᵢ(alpha): the opacity of sample i. 0 is see-through, 1 blocks all light. It gets closer to 1 when the density is high or the stretch is long. Experiment 1 sets α directly, with no σ or δ.Tᵢ: transmittance. The light that survived samples 1 to i − 1 and reached sample i.cᵢ: the color (r, g, b) of sample i.Tᵢαᵢ: the share (weight) of sample i, the part of the pixel color that comes from it.C: the pixel color.
With three samples. Red (1, 0, 0) with α 0.4, green (0, 1, 0) with α 0.5 and blue (0, 0, 1) with α 1, in that order.
| Sample | αᵢ | Tᵢ | Share Tᵢαᵢ | Why |
|---|---|---|---|---|
| 1 red | 0.4 | 1 | 1 × 0.4 = 0.4 | it is in front, nothing hides it |
| 2 green | 0.5 | 1 × (1 − 0.4) = 0.6 | 0.6 × 0.5 = 0.3 | red blocked 0.4 of the light |
| 3 blue | 1 | 0.6 × (1 − 0.5) = 0.3 | 0.3 × 1 = 0.3 | only 0.3 is left after the two in front |
The pixel color is C = 0.4·(1, 0, 0) + 0.3·(0, 1, 0) + 0.3·(0, 0, 1) = (0.4, 0.3, 0.3). Blue has α 1, so the light left behind it is 0.3 × (1 − 1) = 0, and the shares add up to 0.4 + 0.3 + 0.3 = 1. On its own blue is fully opaque, yet hidden behind the other two it gets only 0.3 of the pixel.
6. 3D Gaussian splatting: skip the empty space, draw in real time
NeRF calls the network at every sample on every pixel's ray, and many of those samples land in empty space. The 3D Gaussian splatting paper (Kerbl et al.) represents the scene with many 3D Gaussians instead of a network. Think of a 3D Gaussian as a soft, blurry ellipsoid blob that is dense in the middle and fades toward the edges. Drawing means stamping these blobs onto the screen (splatting).
- Start. It starts from the sparse points produced during camera calibration.
- Empty space. It keeps the good properties of a continuous volume representation while avoiding needless work in empty space.
- Training. It alternates between controlling the density of the Gaussians (adding and removing them) and optimizing each Gaussian's anisotropic covariance, a shape that can spread differently in each direction.
- Speed. The paper reports real-time novel view synthesis at 30 fps or more at 1080p.
7. When to use what
| Option | Good | Bad | Use when |
|---|---|---|---|
| Depth map + 2D convolution | the same 2D grid as an image, so 2D networks work as is | only the surface seen from one viewpoint | the distance seen by one camera is enough |
| Voxels + 3D convolution | extends the ideas of 2D convolution directly | grows with the cube of the resolution. Empty cells take space | the job works at a low resolution |
| Point cloud + PointNet | takes the points directly, no conversion. One architecture for classification, part segmentation and scene parsing | the simple form on this page (each point alone, then max pooling) has no step that looks at nearby points together | you get data as points, as from a scanner, and want to classify or segment it |
| NeRF | learns from photos with known camera poses alone and draws new views | drawing calls the network for every sample of every pixel, which is a lot of work | you want to see a scene from new angles, given photos from many angles |
| 3D Gaussian splatting | skips work in empty space, real time at 1080p | needs the points from camera calibration to start | new views must be drawn in real time |
Frequently asked
How is NeRF different from 3D Gaussian splatting?
NeRF stores a scene as one neural network function. For each pixel it calls that function at points along a ray and combines the colors with volume rendering. 3D Gaussian splatting stores the scene as many 3D Gaussians and draws them by splatting them onto the screen. It avoids wasted work in empty space, and the paper reports real-time novel view synthesis at 30 fps or more at 1080p.
Why not just concatenate the points in order and feed them to a network?
The order of the points means nothing, but concatenation turns the same set of points into a different input for every order. In experiment 2 the concatenated list changes every time you shuffle. So each point goes through the same layer, and an operation that ignores order, such as max pooling, combines them.
Why can't voxels simply use a higher resolution?
Because the number of cells is the resolution cubed. Doubling each side gives 8 times the cells. 128³ is 2,097,152 cells, which is 8 MiB even with one float32 per cell. 256³ is 64 MiB. Empty cells away from the surface take up space too.
Words
| Plain words used here | Textbook term |
|---|---|
| a picture with a distance in each cell | depth map |
| 3D pixel · grid of 3D cells | voxel · voxel grid |
| list of points | point cloud |
| corners and triangle faces | mesh, vertex, face |
| storing as a function | implicit representation |
| sliding a cube-shaped kernel | 3D convolution |
| same answer in any order | permutation invariance |
| the same layer for every point | shared MLP, multilayer perceptron |
| largest value in each slot | max pooling |
| network that holds a scene | neural radiance field (NeRF) |
| combining colors along a ray | volume rendering |
| how thick · how much light is blocked | volume density · opacity (alpha) |
| surviving light | transmittance |
| where a photo was taken from and which way it faced | camera pose |
| drawing from a new angle | novel view synthesis |
| stamping 3D blobs onto the screen | 3D Gaussian splatting |
| a shape that spreads differently in each direction | anisotropic covariance |
Sources
- Qi et al., PointNet: Deep Learning on Point Sets for 3D Classification and Segmentation, 2016 (the irregular format of point clouds and the earlier conversion to voxels or image collections, an architecture that takes point clouds directly, permutation invariance of input points, classification, part segmentation and scene semantic parsing).
- Mildenhall et al., NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis, 2020 (a continuous scene in a fully connected network, position and direction in, density and color out, samples along camera rays and classic volume rendering, differentiable rendering with photos of known camera pose).
- Kerbl et al., 3D Gaussian Splatting for Real-Time Radiance Field Rendering, 2023 (3D Gaussians starting from the sparse points of camera calibration, avoiding work in empty space, density control and anisotropic covariance optimization, 30 fps or more at 1080p).