How to dynamically update MAX_RENDERINGGROUPS

Hi everyone !
I haven’t post for a long time but i still use BJS daily and thanks your all for the amazing work done !

I have an issue working with the rendering groups and I am not sure if this is a bug or if I don’t update the renderingManager correctly.

In my app, I don’t know in advance the number of rendering groups that I will need in the scene as meshes are imported from user actions. That’s why I would like to dynamically update this value.

Here is a PG :

5 spheres are created from left to right with increasing renderingGroup for each of them.

  • If MAX_RENDERINGGROUPS is let to 4 (initial state), then the 5th sphere is not rendered, which is the expected behaviour.
  • If MAX_RENDERINGGROUPS is set to 5 before the scene creation, the 5th sphere is rendered in front of the others as expected. (decomment line 7)
  • If MAX_RENDERINGGROUPS is set to 5 after the scene creation, the 5th sphere is then rendered, but not “in front of” the previous rendering groups.
    Btw, If line 4 is commented (no more force of initial state at 4) and the page is run again, it then works

Is there a way to dynamically update MAX_RENDERINGGROUPS after the scene creation ?

Thank you !

Oh, that’s an interesting issue :slight_smile:

When you add a new rendering group you will need to add a clearing state for it. It initially loads with the number of clear-definitions that fits the max defined before the scene is created. If you add, you will need to set clearing to the new one:

Babylon.js Playground (


Thank’s @RaananW ! It works like a charm like that !
I now understand what was missing, and why ! :ok_hand:

1 Like