Is there a babylonjs equivalent to transparent object occlusion?

Hey folks

I want to create an invisible object in Babylon.js that, while not visible itself, still occludes other objects behind it. So if I aim a camera at a plane, and a sphere goes behind it it should be occluded like normal, if sphere comes back in front the sphere should be not occluded

I’ve tried a few different things but nothing has worked so far.

Any ideas? Thanks

Render it to RenderTargetTexture, and use it as a mask to remove pixels in a PostProcess shader or Node Material

1 Like

This works well found it via playground search:

occluderMaterial.backFaceCulling = true
occluderMaterial.transparencyMode = Material.MATERIAL_OPAQUE
occluderMaterial.alphaMode = Constants.ALPHA_PREMULTIPLIED
occluderMaterial.disableLighting = true
occluderMaterial.disableColorWrite = true
m.material = occluderMaterial;
m.onBeforeRenderObservable.add(() => engine.setColorWrite(false));
m.onAfterRenderObservable.add(() => engine.setColorWrite(true));