Created
August 23, 2016 09:06
-
-
Save XProger/6d1fd465c823bba7138b638691831288 to your computer and use it in GitHub Desktop.
frustum culling for sphere
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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