# Difference in Rendering Transparent Materials When DepthPrePass is Toggled Through Inspector

**URL:** <https://forum.babylonjs.com/t/difference-in-rendering-transparent-materials-when-depthprepass-is-toggled-through-inspector/61084>\
**Category:** Questions\
**Created:** [October 21, 2025, 10:04pm UTC](https://forum.babylonjs.com/t/difference-in-rendering-transparent-materials-when-depthprepass-is-toggled-through-inspector/61084 "2025-10-21T22:04:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [October 21, 2025, 10:04pm UTC](https://forum.babylonjs.com/t/difference-in-rendering-transparent-materials-when-depthprepass-is-toggled-through-inspector/61084/1 "2025-10-21T22:04:19Z")

</div>

Im really kind of stumped by some behavior that we are seeing with transparent materials. The behavior changes depending on when I toggle the depth pre pass or have frozen the material.

First, if I do no depth pre pass and no freeze it sorts incorrectly which is expected:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/b/0/b0a2a12f9dc7b34d455385c1655ab9deb43978f8.png)

But then if I set them to do the depth pre pass it clears out transparent materials that are behind it:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/c/a/ca5ee404e73c341a572d12997027c11db9e986d7.png)

But then if I freeze the material with the depth pre pass everything sorts correctly buuuut then some of the icons then appear as a black box (not all the black box in the second image is a transparent typing indicator):

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/b/3/b3ddb367422820c69706e32c7e902f1c534b4235.png)

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/8/b/8b34341c0da63696eaf80098d347cece63b2e4a9.png)

Finally which really makes me scratch my head is if I leave the materials as frozen but then take off in code the depth pre pass, fire up the inspector and on the materials through the inspector say they need a depth pass everything renders correctly.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/1/c/1c58c08e6659a13d16a08d2bc63ea7c75387627e.png)

Im not really sure why this is happening, I’ve tried to toggle the pre pass later in the code at the time of showing the indicator but that did not work as well and just does the black box.

Is there something that Im missing here?

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/f/1/f15a62c87f4f2a5cff08fd464884afa01a8448ff.png)

We have tried a bunch of different setup and its either they don’t sort correct, clear out the transparencies behind them or render as a black box so I’m fairly confused now.

---

<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:** [October 22, 2025, 7:41am UTC](https://forum.babylonjs.com/t/difference-in-rendering-transparent-materials-when-depthprepass-is-toggled-through-inspector/61084/2 "2025-10-22T07:41:39Z")

</div>

I believe all your transparent objects are always facing the camera (billboards)? If so, sorting them should work (use the mesh `alphaIndex` property for this). Also, if you can set up a reproduction in the Playground, it will help us investigate the issue.

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [October 22, 2025, 2:41pm UTC](https://forum.babylonjs.com/t/difference-in-rendering-transparent-materials-when-depthprepass-is-toggled-through-inspector/61084/3 "2025-10-22T14:41:36Z")

</div>

Roger that. Let me see what I can do!

**UPDATE** well it looks like the behavior is specific to our setup. I’m wondering if it has to do something with us having duel camera.

> **[Babylon.js Playground](https://playground.babylonjs.com/?inspectorv2=true#1884L7)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL and WebGPU 3D scenes

In the playground they render correct and I can never get them to do what they do in our setup even with the same properties so there is something else I’m not seeing that is causing it.

@Evgeni_Popov could it be related to the fact we have a First Person Camera (universal camera) and a Third Person Camera (ArcRotate) with the Third Person Camera a child of the first person and the activeCameras list being [ThirdPerson, FirstPerson]? It almost feels like its getting the depth values from the First Person camera but using them with the Third Person.

What I have also noticed that in our setup the orientation of the camera matters, where it will sort behind an object when looking one direction at a certain distance but then if I look the opposite and go to the same distance it will sort in front. This is really making me scratch my head.

I also cant get the playground to ever do this:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/c/a/ca5ee404e73c341a572d12997027c11db9e986d7.png)

If I can solve for that at the very least then I think things would be working!

**SECOND UPDATE**  
I added the dual camera setup and still cant get the same behavior, this is actually kind of nuts.

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [October 22, 2025, 9:21pm UTC](https://forum.babylonjs.com/t/difference-in-rendering-transparent-materials-when-depthprepass-is-toggled-through-inspector/61084/4 "2025-10-22T21:21:56Z")

</div>

Oooo oo I figured it out!

So all the problems with the clipping/sorting happen depending on the billboard planes orientation!

This might actually be a bug!

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/6/1/6107161ca76c57dc409d90cc2796adcc992ba7d0.png)

So if you walk forward with “W” and then get past the plane you can look backwards and recreate all the problems we are seeing in our environment!

> **[Babylon.js Playground](https://playground.babylonjs.com/?inspectorv2=true#1884L7%237)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL and WebGPU 3D scenes

If you have the pre pass enabled you get the clipping/discard glitch, and if you have it disabled you get the sorting glitch!

---

<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:** [October 23, 2025, 9:38am UTC](https://forum.babylonjs.com/t/difference-in-rendering-transparent-materials-when-depthprepass-is-toggled-through-inspector/61084/5 "2025-10-23T09:38:54Z")

</div>

The problem is that transparent meshes are instances, and sorting transparent instances does not work as expected because sorting is performed on the CPU side only with the master mesh, not with the instances. In your example, the two icon meshes that are sorted with the background are the `_basis` meshes, and since these meshes do not move, depending on the camera position, the sorting is incorrect.

One solution is to use clones instead of instances, but this is less efficient if you have a lot of transparent meshes:

> **[Babylon.js Playground](https://playground.babylonjs.com/#1884L7%238)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL and WebGPU 3D scenes

Note that `icon.doNotSyncBoundingInfo = true` must be commented out, because the sorting step uses the center of the mesh’s bounding sphere.

OIT also works (`scene.useOrderIndependentTransparency = true;`) but this option can also affect performance.

Unfortunately, I don’t see any other solution…

We plan to look into a better way of managing transparent meshes, one that performs better than OIT. But I can’t give you a specific date.

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [October 23, 2025, 3:16pm UTC](https://forum.babylonjs.com/t/difference-in-rendering-transparent-materials-when-depthprepass-is-toggled-through-inspector/61084/6 "2025-10-23T15:16:32Z")

</div>

Yeah we can not use clones, dang this sucks. So basically we are out of luck then? ☹ We had tested those other suggestions in the past and it created more problems then it fixed unfortunately.

I appreciate that you looked into this for me, thank you.

---

<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:** [October 23, 2025, 4:39pm UTC](https://forum.babylonjs.com/t/difference-in-rendering-transparent-materials-when-depthprepass-is-toggled-through-inspector/61084/7 "2025-10-23T16:39:48Z")

</div>

Maybe you can try to implement weighted & blended OIT and see if it works in your case:

> **[Implementing Weighted, Blended Order-Independent Transparency](https://casual-effects.blogspot.com/2015/03/implemented-weighted-blended-order.html)**
>
> Why Transparency? Result from the Weighted, Blended OIT method described in this article. Everything gray in the top inset image ha...

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [October 23, 2025, 5:17pm UTC](https://forum.babylonjs.com/t/difference-in-rendering-transparent-materials-when-depthprepass-is-toggled-through-inspector/61084/8 "2025-10-23T17:17:39Z")

</div>

> **[Babylon.js Playground](https://playground.babylonjs.com/?inspectorv2=true#1884L7%2310)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL and WebGPU 3D scenes

So odd enough, if we turn off the pre pass and set the alpha mode to just alpha test none of the sorting or discard glitches happen. What would be the difference between having the blending and just test that allows this to work correctly?

At least with this we can keep our instances, they are just a little more aliased but that is fine!

---

<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:** [October 23, 2025, 6:52pm UTC](https://forum.babylonjs.com/t/difference-in-rendering-transparent-materials-when-depthprepass-is-toggled-through-inspector/61084/9 "2025-10-23T18:52:30Z")

</div>

> [@Pryme8](#):
>
> What would be the difference between having the blending and just test that allows this to work correctly?

That’s because alpha tested only materials are not transparent materials, so they work the same as opaque materials, the difference being that if alpha for a pixel is less than a threshold value, the pixel is discarded and not updated.

It’s the easiest fix, if you don’t need transparency for your icons!

---

<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:** [October 23, 2025, 7:13pm UTC](https://forum.babylonjs.com/t/difference-in-rendering-transparent-materials-when-depthprepass-is-toggled-through-inspector/61084/10 "2025-10-23T19:13:10Z")

</div>

Note that you can make it work with alpha testing + blending by forcing depth write for the icon materials:

> **[Babylon.js Playground](https://playground.babylonjs.com/#1884L7%2312)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL and WebGPU 3D scenes

That way, you can set an `alphaMode` and try to improve on the anti-aliasing problem.
