Highlight layer issues with excluded meshes

Hey everybody!
I have an issue with highlight layer which seems like a bug to me.

Highlight a mesh without taking into account other meshes overlapping it.

Add only the required mesh to the highlight layer. Exclude all other meshes from this layer.

The overlapping meshes still affect the highlighted mesh sometimes. This is related to the meshes draw order.

Here is a PG to reproduce. Just click the ground.

Do you think it is a bug? I feel like so, cause the description of the used APIs implies this shouldn’t be the case.

1 Like

We’ve had a discussion about this a while ago: Highlight occluded - Questions - Babylon.js (babylonjs.com)

@sebavan is looking into making the behavior more consistent with users’ expectations, but for now there are some workarounds in the topic.


Thanks a ton!
I was looking for similar topics but didn’t find this one. Glad to hear this is a known thing and there is already some progress being made!


not really any progress per se cause the system is not designed for this so I am trying to figure a way to handle it but there is not mush I can find at the moment.


I see.
Thanks for the clarification. In the mentioned thread @carolhmj proposed to draw only required meshes to a separate stencil buffer/mask which seems to me like a reasonable solution. This is what you mean to be not that easily achievable by design, right?

This is a bit more complex as the stencil op would need to draw the mask where depth test is failing on the main canvas as well and some of the depth comparisons were wrong after that in my early tests.

Right. I was thinking of a solution with a separate depth buffer. In one of my prev projects we used to do highlighting this way. I guess you would consider this too much of a performance hit.
Thanks for the explanation! Really hope you will figure out how to make it work in some not so distant future :slightly_smiling_face: