Highlight occluded

Look at this example.
https://playground.babylonjs.com/#4AARMT

Overlapped balls also get highlights, which is incorrect.

Hey there, I took some time to give it a try myself. Taking a look at the documentation I think this could be the intention of how highlight layer works. I think this is because the highlight layer is being rendered on top. In your example I tried setting the mesh visibility to anything under 1. Take a look what I got.

Now I know this is not the desire so I took a look at another example. In the docs this example talked about excluding meshes
https://playground.babylonjs.com/#2FFOYQ#54

Even with the mesh alpha set to 1 you will still see the highlight bleed through excluded the highlight will still show through the sky box. Now I’m wondering if the work around for this is to use something with camera masks/layers. You can also add a black highlight to the sphere.

Hope this was helpful. In any case still feels like a bug so I will look into it further if this was the intention or not.

2 Likes

Thank you for your reply.This is amazing :joy:, maybe there is a bug somewhere, waiting for the author to fix it.

I agree with @msDestiny14 with this behavior being by design. The highlight layer seems to use the stencil buffer, and excluding a mesh from the layer will just exclude that specific mesh from the buffer. I can take a deeper look into the code if it’s needed. But one solution indeed would be to use layer masks to render each mesh to a separate stencil, so they don’t affect each other: HighlightLayer | Babylon.js Playground (babylonjs.com)

@kekeqy if the layer mask solution doesn’t work for your purposes, then the best approach would be to file a bug on the forum so that we can discuss and prioritize it.

2 Likes

@carolhmj It solved the ball highlight problem, but the ball obscured the highlight.

Is this what you want ?

1 Like

@musk It’s not what I want.

Do you want the intersection between ground and ball to be highlighted? If so, you just need to remove the addExcludedMesh line.
Babylon.js Playground (babylonjs.com)

1 Like

@carolhmj This was not the result I wanted, I needed to highlight the full outline of the ground.

1 Like

https://threejs.org/examples/webgl_postprocessing_outline.html
Similar to this example, regardless of occlusion, can show the full outline.

A work-around I’ve been using, that might work for you too until the bug(?) can be fixed, is to create a child clone with visibility 0.001 and renderingGroupId 1, which is used to render the highlight last. :slightly_smiling_face:
https://playground.babylonjs.com/#4AARMT#3

2 Likes

This is not a bug for me (cc @sebavan ) as the postprocess is working as expected.
That being said we could also include a mode where the occluded part of the overlay could be rendered with a different color

3 Likes

That would be good I think, if could set it to Color4(0, 0, 0, 0) to get rid of it. When adding an addExcludedMesh I expected the highlighted mesh to be highlighted exactly the same as it would be if the excluded mesh didn’t exist, that’s why it seemed like maybe a bug but maybe it’s just a wrong expectation. :slightly_smiling_face:

1 Like

Let’s have @sebavan do a check just in case :slight_smile:

2 Likes

Ooh, I just saw @msDestiny14’s post that all you have to do is set the excluded mesh’s visiblity to 0.99 to make it so that it doesn’t affect the highlight layer at all! :slightly_smiling_face: :beers:
https://playground.babylonjs.com/#4AARMT#5

I think the addExcludedMesh documentation is a little unclear thou, since it says that the excluded mesh wont impact the highlight layer but really the mesh’s visibility must be less than 1 for that to be true. IDK how to word that in the documentation thou or how to describe the effect when visibility is 1. :thinking:

2 Likes

Yup currently addExcludedMesh is only for transparentMeshes as they do not require depth information. I ll see if I can add a special mode for this but I can not promise anything for now :slight_smile:

4 Likes

@Deltakosh @sebavan @Blake Is there any progress ?

yup, I am not finding a consistent way to make it work at the moment. Still looking into it.

1 Like