Test to see if mesh is seen by camera

Hi!

Is there any way to check to see if a mesh is visible by the camera? Not like the .isVisible but like if a mesh is in the way of it.
https://playground.babylonjs.com/#QPQC8Z

Kinda like if you move above the sphere and look down. you cant see the ground object. Is there any way to test for that?

Hi Givo,

How precise do you need to be? The trick with this question (unless I’m misunderstanding) is that the answer isn’t simply yes or no; you have to define how you want to deal with partial visibility. Potential options range from a small number of raycasts (if you’re not too worried about partial visibility and the obstacles you care about are all pickable) to precomputed or periodically updated visibility maps (if your environment is relatively constrained and stable such that it makes sense to preprocess it) to shaders evaluating the rendered depth/scene pixel by pixel (if you need things very precise and have the resources – both dev and compute – to achieve this).

Picking a few important points on your target (for example, the center and/or corners of your ground plane in your Playground) and raycasting at them is almost certainly the easiest way to get off the ground, though it’s not really efficient and could be imprecise. Will that work? If not, can you tell us a little more about your use case?

Uh, I was hoping for efficient. I was thinking about using raycasts, but for 1000 meshes that is not a good idea.

https://playground.babylonjs.com/#D1Z1VL#22

It is a little voxel “engine” I’ve been making. with “stupid” meshing (every voxel is a cube!) basically having 1000 cubes all with textures and physics is not a good idea. Having the meshes be disabled when not visible might increase fps.

Maybe occlusion queries? (but only webgl2): Occlusion Queries - Babylon.js Documentation

1 Like

When would wbgl1 be used? Isn’t it always webgl2?

Well it is webgl1 on iOS and Internet Explorer

Oh. I’m assuming people wouldn’t try to play a voxel clone without touch contols on ios and internet explorer is probably not used by a computer literate person, so I think I’m fine because I’m just messing around.

1 Like

When I look at the lot of cubes, 5 fps

away, 50 fps

https://playground.babylonjs.com/#D1Z1VL#23

why?


(from Chrome performance debugging)

From a perspective that takes in most of your block of cubes, I see approximately 7 milliseconds of occlusion query alone, without diving deeply into the profile. This is a relatively expensive check, so I’m not sure you’ll be able to do something like this indiscriminately without negatively impacting performance. If your scenario is voxel-specific, there are almost certainly tricks you can do depending on the specifics of your use case.

1 Like

Oh. Thanks for the explanation. I didn’t know chrome had these render tools. Thanks! (X2)