# Unity3d custom Frustum Culling - find all points on the near side of a sphere

Scenario

I have a custom sphere of 1 million plus vertices that I'm using for an interactive. Looping through 1M+ points per mouse movement is exceedingly costly so I've decided to leverage frustum culling. This helps but all the points on the back-facing side of the sphere are still being looped through which is still very costly.

My plan is to cut the sphere in half with a plane that is perpendicular to the viewing camera's angle. I'll place the sphere origin at the 0,0,0 of the sphere and viola it's cut in half.

Question

My issue is that if the plane is at an angle, which it will be 99.9% of the time, how can I verify that a given Vector3 is on the normal side of the plane?

extra

• I'm using GeometryUtility.CalculateFrustumPlanes to get the frustum bounds
• While writing this question I thought (and plan) to prototype adding my plane "slice" to the frustum boundary planes then using GeometryUtility.TestPlanesAABB to determine which points should be rendrered
• Presumably you tried Plane.GetSide(Vector3 point)? Dec 9, 2021 at 0:32
• @DMGregory out of my shame I want to delete this question but perhaps posting my final solution will be helpfull for someone else. ¯\_(ツ)_/¯ Dec 9, 2021 at 23:56
• I'd say a detailed answer is much better than just a link to a relevant function. ☺️ So that sounds to me like a good plan. Dec 10, 2021 at 0:38

## 1 Answer

I came up with the idea to shorten the camera frustum to end at the center of my target group, check all of my object's collider positions against TestPlanesAABB, then set the camera frustum back to what it was.

public static bool IsColliderVisible(Collider collider, Vector3 targetPos)
{
UnityEngine.Camera camera = UnityEngine.Camera.main;
float distanceToCutoff =
Vector3.Distance(camera.transform.position, targetPos);
float frustumLength = camera.farClipPlane;
camera.farClipPlane = distanceToCutoff;
Plane[] frustumPlanes = GeometryUtility.CalculateFrustumPlanes(camera);
camera.farClipPlane = frustumLength;

return GeometryUtility.TestPlanesAABB(frustumPlanes, collider.bounds);
}


extra

I may end up using a nearest-neighbor type algorithm to take a point I know is within view and work form there.