# How to determine if a mesh is fully hidden behind other mesh?

**URL:** <https://forum.babylonjs.com/t/how-to-determine-if-a-mesh-is-fully-hidden-behind-other-mesh/52904>\
**Category:** Questions\
**Created:** [August 19, 2024, 11:37am UTC](https://forum.babylonjs.com/t/how-to-determine-if-a-mesh-is-fully-hidden-behind-other-mesh/52904 "2024-08-19T11:37:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![poshuk](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/poshuk/32/38718_2.png) [@poshuk](https://forum.babylonjs.com/u/poshuk)\
**Post date:** [August 19, 2024, 11:37am UTC](https://forum.babylonjs.com/t/how-to-determine-if-a-mesh-is-fully-hidden-behind-other-mesh/52904/1 "2024-08-19T11:37:35Z")

</div>

Hi all,  
I am trying to make this selection demo better but stuck on filtering out fully hidden meshes.  
The existing solution is very slow due to raycasts.  
is there any better solution to filter hidden meshes or selecting meshes in general?

PG: [https://www.babylonjs-playground.com/#Q5KMXP#116](https://www.babylonjs-playground.com/#Q5KMXP#116)

Thanks

---

<div class="post-metadata">

**Author:** ![poshuk](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/poshuk/32/38718_2.png) [@poshuk](https://forum.babylonjs.com/u/poshuk)\
**Post date:** [August 19, 2024, 12:40pm UTC](https://forum.babylonjs.com/t/how-to-determine-if-a-mesh-is-fully-hidden-behind-other-mesh/52904/3 "2024-08-19T12:40:47Z")

</div>

Thanks for the response.  
Yes i tried occlusion queries but it’s didn’t work and made scene slower too.  
Selection with occlusion: [https://www.babylonjs-playground.com/#Q5KMXP#117](https://www.babylonjs-playground.com/#Q5KMXP#117) (not working)

octree.select also doesn’t filter the occluded meshes.

---

<div class="post-metadata">

**Author:** ![alexchuber](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/alexchuber/32/52000_2.png) [@alexchuber](https://forum.babylonjs.com/u/alexchuber)\
**Post date:** [August 20, 2024, 8:29pm UTC](https://forum.babylonjs.com/t/how-to-determine-if-a-mesh-is-fully-hidden-behind-other-mesh/52904/4 "2024-08-20T20:29:45Z")

</div>

Using occlusion queries in this scenario won’t work anyway (TIL!) From the docs:

> **Very important** : The meshes you activate for occlusion requests **must** be rendered _after_ their potential occluders! The easiest way to do this is to set their `renderingGroupId` property to a value greater than that of the occluding meshes (don’t forget to call `scene.setRenderingAutoClearDepthStencil()` with the appropriate parameters, as you probably won’t want to clear the depth buffer between rendering groups).

As far as other methods go, there may be a way via stencils or by GPU picking in the selected screen area.

Are you trying to filter out occluded objects for performance reasons?

---

<div class="post-metadata">

**Author:** ![poshuk](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/poshuk/32/38718_2.png) [@poshuk](https://forum.babylonjs.com/u/poshuk)\
**Post date:** [September 4, 2024, 6:56pm UTC](https://forum.babylonjs.com/t/how-to-determine-if-a-mesh-is-fully-hidden-behind-other-mesh/52904/5 "2024-09-04T18:56:58Z")

</div>

I am developing a feature in an app where users can select machine parts and set texture/color to the group.

I ended up implementing color picking. Its faster than raycasts and pixel perfect so partially visible meshes can also selected.  
Color picking: [https://www.babylonjs-playground.com/#Q5KMXP#129](https://www.babylonjs-playground.com/#Q5KMXP#129)

What i have if a tiny bug where in imported meshes, sometimes after drawing selection box for first time it does not select meshes but after that it works fine.  
do you have any idea what might be causing this issue?  
🪲 [https://www.babylonjs-playground.com/#Q5KMXP#130](https://www.babylonjs-playground.com/#Q5KMXP#130)

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [September 4, 2024, 7:45pm UTC](https://forum.babylonjs.com/t/how-to-determine-if-a-mesh-is-fully-hidden-behind-other-mesh/52904/6 "2024-09-04T19:45:43Z")

</div>

I’ve recently added this one:

> [@GPU multi picking](https://forum.babylonjs.com/t/gpu-multi-picking/53218/1):
>
> A function called multiPickAsync has been added. It’s similar to the pickAsync function but accepts an array of IVector2Like coordinates as an input not just a single one. DOCS: [Babylon.js docs](https://doc.babylonjs.com/features/featuresDeepDive/mesh/interactions/picking_collisions#gpu-picking) (After the PR for the docs gets merged: [Update picking\_collisions.md by RolandCsibrei · Pull Request #1187 · BabylonJS/Documentation · GitHub](https://github.com/BabylonJS/Documentation/pull/1187/files))

---

<div class="post-metadata">

**Author:** ![poshuk](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/poshuk/32/38718_2.png) [@poshuk](https://forum.babylonjs.com/u/poshuk)\
**Post date:** [September 5, 2024, 4:23am UTC](https://forum.babylonjs.com/t/how-to-determine-if-a-mesh-is-fully-hidden-behind-other-mesh/52904/7 "2024-09-05T04:23:14Z")

</div>

That’s great!  
I’ll use it in my annotation viewer piece next.

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [September 5, 2024, 4:33am UTC](https://forum.babylonjs.com/t/how-to-determine-if-a-mesh-is-fully-hidden-behind-other-mesh/52904/8 "2024-09-05T04:33:02Z")

</div>

> [@poshuk](#):
>
> do you have any idea what might be causing this issue?

I bet your render target is not ready yet.

---

<div class="post-metadata">

**Author:** ![poshuk](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/poshuk/32/38718_2.png) [@poshuk](https://forum.babylonjs.com/u/poshuk)\
**Post date:** [September 5, 2024, 5:32am UTC](https://forum.babylonjs.com/t/how-to-determine-if-a-mesh-is-fully-hidden-behind-other-mesh/52904/9 "2024-09-05T05:32:45Z")

</div>

You are right.  
Shader compilation takes more than a frame thats why rtt was blank.  
I fixed it by adding a flag to check if shader is compiled.

> **[Babylon.js Playground](https://www.babylonjs-playground.com/#Q5KMXP%23132)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL and WebGPU 3D scenes

thanks @roland for the help!
