# Slice doesn't hide the edges (part deux)

**URL:** <https://forum.babylonjs.com/t/slice-doesnt-hide-the-edges-part-deux/34081>\
**Category:** Bugs\
**Created:** [September 20, 2022, 5:42pm UTC](https://forum.babylonjs.com/t/slice-doesnt-hide-the-edges-part-deux/34081 "2022-09-20T17:42:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anton](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/anton/32/4310_2.png) [@Anton](https://forum.babylonjs.com/u/Anton)\
**Post date:** [September 20, 2022, 5:42pm UTC](https://forum.babylonjs.com/t/slice-doesnt-hide-the-edges-part-deux/34081/1 "2022-09-20T17:42:07Z")

</div>

Hello everyone,

This question/bug report is going to be a continuation of this topic: [Slice doesn't hide the Edges](https://forum.babylonjs.com/t/slice-doesnt-hide-the-edges/14910)

@Evgeni_Popov’s [fix](https://forum.babylonjs.com/t/slice-doesnt-hide-the-edges/14910/8) works if clip plane is set at the scene level globally for all the meshes:

> **[Babylon.js Playground](https://playground.babylonjs.com/#Y6W087%23248)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

But if you want to use per-mesh clip planes (as explained [here](https://doc.babylonjs.com/divingDeeper/scene/clipPlanes)) it stops working:

> **[Babylon.js Playground](https://playground.babylonjs.com/#Y6W087%23253)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Neither of the possible values for `edgesRenderer.lineShader.options.useClipPlane` makes a difference.

If this is truly a bug - can/will this be addressed and fixed?

Thank you!  
Anton.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [September 20, 2022, 6:29pm UTC](https://forum.babylonjs.com/t/slice-doesnt-hide-the-edges-part-deux/34081/2 "2022-09-20T18:29:29Z")

</div>

The edge rendering is a separate step from the mesh rendering, so the mesh events like `onBeforeRenderObservable` / `onAfterRenderObservable` won’t work for it.

What you can do is hooking the `EdgesRenderer.render` function to set/unset the scene clipping planes:

> **[Babylon.js Playground](https://playground.babylonjs.com/#Y6W087%23254)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

@sebavan / @Deltakosh I wonder if we should add some observers like `onBeforeRendering` / `onAfterRendering` in the edge renderer… Also, what about adding clipping plane support to the `Material` class in addition to the `scene.clippingPlaneX` properties? We would avoid the use of `mesh.onBeforeRenderObservable` / `mesh.onAfterRenderObservable` to set clip planes and we could also reuse the data in the edge renderer to apply the same clipping planes if defined at the material level.

---

<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:** [September 20, 2022, 6:33pm UTC](https://forum.babylonjs.com/t/slice-doesnt-hide-the-edges-part-deux/34081/3 "2022-09-20T18:33:30Z")

</div>

I like the idea! (of adding clipping planes to material class)

---

<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:** [September 20, 2022, 6:36pm UTC](https://forum.babylonjs.com/t/slice-doesnt-hide-the-edges-part-deux/34081/4 "2022-09-20T18:36:12Z")

</div>

I am not a fan of anything requiring onBefore/onAfter as it breaks WebGPU perf compat. ClipPlanes at the material levels sounds really coool

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [September 20, 2022, 10:20pm UTC](https://forum.babylonjs.com/t/slice-doesnt-hide-the-edges-part-deux/34081/5 "2022-09-20T22:20:54Z")

</div>

Issue created:

> <https://github.com/BabylonJS/Babylon.js/issues/13002>
>
> Currently, clip planes are defined at the scene level, but it is sub-optimal bec…ause if we want some per-mesh clip planes we must use the \`mesh.onBeforeRenderObservable\` / \`mesh.onAfterRenderObservable\` events on each mesh.
> 
> It is also more cumbersome for the user than having the possibility to set the clip planes directly in the material.

---

<div class="post-metadata">

**Author:** ![Anton](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/anton/32/4310_2.png) [@Anton](https://forum.babylonjs.com/u/Anton)\
**Post date:** [September 20, 2022, 11:09pm UTC](https://forum.babylonjs.com/t/slice-doesnt-hide-the-edges-part-deux/34081/6 "2022-09-20T23:09:44Z")

</div>

You guys rock, thank you!  
Will use the suggested workaround for now, but looking forward to this being implemented in the future!
