TL;DR
Volume rendering draws things you can partly see through, such as fog, smoke, clouds and gas or tissue. For each pixel it follows one ray from the camera into the scene. It adds up the light that each point on the ray gives off, and it weights each point by how much of that light survives the points in front of it. The same rule, applied to a stack of layers, is the familiar Alpha Compositing of semi-transparent pictures.
Builds on: Definite Integral, Exponential Function, Vector · Leads to: NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis
Where it's used
Clouds, smoke and fire in films and games. A cloud in an animated film is not a surface. Light enters it, is absorbed as it passes through, and fades the deeper it goes. A renderer computes the colour of each pixel that sees the cloud by following the camera ray through the cloud and combining the samples along it.
3D views of medical scans. A CT or MRI scan gives a grid of values, one per small cube of tissue, which is a Voxel Grid. Viewers turn that grid into a 3D picture by treating each cube as a semi-transparent sample and running the same ray sum.
Neural radiance fields (2020). Mildenhall and colleagues (NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis) trained a Feedforward Neural Network that returns a density and a colour at any 3D point. To draw a new view of the scene, they ran volume rendering along each camera ray and compared the result with real photographs. Because every step is differentiable, the network could be trained by Backpropagation from the photographs alone.
How it works
Take one pixel. In a Pinhole Camera Model its camera ray is the straight line from the eye through that pixel, and it passes through a small misty region, and we cut the ray into two pieces of length 1. Piece 1 is nearer the camera and has density and colour . Piece 2 is behind it, with density and colour . Behind both pieces is black background with value .
- Shoot the ray. The camera sees the light that travels back along the ray. That light can come from any point on the ray, and light from the far piece has to pass through the near piece to reach the camera.
- Read the density and colour in each piece. Piece 1: , . Piece 2: , . Density says how strongly the piece blocks light per unit length, and colour says what light it gives off. Check: both numbers come from the scene, nothing is computed yet.
- Turn density into opacity. A piece of density and length blocks the fraction of the light that passes through it. Piece 1: . Piece 2: . Check: both lie between and , and the denser piece blocks more.
- Work out transmittance. Transmittance is the share of light that reaches a piece from behind, after the pieces in front have taken their share. Light from piece 2 has to pass piece 1, so it keeps of its brightness. Light from piece 1 keeps everything, so . Check: equals , which is .
- density 0.5
- density 1
- Weight each piece. The weight is , the share of the pixel that comes from that piece. . . Check: the two weights add to , which equals , the opacity of the whole ray (total density times length is ).
- Add up the colours. The pixel is . The is the light that gets through both pieces and reaches the black background. Check: lies between the two piece colours and , as it must.
flowchart LR A[Camera ray for one pixel] --> B[Sample points along the ray] B --> C[Density and colour at each sample] C --> D[Opacity from density and step length] D --> E[Transmittance: light left after the samples in front] E --> F[Weight = transmittance times opacity] F --> G[Sum weighted colours plus background]
The math
Definition
Along a ray for between and , let be the density and the colour at the point . The rendered colour is
Here is the camera centre, is the direction through the pixel, and measures distance along the ray. The function is the transmittance: the fraction of light from the point at distance that survives the medium between it and the camera.
Step 1 in symbols: the ray
A point on the ray is , a Vector sum. Smaller means nearer the camera, so the integral runs from the near end to the far end .
Step 3 in symbols: opacity over one piece
If is constant on a piece of length , then over that piece. The light surviving the piece is , a use of the Exponential Function with a negative exponent, so the opacity is
Step 4 in symbols: transmittance multiplies
Splitting the integral at a point shows that transmittance is multiplicative. Light surviving pieces and together is the product of the two survival fractions:
For piece 2 in the walkthrough, .
Step 5 in symbols: the discrete sum
Split into pieces with edges , lengths , and constant density and colour on each piece. On piece , the integral is exactly , so
Check: because , the weights telescope. They add to , so the leftover is exactly the share that goes to the background .
Worked examples
A ray of length 2 passes through a uniform medium with everywhere. The colour is white, , and the background is black.
- Total density times length: .
- Transmittance at the far end: .
- Opacity of the ray: .
- Check by integrating directly: .
- Interpretation: white light through a medium that blocks 63 percent of it gives a grey pixel with value 0.6321. Step 3 and step 4 agree because the colour is 1 everywhere.
Three samples, each of length , with densities and colours . The background is black.
- Opacities: , , .
- Transmittances: , , .
- Weights : , , .
- Total weight: , which equals . Check: the leftover is .
- Pixel: .
Interpretation: the empty first sample contributes nothing. The dense second sample dominates because nothing in front of it blocks it. The third sample sits behind it, so its colour counts for much less.
A camera looks through fog toward a red wall. Samples are taken every 2 metres at . The density is at samples 1, 2 and 5, and per metre at samples 3 and 4. The red channel of the fog colour is at sample 3 and at sample 4. The red value of the wall behind is .
- Opacities with : , and .
- Transmittances: , , and , where is the light reaching the wall.
- Weights: and .
- Total weight from the fog: , which is . The wall gets the leftover .
- Red value: .
Try it: suppose the fog thins out at sample 4, so its density is there and everything else is unchanged. Work out the red value the same way, noting which weight becomes and what reaches the wall. Answer: . The contribution from sample 3 is still . After sample 3 only of the light survives, so the wall contributes . Then .
Common mistakes and tradeoffs
It is tempting to think that density is the same as opacity. In fact opacity is , which depends on the step length as well. The same density over a shorter step blocks less light, so a renderer must keep in the formula.
It is tempting to average the sample colours. In fact each colour is weighted by the light that reaches the camera through it, because the samples in front block the ones behind. A bright sample hidden behind a dense one should count for little, and averaging would give it the same say as a visible one.
It is tempting to use directly as the weight. In fact the weight is . In Example 2, using as its weight would give the hidden third sample far too much influence. Forgetting is the most common bug.
It is tempting to expect the weights to add to . In fact they add to the opacity of the ray. A fully opaque ray has weights that sum to , and a clear ray leaves everything to the background.
Use volume rendering for things that are genuinely translucent, such as fog, smoke, cloud and learned radiance fields. Its formula is smooth in the density and colour, so you can fit it to photographs with gradients. The cost is many samples per ray, and the answer depends on how finely you sample. For solid surfaces, drawing triangles with a rasteriser is much cheaper and sharper. Gaussian Splatting avoids sampling each ray by projecting soft blobs onto the image and blending them in depth order, which is faster to draw but gives up some of the physical form.
History
In the 18th century, Pierre Bouguer and Johann Heinrich Lambert described how light weakens exponentially as it passes through an absorbing material. In 1852 August Beer added how the weakening depends on concentration, and the result is now called the Beer-Lambert law. In 1984 James Kajiya and Brian Von Herzen published a method for ray tracing volume densities in computer graphics. Nelson Max's 1995 survey of optical models for direct volume rendering set out forms close to those in use today. The method spread through scientific visualisation and visual effects. In 2020 Mildenhall and colleagues used the same integral with a neural network to render new views of real scenes (NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis).
Recap
- A pixel corresponds to one ray, and its colour is an integral along that ray.
- Density gives the opacity of each small piece of ray: .
- Transmittance is the light that survives the pieces in front, .
- Each colour is weighted by , the weights add to the opacity, and the background receives the rest.
- Read next: Alpha Compositing for the same blending rule in two dimensions, Gaussian Splatting for a faster alternative, and NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis, which trains a network to supply the densities and colours.
Check yourself
QuestionRecall: what fraction of light survives a piece of length with constant density ?Show answer
It is . The opacity of that piece is one minus this, . Surviving and blocked light always add to one.
QuestionComputation: a single sample has density and length . What is its opacity?Show answer
The opacity is . Almost all the light is blocked, because the product of density and length is large.
QuestionWhy: why must the weight of each sample include the transmittance , not just its opacity ?Show answer
A sample's colour reaches the camera only if the light it gives off survives the samples in front of it. The opacity alone says how much this sample blocks, but a sample hidden behind a dense one should contribute little. Multiplying by accounts for that.
QuestionApplied: a renderer doubles the number of samples along a fixed ray, keeping the density and colour functions the same. Does the total opacity of the ray change?Show answer
No. The total opacity is , which depends only on the integral of density along the ray. Cutting each piece in two gives values that add up to the same integral, and the product of the factors is unchanged. Each individual changes, but the total does not. What the extra samples do change is how accurately the colour sum approximates the integral.