Highlight Layer fills color when behind partially transparent meshes

When highlighted mesh is behind, or partially behind a transparent mesh,
the part which is behind the transparent mesh is filled with the HL color.

https://playground.babylonjs.com/#JWT721

HL_bug

In this case you should exclude the transparent plane from the highlight layer:

https://playground.babylonjs.com/#JWT721#1

image

It has always worked until 4.2.0, without having to do that :slight_smile:

Indeed, but there was a change in 4.2 in the stencil buffer handling that led to this change. I guess we should make it clearer in the “Breaking changes” section that it can affect the highlight layer, as for the time being it reads:

- Rendering of transparent meshes: stencil state is now set to the value
registered in the engine instead of being set to `false` unconditionally

That should make it clearer:

- Rendering of transparent meshes: stencil state is now set to the value
 registered in the engine instead of being set to `false` unconditionally.
 This change may affect the highlight layer when using transparent meshes. 
If you are impacted, you may need to exclude the transparent mesh(es) from the layer
1 Like

I’m not sure i fully understand,
to the value registered in the engine
but using Highlight layer,
the engine is created with stencil: true, so why would this be affected if it’s supposed to follow the engines settings?

The value registered with the engine is the one set when calling engine.setStencilBuffer(value). Will make it clear in the comment.

The value you pass to the engine when you create it is just a way to say you may use the stencil buffer in the future, but it is still disabled at start until you call engine.setStencilBuffer(true) at some point.

If you don’t want to exclude your mesh from the layer, you can do what the engine did before the correction, namely set the stencil buffer to false before drawing the transparent meshes:

https://playground.babylonjs.com/#JWT721#2

1 Like