# Highlight layer colours in the whole mesh

**URL:** <https://forum.babylonjs.com/t/highlight-layer-colours-in-the-whole-mesh/1049>\
**Category:** Questions\
**Created:** [January 29, 2019, 11:41pm UTC](https://forum.babylonjs.com/t/highlight-layer-colours-in-the-whole-mesh/1049 "2019-01-29T23:41:06Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)\
**Post date:** [January 29, 2019, 11:41pm UTC](https://forum.babylonjs.com/t/highlight-layer-colours-in-the-whole-mesh/1049/1 "2019-01-29T23:41:06Z")

</div>

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

 ![highlighted](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/1X/73ba6687338211e19e7021e7ee86ca208920341f.jpeg)

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](http://www.html5gamedevs.com/topic/25503-babylon-highlight-layer/) 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?

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [January 30, 2019, 11:44am UTC](https://forum.babylonjs.com/t/highlight-layer-colours-in-the-whole-mesh/1049/2 "2019-01-30T11:44:22Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)\
**Post date:** [January 30, 2019, 1:04pm UTC](https://forum.babylonjs.com/t/highlight-layer-colours-in-the-whole-mesh/1049/3 "2019-01-30T13:04:03Z")

</div>

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

[https://playground.babylonjs.com/#CG4CW0#2](https://playground.babylonjs.com/#CG4CW0#2)

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [January 30, 2019, 4:01pm UTC](https://forum.babylonjs.com/t/highlight-layer-colours-in-the-whole-mesh/1049/4 "2019-01-30T16:01:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)\
**Post date:** [January 31, 2019, 1:05am UTC](https://forum.babylonjs.com/t/highlight-layer-colours-in-the-whole-mesh/1049/6 "2019-01-31T01:05:26Z")

</div>

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

This line “renderingGroupId = 1” breaks the highlight layer

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [January 31, 2019, 3:20pm UTC](https://forum.babylonjs.com/t/highlight-layer-colours-in-the-whole-mesh/1049/7 "2019-01-31T15:20:53Z")

</div>

yes!

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

---

<div class="post-metadata">

**Author:** ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)\
**Post date:** [February 1, 2019, 12:09am UTC](https://forum.babylonjs.com/t/highlight-layer-colours-in-the-whole-mesh/1049/8 "2019-02-01T00:09:01Z")

</div>

That solution killed my map marker ☹

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.

 ![map_marker](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/1X/d670f897c4b7a09de14bdd3f64b2bfeffe637552.jpeg)  
When I apply the “scene.setRenderingAutoClearDepthStencil(1, false, true, false)” line it stops the rendering group ID from working and my map marker disappears

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [February 1, 2019, 12:25am UTC](https://forum.babylonjs.com/t/highlight-layer-colours-in-the-whole-mesh/1049/9 "2019-02-01T00:25:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)\
**Post date:** [February 1, 2019, 12:32am UTC](https://forum.babylonjs.com/t/highlight-layer-colours-in-the-whole-mesh/1049/10 "2019-02-01T00:32:27Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [February 1, 2019, 12:33am UTC](https://forum.babylonjs.com/t/highlight-layer-colours-in-the-whole-mesh/1049/11 "2019-02-01T00:33:09Z")

</div>

yes but textures will be shared between scenes automatically

---

<div class="post-metadata">

**Author:** ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)\
**Post date:** [February 1, 2019, 12:35am UTC](https://forum.babylonjs.com/t/highlight-layer-colours-in-the-whole-mesh/1049/12 "2019-02-01T00:35:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [February 1, 2019, 4:36pm UTC](https://forum.babylonjs.com/t/highlight-layer-colours-in-the-whole-mesh/1049/13 "2019-02-01T16:36:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)\
**Post date:** [February 1, 2019, 11:24pm UTC](https://forum.babylonjs.com/t/highlight-layer-colours-in-the-whole-mesh/1049/14 "2019-02-01T23:24:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [February 1, 2019, 11:36pm UTC](https://forum.babylonjs.com/t/highlight-layer-colours-in-the-whole-mesh/1049/15 "2019-02-01T23:36:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)\
**Post date:** [February 3, 2019, 5:21am UTC](https://forum.babylonjs.com/t/highlight-layer-colours-in-the-whole-mesh/1049/16 "2019-02-03T05:21:22Z")

</div>

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
