# Issue with custom shapes rendering

**URL:** <https://forum.babylonjs.com/t/issue-with-custom-shapes-rendering/8580>\
**Category:** Bugs\
**Created:** [February 14, 2020, 2:39pm UTC](https://forum.babylonjs.com/t/issue-with-custom-shapes-rendering/8580 "2020-02-14T14:39:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seba](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Seba](https://forum.babylonjs.com/u/Seba)\
**Post date:** [February 14, 2020, 2:39pm UTC](https://forum.babylonjs.com/t/issue-with-custom-shapes-rendering/8580/1 "2020-02-14T14:39:12Z")

</div>

Hello Babylon community,

I run into an issue with rendering custom shapes, some faces in the back are drawn in front of the faces which are closer from the camera.  
I can fix this issue by adding a material and set the property “needDepthPrePass” to true but this cause some serious drop down on FPS side.  
Or by set the mesh property “hasVertexAlpha” to false with does not affect the FPS but in my case I need to set it to true.

Here we can see the issue:  
 ![2020-02-14_issue_2](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/2/29c901787c9b91e3e42e69952f060b5d97cfe972.jpeg)  
 ![2020-02-14_issue](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/8/88fea5c4c7c3ed69cbf6c3993ddf26363b534d1b.jpeg)

Here we can see a proper rendering with “hasVertexAlpha” set to false:  
 ![2020-02-14_render](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/a/a4e672c2bb3d7d7500aa253a59d0773a0429c0da.jpeg)

And here you can find a playground that reproduce the issue  
[https://playground.babylonjs.com/#NXRT8H](https://playground.babylonjs.com/#NXRT8H)

PS: to see the rendering as I expect, set:

- “mat1.needDepthPrePass = false;” to true (line 21)
- or “shapeInScene.hasVertexAlpha = true” to false (line 57)

---

<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:** [February 14, 2020, 3:41pm UTC](https://forum.babylonjs.com/t/issue-with-custom-shapes-rendering/8580/2 "2020-02-14T15:41:26Z")

</div>

That’s the same problem than here: [Have only certain meshes visibile through transparency?](https://forum.babylonjs.com/t/have-only-certain-meshes-visibile-through-transparency/8551)

Why not using a material without alpha for the pieces that don’t need transparency?

[https://playground.babylonjs.com/#NXRT8H#1](https://playground.babylonjs.com/#NXRT8H#1)

Alternatively, instead of enduring the penalty for `needDepthPrePass = true` you can simply set `mat1.forceDepthWrite = true`:

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

---

<div class="post-metadata">

**Author:** ![Seba](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Seba](https://forum.babylonjs.com/u/Seba)\
**Post date:** [February 14, 2020, 4:23pm UTC](https://forum.babylonjs.com/t/issue-with-custom-shapes-rendering/8580/3 "2020-02-14T16:23:46Z")

</div>

Yes, thank you for the fast and good answer and sorry for the duplicate.  
Set the property `forceDepthWrite` to true has solved my problem.  
But I have an other issue, a bit of context first:  
For this project I need to add transparency either on a part of the shape or on its entirety, that’s why I set the color this way:  
`shapeInScene.setVerticesData(BABYLON.VertexBuffer.ColorKind, colors, true);`  
And a shape can have an other shape inside and in this situation I got an overlapping (I believe that’s the name, I’m not sure)  
Not easy to explain but when I have a shape with transparency (alpha \>0 && \<1) with an invible shape inside (alpha=0) I have this issue.  
Picture of my problem:  
 ![2020-02-14_overlapping](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/2/2aad9efbf0ba0b222f48cb8ea3fc0f71e1027d8b.jpeg)

In blue the shape supposed to be totally transparent like above:  
 ![2020-02-14_overlapping_2](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/a/afb0f94b340d78c6a77c7247ab19ea9a865a538b.jpeg)

So when the blue shape is not fully invisible (alpha \> 0) I can understand that the engine doesn’t really know which one to draw first because the shapes have the same position and size but when alpha is set to 0 it seems that the engine still try to draw it right? But it shouldn’t do that?

[playground](https://playground.babylonjs.com/#NXRT8H#3)
