Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:48:55

0001 #pragma once
0002 
0003 LEAF_FUNC
0004 float distance_leaf_slab( const float3& pos, const quad& q0, const quad& q1 )
0005 {
0006    const float3 n = make_float3(q0.f.x, q0.f.y, q0.f.z) ;    
0007    const float a = q1.f.x ; 
0008    const float b = q1.f.y ; 
0009    float pn = dot(pos, n ); 
0010 
0011    //float sd = fmaxf( pn - b, a - pn ) ; 
0012    float sd = fmaxf( pn - b, pn - a ) ;   // uncertain here
0013 
0014    return sd ; 
0015 }
0016 
0017 
0018 /**
0019 intersect_leaf_slab
0020 ---------------------
0021 
0022 One normal, two distances
0023 
0024 **/
0025 
0026 
0027 LEAF_FUNC
0028 void intersect_leaf_slab( bool& valid_isect, float4& isect, const quad& q0, const quad& q1, const float t_min, const float3& ray_origin, const float3& ray_direction )
0029 {
0030    const float3 n = make_float3(q0.f.x, q0.f.y, q0.f.z) ;    
0031 
0032    const float a = q1.f.x ; 
0033    const float b = q1.f.y ; 
0034 
0035    float idn = 1.f/dot(ray_direction, n );
0036    float on = dot(ray_origin, n ); 
0037 
0038    float ta = (a - on)*idn ;
0039    float tb = (b - on)*idn ;
0040    
0041    float t_near = fminf(ta,tb);  // order the intersects 
0042    float t_far  = fmaxf(ta,tb);
0043 
0044    float t_cand = t_near > t_min  ?  t_near : ( t_far > t_min ? t_far : t_min ) ; 
0045 
0046    valid_isect = t_cand > t_min ;
0047    bool b_hit = t_cand == tb ;
0048 
0049    if( valid_isect ) 
0050    {
0051        isect.x = b_hit ? n.x : -n.x ;
0052        isect.y = b_hit ? n.y : -n.y ;
0053        isect.z = b_hit ? n.z : -n.z ;
0054        isect.w = t_cand ; 
0055    }
0056 }
0057 
0058