Huge performance drop when animating

Hi guys!

What can be the problem with this? When you click the button, it starts to animate the visibility property on all meshes. In my case the FPS drops from ~100 to ~45 FPS. Yes, there are 1700 meshes, but is it such a big deal? Any ideas?

Thank you!


Each time the visibility property of a mesh is updated, the material of this mesh is flagged as dirty, meaning the effect must be re-created.

I think we should be able to improve this by flagging as dirty only when the visibility is switched from 1 to something < 1 and vice-versa (same thing for the alpha property of the materials). What do you think @sebavan?

Sounds like a good idea to try !!!

Guys, and can this cause the strange behavior I’m experiencing in the following scenario? I animate overlayAlpha (black) from 0 to 1 on my meshes. While all black I change the material of the meshes. Than I animate the overlayAlpha to 0 to reveal the meshes with the new material set. So far OK. Now I animate the overlayAlpha from 0 to 1 and I set the materials on my meshes back to the original materials and I animate the overlyAlpha again from 1 to 0 to reveal the new (the original ones) materials. Setting a new material on the meshes doubles the number of vertices in the scene. Any ideas?

Dealing with materials only can’t change the geometry of meshes, so it’s not possible the total number of the vertices in the scene can change. I think you will need to setup a repro of this behaviour.

It would be very cool to have this in both cases. I am just a few steps to finish my project, I use alpha and overlayAlpha anims a lot and this part is scaring me, because I didn’t find a way how to overcome the performance problems yet. I would like to have nice smooth animations without my notebook trying to take off from my desk :joy: and that was me who pushed hard to switch from Unity to Babylonjs, so guys is there a chance, that the optimalizations gets implemented soon and I can keep my balls safe from my bosses leg? :joy::joy::joy: Thank you!

So I could try to merge the meshes and animate alpha on the merged mesh?! I’ll try it.

I think it’s creating a copy of the mesh not visible in the inspector and believe or not just by removing the line where I assign the material the weird behavior goes away. I’ll try to isolate the case and setup a PG.

Here’s a temporary fix which won’t dirtyfy the materials if not necessary:

Also, freezing the world matrices can help in your case as you have quite a number of meshes (it’s also in the PG above).

1 Like

Thanks a lot, awesome! Yes, I am freezing the world matrices already.

Bad news, this causes the render loop to lock in certain situations. For example on the mentioned material assignment. :frowning:

What do you mean by “locking the rendering”?

Here’s the PR:

Here it is:

Open the Inspector/Statistics and after 10 seconds the first animation takes place. There are originally about 1.3mil indices. When the anim starts it pops up to 2.5 and over 5mil. After 5 seconds another animation takes places and it freezes the render loop.

Would you please have a look at it?

Thank you!


There are some errors in the console log when running your PG:

Anyway, setting needDepthPrePass = true on a material will make the object rendered in the depth buffer as a first pass, so all objects with materials having needDepthPrePass = true will be rendered 2 times.

Ooops… Yes, that was causing the lock :stuck_out_tongue: had a filter set in debugger console so I didn’t catch this one, my bad. However the information about needDepthPrePass demystified the vertice doubling. Thank you very much for your effort!