The result of the highlight layer does depend on the order on which the meshes are rendered, at least when adding excluded meshes to the picture.
When moving the creation of the material in the 2nd PG you are modifying the uniqueId
of this material, which is now greater than the uniqueId
of the sphere material. Because Babylon.js is sorting the meshes based on their material, the sphere is now rendered before the ground, which leads to the display you can see because we are using the stencil buffer as part of the highlight layer processing, and when the ground is drawn after the sphere the stencil buffer is not updated at the sphere location (because the sphere is excluded from the layer).
cc @sebavan, but I think it’s a side-effect of the technique we use which is unavoidable.
No, there should be no impact. According to my explanations above, you should make sure the excluded meshes are displayed after all the included meshes (using renderingGroupId=1
for all excluded meshes, for eg) to get the right display.