Skip to content

Instantly share code, notes, and snippets.

@XProger
Created August 23, 2016 09:06
Show Gist options
  • Save XProger/6d1fd465c823bba7138b638691831288 to your computer and use it in GitHub Desktop.
Save XProger/6d1fd465c823bba7138b638691831288 to your computer and use it in GitHub Desktop.
frustum culling for sphere
// Computes signed distance between a point and a plane
// vPlane: Contains plane coefficients (a,b,c,d) where: ax + by + cz = d
// vPoint: Point to be tested against the plane.
float DistanceToPlane( vec4 vPlane, vec3 vPoint )
{
return dot(vec4(vPoint, 1.0), vPlane);
}
// Frustum cullling on a sphere. Returns > 0 if visible, <= 0 otherwise
float CullSphere( vec4 vPlanes[6], vec3 vCenter, float fRadius )
{
float dist01 = min(DistanceToPlane(vPlanes[0], vCenter), DistanceToPlane(vPlanes[1], vCenter));
float dist23 = min(DistanceToPlane(vPlanes[2], vCenter), DistanceToPlane(vPlanes[3], vCenter));
float dist45 = min(DistanceToPlane(vPlanes[4], vCenter), DistanceToPlane(vPlanes[5], vCenter));
return min(min(dist01, dist23), dist45) + fRadius;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment