Detect if entity rendered

Hi guys,

Is there a way to check if a object is within any cameras render area?

Thank you for any advices.
Radek

Hmm. Havenā€™t done it myself and thereā€™s no inbuilt function that I know of that does it.

However, you could use the frustum to check if the bounding sphere of the object is in view which might be enough for your use case?

https://developer.playcanvas.com/en/api/pc.Frustum.html#containsSphere

You may also want to look at the engine code to see how the engine determines what to cull.

Thank you. But if desired entity is covered with other object so camera do not see him but is in frustum ā€¦

Any other advices ?
Radek

You potentially have to look at spatial partitioning, shape/ray casting to see if object is in front of it partially or fully.

I canā€™t think of anything off the top of my head that could do it. Maybe @Mr_F has some ideas what can be done in the graphics pipeline.

It seems occlusion culling is not builtin in playcanvas ?

That should soon become very easy to do after we release some engine updates :wink:

And yeah, thereā€™s no occlusion culling at the moment (only frustum culling).

1 Like

I need this
I couldnā€™t Implement it can you convert it to playcanvas?

while(notRender){
FollowTheBall();
}

Record_2019_03_04_11_42_48_668

You can try getting the camera frustum and check if the ball is in it?

https://developer.playcanvas.com/en/api/pc.CameraComponent.html#frustum

https://developer.playcanvas.com/en/api/pc.Frustum.html

thanks I will check it out

Occlusion culling tends to be application-specific, unless you are refering to hardware-based occlusion culling which is a different story and is slightly more standardisedā€¦ https://github.com/tsherif/webgl2examples/blob/master/occlusion.html . https://tsherif.github.io/webgl2examples/occlusion.html

Are you sure the engine dev team is working to add hardware occlusion culling and queries?

The non-hardware approach:

Based off a given triangle, or convex hull for the obstacle, etc. you generate a bunch of 3D frustum planes for the obstacle in relation to the camera in which you then test with dot products to see if a particular object is fully covered (ie. fully enclosed within the obstacleā€™s frustum) to varying degrees of accruacy ( depending on what you needā€¦ bounding box in frustum, sphere in frustum etc.). (Hint: For convex hull obstacles, find the visible ā€˜outerā€™ edges of the convex hull obstacle by flagging edges which contain 1 face on one side of it being a backface (hidden) and the other face on the other side of that edge being frontface (visible to camera), order those edges and generate frustum planes in 3D for the convex hull obstacle. Youā€™d need to set up a convex hull object structure that keeps track of each edge of the mesh, and the 2 face references connected by each edge.

Like for this case: I have an actual percentage cover system:
But instead of dealing with convex hull obstacles, i incrementally clip away a view-aligned target bounding boxā€™s area via a polygon soup (the polygons are optimised-searched via a bounding volume hierachy) and then see if there is any remaining clipped area left. Essentially, each environment triangle polygon that is detected to be ā€œpotentially blockingā€ the view-aligned target bounding box is used to clip away the bounding boxā€™s polygon area.

https://playcanvas.com/project/573035/overview/sketchfab-assets-tests


1 Like