Efficient empty volume rendering in Cycles Suppose I am rendering a smoking torus from above in Cycles:

(at laughably bad resolution, of course, but that's not the point)



Cycles spends a lot of time rendering the empty space, even though the density is 0 (and therefore, the volume should have no effect on light). I don't quite know why Cycles has to think so much.

In fact, the render times can be almost halved (from 11 min to 6 min) by using an old BI trick and masking empty parts of the volume with a shadeless object (which can be made here).



This is fine for simple test renders, but now I'd like to make actual scenes with smoke and fire in them, and obviously my little masking trick won't work because there are objects behind the smoke that can't be masked. (Also, shrinking the domain is not an option)

How can I optimize scenes with large empty volumetric sections?
It's actually quite similar in Cycles and seems to speed up renderings as well (which indicates there is still room for optimization in Cycles volume rendering).

So with a basic setup:


You get result (~16 seconds):


Now add a Shader Mix Node and use Density as a Mix factor:


With current Cycles algorithms you can leave the second slot unconnected - it just tells Cycles to compute volume rays for areas that are masked by density with a value greater than 0.5 (screen shows the reverse of that, but it's the same if you connect Volume shader in second slot and use converter math node 'Greather than', which would be more intuitive, I guess).

Now the result of this little tweak:

Time almost halves! But there are very crisp edges - you can tweak that with changing the converter math node value to a very low number (which would tell cycles to leave out only area with density values close to zero:


And the result:


Still reasonable improvement over the original render time and nearly the same visual effect.