We are working on our application and as part of making things performant we are relying on instancing as well as freezing materials. The issue we are encountering is that the following scenario causes issues and I was hoping that someone could shed some light on a possible solution. The following series of events seems to cause instanced meshes to not render:
- Create a master mesh with its material frozen
- Create an instance outside of the camera frustum (causing it to be excluded from the active meshes)
- Adjust the camera so that the instanced mesh is now inside the camera frustum (causing it to be included in the active meshes)
This results in the instanced mesh not rendering.
What is interesting, however, is that this issue doesn’t happen if any instances are inside the initial active mesh selection (e.g. if there were 1k instances and one happened to be inside the active meshes then the issue doesn’t seem to happen).
Here is a playground which shows the issue: https://playground.babylonjs.com/#8L50Q3#143 . There is a second instanced mesh to the right of the box in the scene that does not render. To reproduce the fix simply uncomment the lines that create the second instance that is visible.
Any ideas? We have also explored only freezing the material until after an initial render, etc. but this seems to have no effect. The issue also seems to sporadically fix itself when other meshes that are seemingly unrelated are added to the scene.