Advertisement

Plane intersection : Backface culling

Started by December 23, 2014 02:42 AM
0 comments, last by Randy Gaul 10 years, 1 month ago

Here a plane intersection function :


bool IntersectRayPlane( const CRay& Ray, const CPlane& Plane, float* t )
{
  const float Numerator = VectorDot( Plane.n, Ray.m_Origin ) + Plane.d;
  if( Numerator <= 0.0f )
    return false;
  const float Denominator = VectorDot( Plane.n, Ray.m_Direction );
  if( CMath::Abs( Denominator ) < CMath::EPSILON )
    return false;
  *t = -( Numerator / Denominator );
  return true;
}

This part is the backface culling :


if( Numerator <= 0.0f )
    return false;

Is it better to have a boolean param to enable or disable the backface culling ?

Edit :

Maybe that's more clear to do : const float Numerator = Plane.DistanceToPoint( Ray.m_Origin );

Maybe that's more correct to do : if( Denominator == 0.0f )

It's better to have two different functions for whether or not you care about backface tests. If backface culling is on, then call one kind of function, otherwise the other. This will allow you to factor out the branching due to the backface boolean out of any processing loops.

This topic is closed to new replies.

Advertisement