Highhight of object A is uncorrect if object A is behind object B and is created later than object B

Highhight of object A is correct if object A is behind object B and is created later than object B.

Howerver highhight of object A is correct if object A is behind object B and is created before object B.

Is there any way to solve this problem

It would be nice to have PG links as well, not only screenshots.

Yes, well, we had this problem before, didn’t we?

There are already a number of topics around this issue. It essentially comes from the rendering order and the fact that the hl is rendered at post-processing level (or just before, I’m not an expert).
I believe there is a way to fix it with layerMask and/or renderingGroupID but it’s not 100% satisfying (in my opinion). It quickly tends to create a mess in a complex scene.

I believe @Evgeni_Popov would be the best person here to answer this (if he’s not on vacation).

Else, you can still try your luck at browsing the forum threads for highlight layers (or glow layers) which basically act pretty much the same.

Given how the algorithm works, you won’t be able to get a circle as the highlight for your sphere if it is not displayed first.

You can achieve this either by using a renderingGroupId == 0 for objects that need to be highlighted and renderingGroupId > 0 for all other objects (https://playground.babylonjs.com/#PIPX1H#3) or use the uniqueId property of the mesh materials to sort them (since 5.0, meshes are by default sorted according to their material.uniqueId value).

You can also not exclude sphere2 from the layer and you will get the same output whatever the creation order of the meshes (but the highlight is not a circle anymore):

6 Likes

Thank you.

1 Like

Found new problem. Using renderingGroupId for objects that need to be highlighted and renderingGroupId > 0 for all other objects will conflict with transparent mesh. If mesh.visible = 0.5 and mesh is highlighed , the mesh will be completely transparent.



How to solve this problem?Or how to use the uniqueId property of the mesh materials to sort them (since 5.0, meshes are by default sorted according to their material.uniqueId value).

It seems to work in this PG:

?

2 Likes