How to use ParticleHelper and HighlightLayer without visual issue?

Hello !
So my question is quite simple : how can I have both an explosion using the ParticleHelper and a working HighlightLayer ?
Here is a simple playground that I have crafted using two other playgrounds coming from the documentation :
Playground with issue : Babylon.js Playground
It comes mostly from the playground of the ParticleHelper (explosion : and the playground of the mesh highlighter.

As you can see, at first the sphere is well highlighted (green highlight). But if you press space to trigger the explosion then the mesh becomes completely green, the highlight layer seems to have been affected by the explosion…

I tried playing with layerMasks to separate these two things, but even by putting the explosion on another layerMask the highlightLayer was still affected… I feek like this should be the solution but I couldn’t make it work…

Also I noticed that this issue only appears with the explosion effect : if you replace the effect with fire for example the issue won’t appear ! Do you know what is the difference between these two effects that could explain the visual issue ?

Thanks in advance !

The explosion effect uses several particle systems, and some of them are using rendering group id 1 and 2.

By default, when rendering objects in a rendering group, the system starts by clearing the depth and stencil buffers.

The problem is that the highlight layer relies on the stencil buffer, so it should stay untouched.

To do that, you can instruct the system to not clear the stencil buffer when dealing with the rendering group id 1 and 2 by calling:

scene.setRenderingAutoClearDepthStencil(1, true, true, false);
scene.setRenderingAutoClearDepthStencil(2, true, true, false);

…and welcome aboard!

1 Like

Thank you very much @Evgeni_Popov for your answer, for updating my playground and for your welcome message.
I tried your solution in my game and everything works fine now, there doesn’t seem to be any side effect when the stencil buffer stays uncleared.

1 Like