# Rendering groups messing up highlight layers and 3D GUI

**URL:** <https://forum.babylonjs.com/t/rendering-groups-messing-up-highlight-layers-and-3d-gui/28224>\
**Category:** Bugs\
**Tags:** prepassrenderer\
**Created:** [March 8, 2022, 7:03am UTC](https://forum.babylonjs.com/t/rendering-groups-messing-up-highlight-layers-and-3d-gui/28224 "2022-03-08T07:03:18Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jetavut](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jetavut](https://forum.babylonjs.com/u/jetavut)\
**Post date:** [March 8, 2022, 7:03am UTC](https://forum.babylonjs.com/t/rendering-groups-messing-up-highlight-layers-and-3d-gui/28224/1 "2022-03-08T07:03:19Z")

</div>

I have a mesh that I want to render on top of other meshes.  
I also use highlight layers and a 3D GUI.

When the mesh rendering group is modified, the highlight layer get messed up and the 3D GUI get rendered on top of all the other elements: [https://playground.babylonjs.com/#R069YG#3](https://playground.babylonjs.com/#R069YG#3)  
Also, if the rendering group is set back to 0 the issues still persist.

Is there a way to fix this? The [documentation mentions](https://doc.babylonjs.com/divingDeeper/mesh/highlightLayer#rendering-groups) that highlights requires stencil and depth info but I don’t see how to fix this.

---

<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:** [March 8, 2022, 9:36am UTC](https://forum.babylonjs.com/t/rendering-groups-messing-up-highlight-layers-and-3d-gui/28224/2 "2022-03-08T09:36:18Z")

</div>

You can force a rendering group id in the highlight layer options: [https://playground.babylonjs.com/#R069YG#4](https://playground.babylonjs.com/#R069YG#4)

This will unblock your second case

---

<div class="post-metadata">

**Author:** ![jetavut](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jetavut](https://forum.babylonjs.com/u/jetavut)\
**Post date:** [March 9, 2022, 2:34am UTC](https://forum.babylonjs.com/t/rendering-groups-messing-up-highlight-layers-and-3d-gui/28224/3 "2022-03-09T02:34:40Z")

</div>

Thank you! It fixes the highlight layer issue.

I still have the 3D GUI being suddenly rendered on top of the rest and I don’t see how to fix it, though.

---

<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:** [March 9, 2022, 3:47pm UTC](https://forum.babylonjs.com/t/rendering-groups-messing-up-highlight-layers-and-3d-gui/28224/4 "2022-03-09T15:47:20Z")

</div>

But this is the entire point of the rendering group here, if you do not want it to render after why changing its group ? I am not sure to fully understand what you expect to happen ?

---

<div class="post-metadata">

**Author:** ![jetavut](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jetavut](https://forum.babylonjs.com/u/jetavut)\
**Post date:** [March 10, 2022, 12:21am UTC](https://forum.babylonjs.com/t/rendering-groups-messing-up-highlight-layers-and-3d-gui/28224/5 "2022-03-10T00:21:33Z")

</div>

I might not having being clear enough, sorry.

As you can see [here](https://playground.babylonjs.com/#R069YG#5), when I set the sphere on the right to be rendered on top of the box, the 3D GUI get also rendered on top of the other meshes, which is not intended.  
Even reverting the sphere’s `renderingGroupId` to 0 doesn’t fix the 3D GUI being rendered on top.

---

<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:** [March 10, 2022, 1:14am UTC](https://forum.babylonjs.com/t/rendering-groups-messing-up-highlight-layers-and-3d-gui/28224/6 "2022-03-10T01:14:00Z")

</div>

I see what you mean but unfortunately you would need to rely on a separate scene for this ☹

Basically, the controls are rendered after the full scene has been drawn but here we are clearing the depth information before rendering the sphere so it can replace the box. Which means that when we render the controls there is nothing else than the sphere in the canvas for them.

It would require quite some changes to allow interleaving utility layer and rendering group. May I ask why you would like to do this ? I am wondering if there are any other options ?

---

<div class="post-metadata">

**Author:** ![jetavut](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jetavut](https://forum.babylonjs.com/u/jetavut)\
**Post date:** [March 11, 2022, 4:26am UTC](https://forum.babylonjs.com/t/rendering-groups-messing-up-highlight-layers-and-3d-gui/28224/7 "2022-03-11T04:26:30Z")

</div>

> May I ask why you would like to do this ?

I have a scene with a 3D GUI. I can also switch the camera to have an overhead view in which the 3D GUI isn’t necessary but a mesh needs to be rendered on top.

So the mesh on top and the 3D GUI are never used at the same time.

&nbsp;

However if `renderingGroupId` is altered, even if it’s reverted back to its original value, the 3D GUI (even if created afterwards) will be always rendered on top.  
See [this playground](https://playground.babylonjs.com/#R069YG#7).

---

<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:** [March 11, 2022, 9:30pm UTC](https://forum.babylonjs.com/t/rendering-groups-messing-up-highlight-layers-and-3d-gui/28224/8 "2022-03-11T21:30:44Z")

</div>

Ok got it, yes this seems like a bug to me I ll push a fix soon

---

<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:** [March 11, 2022, 9:30pm UTC](https://forum.babylonjs.com/t/rendering-groups-messing-up-highlight-layers-and-3d-gui/28224/9 "2022-03-11T21:30:47Z")

</div>

Assigned @sebavan on March 11, 2022, 9:30pm UTC



---

<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:** [March 14, 2022, 2:37pm UTC](https://forum.babylonjs.com/t/rendering-groups-messing-up-highlight-layers-and-3d-gui/28224/10 "2022-03-14T14:37:37Z")

</div>

Unassigned @sebavan on March 14, 2022, 2:37pm UTC



---

<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:** [March 14, 2022, 2:37pm UTC](https://forum.babylonjs.com/t/rendering-groups-messing-up-highlight-layers-and-3d-gui/28224/11 "2022-03-14T14:37:45Z")

</div>

Will be fixed by [fix empty rendering group side effects by sebavan · Pull Request #12159 · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/pull/12159)

---

<div class="post-metadata">

**Author:** ![jetavut](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jetavut](https://forum.babylonjs.com/u/jetavut)\
**Post date:** [March 15, 2022, 12:12am UTC](https://forum.babylonjs.com/t/rendering-groups-messing-up-highlight-layers-and-3d-gui/28224/12 "2022-03-15T00:12:53Z")

</div>

Thank you a lot!
