A texture with one more dimension
The volume density field
A 2D texture is looked up with (u,v) and returns a colour. A 3D texture is looked up with (x,y,z) and returns, here, a single density — how much medium is present at that point in space. It is stored the obvious way, as a stack of 2D slices, and it is filtered the obvious way, by blending the eight texels surrounding the sample point instead of four.
Twelve of the slices, drawn one behind the other. The hardware stores exactly this — a contiguous run of 2D images — and texture(vol, vec3(x,y,z)) is the operation that reaches into two neighbouring slices and blends between them.
The same volume, ray marched with a light. Drop the resolution to 8³ and switch to nearest — the texels become visible as cubes, which is the volumetric version of a pixelated texture.
| texel | x | y | z | value | weight |
|---|
—
Doubling the resolution costs eight times the memory, not four. That single fact is why production cloud systems rarely store a big uniform grid — they use sparse structures, tile the volume, or generate the density procedurally in the shader and store nothing at all.