Instanced meshes issue with frozen materials and active mesh selection

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:

  1. Create a master mesh with its material frozen
  2. Create an instance outside of the camera frustum (causing it to be excluded from the active meshes)
  3. 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.

Hello @ghempton , how are you doing?

This seems to be a bug on how material.freeze() affects rendering behavior for instances. @sebavan are you familiar with this?

It looks awfully similar to smthg we fixed with @Deltakosh a couple weeks ago but with instances this time.

let s see if he has a quick idea or I ll have a look today.

ok I have a fix :slight_smile:
fix cache miss with instances out of frustrum by deltakosh · Pull Request #12672 · BabylonJS/Babylon.js (github.com)

1 Like

You guys are amazing as always! Looking forward to trying the fix out.

1 Like

Merged! it is on master and will be live on Thursday morning :slight_smile:

3 Likes