
2. Interactive Sparse Eulerian Fluid 295
float2 IntersectBox ( Ray r , float3 boxmin , float3 boxmax)
{
// Compute i n t e r s e c t i o n o f ray with a l l s i x bounding box p la ne s .
float3 invR =1.0 /r . d ;
float3 tbot = invR ∗ ( boxmin . xyz − r . o );
float3 ttop = invR ∗ ( boxmax . xyz − r . o );
// Reorder intersections to find smallest and largest on
// each axis .
float3 tmin = min ( ttop , tbot );
float3 tmax = max ( ttop , tbot );
// Find the largest tmin and the smallest tmax.
float2 t0 = max ( tmin . xx , tmin . yz );
tnear = max ( t0 . x , t0 . y );
t0 = min ( tmax . xx , tmax . yz );
tfar = min ( t0 . x , t0 . y );
return float2 ( tnear ...