Possible to render a mesh above all other meshes but with exceptions?

Hi all! I have a quick question. Not sure if its even possible but I guess it doesn’t hurt to ask. I’d like to know if it’s possible to create a mesh that renders above all other meshes in my scene save for a list of exceptions. The tricky part is that I’d still like that list of exceptions to be rendered normally (i.e not rendered above everything). Would love to know if this is something that can be accomplished in babylon. Thanks!

Hello, Sure is.
In fact there are a number of methods for this.
Speaking about one single mesh and just a shortlist of exceptions and assuming these are all and will remain in the scene, I would look at layerMask or renderingGroupId (or a combination of both).
In-Depth layerMask

Else, if you set-up a quick PG to test the feature, I’m sure someone in this forum (including me) will help you find the best way for your needs.

Edit: May be have a look at this recent post that is probably quite similar to your needs (except you would push an array to use one of the layerMasks for your exception list)

Hey @mawa thanks for answering, I had a look at the post + docs you linked and been fiddling inside a PG for a little while. In particular i’ve tried using a combination of multiple cameras, renderGroupIds and layerMasks. I can get a mesh to render above everything but cant seem to get the exception meshes to work :frowning:. https://playground.babylonjs.com/#MCEB74#1

Ok, assuming that the red plane is the exception mesh(es) that should render above the yellow sphere and that the grey disc should render above all other meshes, correct? Something like this:

Hey @mawa close but not exactly. I’d still like the yellow sphere to occlude the red planes if they are in front of them. Currently the red planes (which are blocking the grey circle properly) are still rendered above the yellow sphere even when they are behind it.

To re-phrase what i’m looking to achieve. I want the grey circle to render above everything except for a number of exception meshes in the scene (Red Planes). Those exception meshes (Red Planes) should still render normally (i.e get occluded when an object is in front of them / occlude objects when they are in front of them)

Also would love to know if a multi-camera approach is the best or only way to achieve the effect I’m looking for. If that is the case, so be it but would ideally love a single camera approach if that’s a possibility.

Also upon closer inspection, I see that this solution relies on the creation order of each mesh? Forgive me if this is incorrect. In the app I’m building. Meshes are for the most part loaded in dynamically. Using the scenario above, I have control of when the grey circle and the red planes are loaded but not any of the other meshes in my scene. All those other meshes are loaded in dynamically.

I understand. Sadly never had this scenario before but yes, there are other ways. Just not sure which one would best apply here also with regards to

I’m a bit busy right now with some other stuff and since I don’t know the answer straight ahead, let me see if I can call in some people who might know @bghgary @sebavan May be you Guys can answer this. details are above. Thx a lot,

Thanks @mawa appreciate the help. I also understand that what i’m asking is pretty strange and specific. Like i said originally, I don’t even know if its possible to begin with :sweat_smile:

I unfortunately do not see any easy way to do this. The process might look like this:

Maybe you would use a special depth renderer to render the list of your special meshes.

Then clear the depth buffer and reuse the depth rendered texture as an exclusion list to draw the special exclusion list.

And finally draw the mesh above everything but the list.

Hello, just checking in, was your question answered? @ldogg

Hi @carolhmj unfortunately I couldn’t ever figure out to do exactly what I was asking. Even after trying @sebavan’s suggestions. As such I just assumed it wasn’t possible to achieve in babylon and went with an alternative approach entirely.

1 Like