# Tweaking material in Sandbox in order to be occlusive yet invisible

**URL:** <https://forum.babylonjs.com/t/tweaking-material-in-sandbox-in-order-to-be-occlusive-yet-invisible/9822>\
**Category:** Questions\
**Tags:** material, shader\
**Created:** [April 8, 2020, 2:54pm UTC](https://forum.babylonjs.com/t/tweaking-material-in-sandbox-in-order-to-be-occlusive-yet-invisible/9822 "2020-04-08T14:54:54Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![paleRider](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/palerider/32/7774_2.png) [@paleRider](https://forum.babylonjs.com/u/paleRider)\
**Post date:** [April 8, 2020, 2:54pm UTC](https://forum.babylonjs.com/t/tweaking-material-in-sandbox-in-order-to-be-occlusive-yet-invisible/9822/1 "2020-04-08T14:54:54Z")

</div>

Hi there, good people of this forum:

I wonder if it’s possible to tweak a material in a GLTF/GLB file, by means of Sandbox controls, in order to have an occlusive material. I want it to be applied to helper geometries that are not shown but occlude the objects behind them.

As an example I want that, while not being shown, the boxes occlude the orbiting objects:

![ezgif.com-crop](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/c/cefcf5b0c3c71ed2bce9ace172256881fb26f27c.gif)

In different render engines forums I’ve read about setting:

1. “shadingModel” to unlit,
2. “colorWrite” to false,
3. and “depthWrite” to true

…but these are parameters that I can’t find in Sandbox GUI, although I think are available through WebGL.

Thanks for your time.

---

<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:** [April 8, 2020, 3:07pm UTC](https://forum.babylonjs.com/t/tweaking-material-in-sandbox-in-order-to-be-occlusive-yet-invisible/9822/2 "2020-04-08T15:07:48Z")

</div>

Hey! and welcome back!

1. ShadingModel to unlit: Set material.disableLighting = true
2. DepthWrite is on by default

2 cannot directly be done from the inspector but you can do it with mesh.onBeforeDrawObservable / mesh.onAfdterDrawObservable and call engine.setColorWrite(true / false)

If you have a good use case I could add it as a property of a material

---

<div class="post-metadata">

**Author:** ![paleRider](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/palerider/32/7774_2.png) [@paleRider](https://forum.babylonjs.com/u/paleRider)\
**Post date:** [April 8, 2020, 5:16pm UTC](https://forum.babylonjs.com/t/tweaking-material-in-sandbox-in-order-to-be-occlusive-yet-invisible/9822/3 "2020-04-08T17:16:40Z")

</div>

Hi there **Deltakosh** , and thank you for such an immediate response.

From your answer may I understand that, in order to have an occlusive-invisible material, that three parameters: shading model, color write (aka color mask) and depth write must be set as proposed?  
I mentioned them here only because It’s the way to go within Google’s Filament Rendering Engine.

About the case of use, is of course in AR applications where we like to add an extra of immersion with occlusion of real elements in a nearer position from the camera.

At the moment we’ve using ARCore/Sceneform/Filament technologies for AR apps development with very good results. By the way Sceneform is now OpenSource. The web spin-off project of ARCore, namely [model-viewer](https://github.com/google/model-viewer) web component is using at the moment three.js, but they hope to include more facades (BJS by example) in the future by means of their [3DOM library](https://github.com/google/model-viewer/tree/master/packages/3dom).

Best regards.

---

<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:** [April 8, 2020, 5:57pm UTC](https://forum.babylonjs.com/t/tweaking-material-in-sandbox-in-order-to-be-occlusive-yet-invisible/9822/4 "2020-04-08T17:57:30Z")

</div>

> [@paleRider](#):
>
> I understand that, in order to have an occlusive-invisible material, that three parameters: shading model, color write (aka color mask) and depth write must be set as proposed?

This is correct 🙂

---

<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:** [April 8, 2020, 7:29pm UTC](https://forum.babylonjs.com/t/tweaking-material-in-sandbox-in-order-to-be-occlusive-yet-invisible/9822/5 "2020-04-08T19:29:18Z")

</div>

With `needDepthPrePass` already existing, I think we would only need an additional material property like `isInvisible` or `passThroughMaterial` that would make the object not rendered (but `needDepthPrePass` would still be honored): by setting `needDepthPrePass` to `true` and this new property to `true` you would achieve what you want.

Can do a PR if you want?

---

<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:** [April 8, 2020, 7:42pm UTC](https://forum.babylonjs.com/t/tweaking-material-in-sandbox-in-order-to-be-occlusive-yet-invisible/9822/6 "2020-04-08T19:42:39Z")

</div>

Or maybe, if there’s no point to have a standalone property like `invisible` because the feature will always be used in conjunction with `needDepthPrePass`, the property could be named `depthPrePassIsExclusive` instead.

---

<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:** [April 8, 2020, 10:46pm UTC](https://forum.babylonjs.com/t/tweaking-material-in-sandbox-in-order-to-be-occlusive-yet-invisible/9822/7 "2020-04-08T22:46:47Z")

</div>

What about just having a disableColorWrite? that could be more flexible

---

<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:** [April 8, 2020, 10:50pm UTC](https://forum.babylonjs.com/t/tweaking-material-in-sandbox-in-order-to-be-occlusive-yet-invisible/9822/8 "2020-04-08T22:50:34Z")

</div>

More flexible indeed, but less performant: the full fragment shader is still run.

In the depth pre-pass case, the fragment shader stops early.

Maybe we should support both functionalities?

---

<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:** [April 9, 2020, 3:38pm UTC](https://forum.babylonjs.com/t/tweaking-material-in-sandbox-in-order-to-be-occlusive-yet-invisible/9822/9 "2020-04-09T15:38:52Z")

</div>

yes because for nme I could need to run the entire fragment to get what I need

---

<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:** [April 9, 2020, 3:41pm UTC](https://forum.babylonjs.com/t/tweaking-material-in-sandbox-in-order-to-be-occlusive-yet-invisible/9822/10 "2020-04-09T15:41:54Z")

</div>

`disableColorWrite` seems ok then!

---

<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:** [April 9, 2020, 4:30pm UTC](https://forum.babylonjs.com/t/tweaking-material-in-sandbox-in-order-to-be-occlusive-yet-invisible/9822/11 "2020-04-09T16:30:43Z")

</div>

I’ll do the PR !
