Highlight through objects

Hello everyone,

I’m having a problem with highlighting object through other objects.
An example here :

https://www.babylonjs-playground.com/#2338DN

Basically I hoped to get an outline of the plane with the highlight and not half of the sphere red.
Any idea or advice to get that ?

Thanks,

https://www.babylonjs-playground.com/#2338DN#1

hl.outerGlow = false;

Does the trick

You should draw last (create last) the element to exclude to ensure that the stencil buffer is not erased by them: https://www.babylonjs-playground.com/#2338DN#2

1 Like

Thank you for your quick answer. It is exactly the result I want.

Quick questions then, any idea how to sort meshes’ Z.
The meshes are loaded dynamically in my example so loading then in order is not an option for me :confused:
I know it’s done automatically for transparency alpha blended materials, any way to apply it to opaque ones ?

You could use 2 rendering groups and then use setRenderingAutoClearDepthStencil to prevent any changes between groups:

https://www.babylonjs-playground.com/#2338DN#3

Would it work for 50+ objects ?

This can be pretty expensive but will depend on the objects complexity