Tweaking material in Sandbox in order to be occlusive yet invisible

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

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.

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

1 Like

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 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.

Best regards.

This is correct :slight_smile:

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?

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.

1 Like

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

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?

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

disableColorWrite seems ok then!

I’ll do the PR !

1 Like