Transparent Occlusion for AR (Premium Only)
-
Introduction
Sometimes you want to use object A to occlude (i.e. block) another object B, so that a part of object B will not be visible. At the same time, you might also want to make object A transparent, so no one sees it.
This is what we call “transparent occlusion”. It is especially useful in AR (augmented reality) projects, since you may want a real object to occlude a 3D virtual object.
For example, suppose you have a real table in the camera view, and you want to place a virtual ball below that table. By default, the ball will be drawn above the camera image, so it will show up above that table, not below it. To fix this issue, you can add a 3D box to represent the tabletop, and use this box as a “transparent occlusion”. The ball will be blocked from sight, and because the box is transparent, the real table will be seen, as if it is the real table that is occluding the ball.
To use an object for transparent occlusion, you just need to run this block:
When you run this block, there will be 2 effects:
- The sprite object (the currently selected object) will become invisible;
- Any other object that is added to the scene after the sprite object will still be occluded by it.
Demo 1
In this program, we add a sphere “A” and a box “B”. The sphere is in front of the box, so it will block a part of the box:
Now suppose we select the sphere and use it for transparent occlusion. The sphere will disappear, yet we will still see that part of the box is occluded by the sphere.
Demo 2
It is critical for you to understand that only objects added after object A has been added will be blocked by it.
For example, suppose there is also a blue box named “C” that’s added before the sphere:
Before using transparent occlusion, this is how it looks:
Now if we turn on transparent occlusion, you will see that although the sphere sill occludes part of the green box, it does not occlude the blue box at all.