Highlight layer colours in the whole mesh

When I use the highlight layer I end up with this:

I only want the outline to be highlighted. I found an old forum post about highlight layers here Babylon Highlight layer - Announcements - HTML5 Game Devs Forum and they mentioned using “stencil: true” when creating the engine. I’ve done that but my problem persists.

I’ve tried turning off inner glow. They doesn’t make any difference. However, when I turn off outerglow the highlight disappears altogether.

Anyone know what I might be doing wrong?

It looks like something in the scene breaks the stencil info (like cleaning them) before applying the result.

Could you share a link to your scene or repro in the playground ?

Hmm…it works perfectly fine in the playground (I don’t even need to mention stencil) so there must be something else in my code that’s breaking the stencil info


Can you share your example somewhere? Do you have many cameras or scenes that render simulteanously?

Ok, I’ve figured it out. You can see the problem here https://playground.babylonjs.com/#CG4CW0#7

This line “renderingGroupId = 1” breaks the highlight layer


here is a way to fix it:
https://playground.babylonjs.com/#CG4CW0#8 (line #26)

That solution killed my map marker :frowning:

I guess my problem is quite specific. I have 2 cameras. One is the main camera that fills up the screen. Another camera is for the mini-map (top-left of the screen). I’m using layer masks so the avatars don’t show up on the mini-map. There’s a map marker for each avatar instead. I’m using rendering group IDs so the map marker is always on top of everything else, even if the avatar walks into a house or under a tree.

When I apply the “scene.setRenderingAutoClearDepthStencil(1, false, true, false)” line it stops the rendering group ID from working and my map marker disappears

What about using two scenes then? It would let you have really independant renderings

so make the minimap a separate scene and render it on top of the other one? Does that mean I have to import the city twice, one for each scene?

yes but textures will be shared between scenes automatically

what about meshes? There is 3.58MB worth of mesh data. I’m worried about my draw calls if I have to duplicate all those meshes.

You are already duplicating the drawcalls as you are rendering twice already
The mesh data will be duplicated which is the only drawback here

Hmm…I think mini-maps like this are a bad idea. Too many draw calls. I’m going to try and pre-render to a texture instead. Then I won’t have to worry about rendergroup IDs either

yeah this is usually the way to do it in an efficient way

Thank you for the discussion. I’ve realised simply having a birds-eye view camera is not a good way of making a minimap.
I created a new project for internal use. It loads a city in a birds-eye view camera then exports render target to PNG and I just use that as the minimap in my other project. My cities are not dynamic so its fine if I use a fixed image throughout.
This also means I don’t have to worry about render group IDs since my avatar markers can just be positioned slightly above the minimap and it’ll always appear above. So now I can use highlight layer without any problems

1 Like