Where does the volume start?

Finding the volume with a slab test

A volume has no surface to intersect, so there is nothing for a ray to hit. What it does have is a bounding box, and a box is trivial to intersect: treat it as a pair of parallel slabs per axis, work out the interval of t the ray spends inside each one, and take the overlap. Everything before tenter and after texit is empty space, and sampling it is pure waste.

The ray and the box
Drag the origin or the aim dot
the two intervals, on the t axis overlap is where the marching happens
inside the x slab inside the y slab inside both — inside the box
Marching what the test saves
24
6.0

The test live values

      
The three cases and how the test tells them apart

The intervals overlap ahead of the ray. Ordinary case — march from tenter to texit.

The intervals do not overlap. The ray passes the box on one side. There is no t that is simultaneously inside both slabs, so tenter > texit and the test fails without any geometry being touched.

The overlap is entirely behind the origin. The box is behind the camera. Both values come out negative, which is why the entry point is clamped with max(tenter, 0) — without that clamp a camera sitting inside the volume would start marching from a point behind itself. Drag the origin into the box and watch that clamp do its job.

Why this matters more than it looks the empty space problem

A cloud occupying a fifth of the screen still has rays crossing the whole scene. Without a bounds test every one of those rays samples the density function along its entire length, and the overwhelming majority of those samples return zero — paid for in full.

The same reasoning scales up. Production volume renderers do not stop at one box: they subdivide the volume into a grid of bricks, mark which bricks are empty, and skip whole regions inside the bounds as well. It is the same idea applied recursively, and it is the volumetric answer to the acceleration structures a ray tracer uses on triangles.

t at entry
t at exit
Distance inside the box
Samples saved
Result
Six comparisons and two divides, in 3D. That is the entire cost of the test, and it runs once per ray before any density is touched. Note also what it gives you beyond the saving: a definite tenter and texit means the step size can be computed as (texit − tenter) / N, so every ray takes the same number of samples regardless of the angle it enters at. Without that, a ray crossing the box corner‑to‑corner would be sampled far more sparsely than one crossing face‑to‑face, and the difference would show up as a brightness seam across the image.