# Depth sensing standard material rendering bug

**URL:** <https://forum.babylonjs.com/t/depth-sensing-standard-material-rendering-bug/59847>\
**Category:** Bugs\
**Tags:** webxr, depth\
**Created:** [July 31, 2025, 2:17pm UTC](https://forum.babylonjs.com/t/depth-sensing-standard-material-rendering-bug/59847 "2025-07-31T14:17:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wellandr](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wellandr/32/19572_2.png) [@Wellandr](https://forum.babylonjs.com/u/Wellandr)\
**Post date:** [July 31, 2025, 2:17pm UTC](https://forum.babylonjs.com/t/depth-sensing-standard-material-rendering-bug/59847/1 "2025-07-31T14:17:14Z")

</div>

Hello guys,

While playing around with the Augmented reality features of babylonjs, I stumbled upon a bug where some items would get occluded by the depth sensing feature, while others wont. And so for no apparent reason.

Here is a code sandbox reproducing the error and a screen cap : [https://playground.babylonjs.com/#KDWCZY#619](https://playground.babylonjs.com/#KDWCZY#619 "https://playground.babylonjs.com/#KDWCZY#619")

 ![Screenshot_20250731_160341_Chrome](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/8/a/8ac9d8c7175498ed8f0f9170d819ae9486f09fe0.jpeg)

In this picture, the skeleton is a default mesh with no particular material. The cube have the standard material.

And here, same code sample but with the standard material commented out, you get this : [https://playground.babylonjs.com/#KDWCZY#620](https://playground.babylonjs.com/#KDWCZY#620)

 ![Screenshot_20250731_161321_Chrome](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/e/3ef401075182bec0d225916df26671b7426e04e1.jpeg)

What could be done to work around that ?

Tested on : Samsung s22, Chrome 138, android 15

---

<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:** [July 31, 2025, 4:16pm UTC](https://forum.babylonjs.com/t/depth-sensing-standard-material-rendering-bug/59847/2 "2025-07-31T16:16:36Z")

</div>

cc @docEdub

---

<div class="post-metadata">

**Author:** ![docEdub](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/docedub/32/14525_2.png) [@docEdub](https://forum.babylonjs.com/u/docEdub)\
**Post date:** [August 1, 2025, 4:20am UTC](https://forum.babylonjs.com/t/depth-sensing-standard-material-rendering-bug/59847/3 "2025-08-01T04:20:13Z")

</div>

I repro this on my Quest 3. Investigating now.

---

<div class="post-metadata">

**Author:** ![docEdub](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/docedub/32/14525_2.png) [@docEdub](https://forum.babylonjs.com/u/docEdub)\
**Post date:** [August 1, 2025, 7:56am UTC](https://forum.babylonjs.com/t/depth-sensing-standard-material-rendering-bug/59847/4 "2025-08-01T07:56:11Z")

</div>

tl;dr Move the material creation outside the `onAnchorAddedObservable` callback.

* * *

The WebXR `onAnchorAddedObservable` callback is called from the render loop, so creating a material there is unexpected.

Moving the material creation out of the callback/render-loop gets depth occlusion working for it:

[https://playground.babylonjs.com/#KDWCZY#622](https://playground.babylonjs.com/#KDWCZY#622)

---

<div class="post-metadata">

**Author:** ![Wellandr](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wellandr/32/19572_2.png) [@Wellandr](https://forum.babylonjs.com/u/Wellandr)\
**Post date:** [August 1, 2025, 8:55am UTC](https://forum.babylonjs.com/t/depth-sensing-standard-material-rendering-bug/59847/5 "2025-08-01T08:55:12Z")

</div>

Thank you @docEdub for your explanation and @Deltakosh for the ping !

I was able to reproduce your fix on my original [project](https://github.com/arthurmougin/figma-xr/commit/886f8f0217a940bab32985381dda222f07c7c4a0#diff-353c882b105eff4d6232495323a6b2e112503798495cb73d61a1b7e6a4d4cf63L111) 💪  
In my case, the generation of the material was not in a `onAnchorAddedObservable` callback, but in a function called on user interact.

We can close the ticket, but for the record :  
Could it be that any material created after the initialization of the `WebXRDepthSensing` or after the entering of the XR session are not taken into account for occlusion ?
