# Instances and culling

**URL:** <https://forum.babylonjs.com/t/instances-and-culling/31573>\
**Category:** Questions\
**Created:** [June 21, 2022, 9:46pm UTC](https://forum.babylonjs.com/t/instances-and-culling/31573 "2022-06-21T21:46:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johan\_Rabie](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johan_rabie/32/24242_2.png) [@Johan\_Rabie](https://forum.babylonjs.com/u/Johan_Rabie)\
**Post date:** [June 21, 2022, 9:46pm UTC](https://forum.babylonjs.com/t/instances-and-culling/31573/1 "2022-06-21T21:46:54Z")

</div>

I was thinking about how I could optimize some scenes and I thought that using instancing might be a good way to deal with some of the performance I want to do.  
But I was wondering about the culling behavior.

I am assuming that instances it self is not culled.  
If the master object goes out of frustrum does it also cull the instances even though the instances might be in view?

Same goes for occlusion culling.  
Does babylonjs by default do occlusion culling?  
If it does and the master object is occluded but some instances are visible, will it still be culled?

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [June 22, 2022, 12:35pm UTC](https://forum.babylonjs.com/t/instances-and-culling/31573/2 "2022-06-22T12:35:07Z")

</div>

> [@Johan\_Rabie](#):
>
> If the master object goes out of frustrum does it also cull the instances even though the instances might be in view?

Nope, that would negate the advantage of using them 🙂

I have disabled the original mesh in this playground, but the instances are still showing - [https://playground.babylonjs.com/#8L50Q3#146](https://playground.babylonjs.com/#8L50Q3#146)

@sebavan can help further for sure 🙂

---

<div class="post-metadata">

**Author:** ![Johan\_Rabie](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johan_rabie/32/24242_2.png) [@Johan\_Rabie](https://forum.babylonjs.com/u/Johan_Rabie)\
**Post date:** [June 22, 2022, 3:12pm UTC](https://forum.babylonjs.com/t/instances-and-culling/31573/3 "2022-06-22T15:12:08Z")

</div>

Ahh, excellent, thank you for your effort.  
I was pondering about how to efficiently build environments on the web.  
Take walls for example, it will be great if you can download a single mesh that represents a wall part and use instancing to follow a path drawing the actual wall.  
This means less data to download and much memory to use but I suppose you might need to use a mesh per wall with instances filling the length of that wall.  
In that way if the mesh and instances are behind the camera, those will be excluded from the render graph.

I am not 100% sure how this will be affected with octrees but I am certainly interested in testing it further 🙂

---

<div class="post-metadata">

**Author:** ![Johan\_Rabie](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johan_rabie/32/24242_2.png) [@Johan\_Rabie](https://forum.babylonjs.com/u/Johan_Rabie)\
**Post date:** [June 22, 2022, 5:02pm UTC](https://forum.babylonjs.com/t/instances-and-culling/31573/4 "2022-06-22T17:02:04Z")

</div>

Am I correct in assuming that active meshes are items that will be drawn.  
I did a test and found that sometimes I get some odd results about what meshes are active when when not.

> **[Babylon.js Playground](https://playground.babylonjs.com/#HDWL3F%2397)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [June 22, 2022, 5:40pm UTC](https://forum.babylonjs.com/t/instances-and-culling/31573/5 "2022-06-22T17:40:50Z")

</div>

We have a bit of offset around the meshes to prevent popping effects and such which might impact the result

---

<div class="post-metadata">

**Author:** ![slin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/slin/32/36084_2.png) [@slin](https://forum.babylonjs.com/u/slin)\
**Post date:** [June 22, 2022, 5:52pm UTC](https://forum.babylonjs.com/t/instances-and-culling/31573/6 "2022-06-22T17:52:50Z")

</div>

> Am I correct in assuming that active meshes are items that will be drawn.

Yes, active meshes are the meshes that camera will render. I remember it also affects the instances in my project. E.g. If the original mesh is not active, the instances are not rendered.

Since I need almost all the meshes all the time in my project, all my meshes has:

`mesh.alwaysSelectAsActiveMesh = true;`

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [July 21, 2022, 11:50am UTC](https://forum.babylonjs.com/t/instances-and-culling/31573/7 "2022-07-21T11:50:25Z")

</div>

Hello just checking in if you’d like any more help on this @Johan_Rabie

---

<div class="post-metadata">

**Author:** ![Johan\_Rabie](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johan_rabie/32/24242_2.png) [@Johan\_Rabie](https://forum.babylonjs.com/u/Johan_Rabie)\
**Post date:** [July 21, 2022, 1:59pm UTC](https://forum.babylonjs.com/t/instances-and-culling/31573/8 "2022-07-21T13:59:17Z")

</div>

No sorry I think we can mark this as resolved, thanks you.
