InstancedMesh problem

I have a scene i export from Blender via glTF, and it seems that linked duplicates/instancedMeshes does some odd things, but maybe I am just missing something. I reproduced it in a PG;

https://playground.babylonjs.com/#EQI31P

The original mesh is the middle sphere, if you rotate the camera so the original goes out of frame the instanced versions wont contribute to the AO post effect. If you enable the bounding box in the inspector for the 3 objects only one bounding box will show at a time, depending on if original, instance 1 or instance 2 is in frame or not. So my thinking was that this ties in to how the AO behaves.

Is this a bug, or am I missing something? Do I need to “fix/freez” the instances or something ?

Nope this should work
Pinging @julien-moreau who is the creator of our SSAO effect

Thanks Deltakosh.

Here is a little more info for you both;

I have a sneaking suspition that it has something to do with instances tho. As mentioned the bounding box display in the inspector only show up on one of the meshes at a time. if the original mesh is in frame it gets the bounding box display otherwise they seem to get priority based on the order of when they were instanciated. You should be able to test that in my PG i think.

Also i had some similar issues when using scene.freezeMaterials() with instancedMesh in scene. Similar behaviour as my PG, but one mesh (the last instanced i think) was going invisible if none of the other instances or original was on screen/in frustum. The AO in this case still seemed to be displaying “correctly” tho, as if the object was still visible. Removing the scene.freezeMaterials() from my gltf loading resolved this particular case it seems.

I also noticed in one case that instances did not get displayed if the instances when the original was on screen while the instances was of screen on start. This was while still using scene.freezeMaterials() in my glTF loading. Here they also still get AO while “invisible”. This one is probably me doing silly things and not knowing when to use freezMaterials() properly, but i found it interesting that they still got AO while “invisible”.

Again; I might just need to read up a bit more on freezeMaterials() before I use it, but i thought this might be helpful to mention, since it seemed to be a somewhat similar/related behaviour to my original problem.

I have not been able to reproduce this in a PG for now, so I am not quite sure what is causing these last two “issues”.

btw; come to think of it these last “issues” were in 4.0.3, will try to test in preview a bit later.

Probably something we fixed recently yep. I wait for @julien-moreau to comment on the intial issue

Hi. And thanks again for quick reply.

Sorry for adding even more, but I thought this might help in the debugging. I managed to recreate somewhat what was happening when I tried to freeze materials in my project.

I added a action on the F key to “toggle” on and of freezeMaterials();

https://playground.babylonjs.com/#EQI31P#3

So if you toggle the freeze on with only the middle sphere (the original) visible and then pan over to one of the others to the right or the left they are invisible, with only the AO showing until you pan enough to get the original out of the frustum, then that disapear to.

Also I noticed that if you freeze with the original and one other in frustum, then look up or down until both are out of frustum, resenter the view and then tilt back so you only get the original in frame again. Then only the AO shows up until you pan over to frame one of the instanced once again.

I could not find where i originaly read about the freezeMaterial, so all i got to go from is the API description. I thought this would only freeze materials from being recalculated or recompiled, but I might have misunderstod here.

Anyway, lets wait and hear what Julien has to say, and have a great weekend in the meantime :slight_smile:

@Elk thanks for reporting! I’m having a look ASAP!

2 Likes

@Deltakosh I’m checking to understand the problem and it looks like the instances have a problem while rendering the depth renderer. As you can see in the screenshot, the left sphere is not rendered in the depth map so the AO is appiled only on the background:
image
I chekced the depth map and the sphere is not rendered:
image
Would you mind to help finding the problem?