Use occluder model to hide objects


I would like to use a 3D model to occlude (hide) some other entities/models inside the scene. As the renderer normally does (object behind other object is hidden).

But as a last step I would like not to render that occluder. Is this possible?

1 Like

@max @Mr_F any idea? I saw in some code examples of yours that you were using some undocumented methods/objects like scene.drawCalls[] and pc.Command.

My question is basically how to remove an object from the final render list, but keep it there during the depth calculations.


I did some portal/occluder things in the texture compression demo. Which is not open-source, probably because we didn’t have the license to share the models… anyway, I was simply changing the meshInstance.visible boolean property, and it would affect depth calculations, but we didn’t have any. Why do you need occluded objects to be rendered to depth?
Also, I used simple rectangles as portals/occluders, not models. You can make a frustum, that goes from the camera position and through every point of a rectangle and then simply check if objects’ bounding spheres/boxes are fully inside the frustum.

Also, do you mean hiding objects just for optimization (when they’re not visible already anyway), or precisely remove them pixel-by-pixel for some effect? If it’s the latter, there are easier ways.

Thanks for your reply @Mr_F.

The scenario is the following: we are rendering 360 skyboxes of the internals of buildings by mapping a 360 texture in a custom geosphere of ours. Now we are trying to render placeholders (e.g. spheres) in world space, to provide clicking functionality for the current room.

We have an exact mesh that includes all walls/floor/ceiling of the building so we can perfectly arrange the spheres in their place (living room, kitchen, bedroom etc.). The placeholders get shown/hidden based on the position of the camera inside the world space.

This works great if we can only remove the actual mesh geometry for the final render step. We would like to keep it for the depth calculations to show/hide the spheres but at the actual rendered frame we would like only to show the 360 skybox and the spheres.

Hmm, do you use pc.Picker for clicking the geometry? And occlude spheres with room mesh?

Yes, we use the picker class to click on the geometry, though we don’t want to click on the building geometry. Just the placeholders, this works fine right now.

Edit: to occlude the spheres with the room mesh … right now are hidden by the normal depth calculations of the renderer. The question is basically if we can leverage the existing render pipeline to occlude the spheres, just at the end hide the building geometry.

I think this should work for you

meshInstance.visible = false;
meshInstance.pick = true;

basically tells the engine to not render the object to the main image, but do render it for the picking pass. Depth occlusion should work fine for the picker.
Just make sure to set it to all mesh instances of all models (spheres and rooms). Mesh instances are inside entity.model.meshInstances.


Though it doesn’t seem to work. Check this example project I made, orbit around, the sphere should be hidden when is behind the occluder:

Edit: picker successfully fails to pick up object when it is occluded, this is good. Last thing to be perfect to avoid rendering it at all.

Well, you need to set visible=false to the sphere as well, but you only change its pick value

Sorry but I didn’t get it, if I set sphere to false as well, then sphere is permanently hidden. The desired result is to be only hidden while it is occluded by the invisible box.

sphere visible=false:

Uhm, I thought spheres are like, click zones, and not actual objects you need to render. So do you need the sphere have partial per-pixel occlusion, or just fully hide it as soon as it’s fully occluded by the box?

Partial per-pixel occlusion would be best, as it happens while the occluder is rendered normally.

If not possible, second option will do.

Edit: yes spheres are the visual click zones that need to be rendered and occluded while the 2D/360 panorama is rendered.

I understand now. You can do it with some material tricks. Here you go:

1 Like

That’s exactly the behaviour we are looking after!

Thanks a lot.

@Mr_F can you check the following:

I added a surrounding geosphere model, but when I enabled alpha blending on that to create some skybox fade in/out effects the box started to behave strangely.

Sometimes it works, sometimes it is cleared in that colour.

Try this, I just changed the layers in the script:

1 Like

Thanks for the prompt reply! It works fine now, and got it, have to be careful of the render order.

I’ve just created an example project for another related issue where the material and layer setup can be used to occlude other objects. As the previous posters mention, be aware of render order.

Anything you don’t want to hide has to be rendered before the Occluder layers.

The van and cube are the occluders

1 Like

Would it be possible to use this to create an augmented reality portal? I tried to set up a simple example but it renders black instead of picking up the camera texture.

Here’s the example project:

There’s a couple of issues in that project.

Because it’s an AR project that uses a video dom element behind the canvas, you need to enable transparent canvas in the project rendering settings and make the camera clear color fully transparent and black so you can see through the canvas that WebGL is rendering on

Project settings → Render

Camera clear color

Finally, change the occlusion script to disable alpha write on the material