Render different color by depthMap with shader

I’m trying to render different color/texture when the plane is blocked by the other mesh. The following playground project has 1 box and 1 sphere, the plane is in the middle. With this viewing angle, I expect it only turns red for the overlapped area with the box (because the box is in front of the plane); while the overlapped area with the sphere must be green (because the sphere is behind the plane).

Welcome aboard!

There’s a simply way to do this, which is to clone the plane and apply a material with an inverted depth function (GREATER). This way the plane will only be rendered when it is occluded by something.

For this to work, the plane must be rendered last, after all possible occluders have updated the depth buffer.

In this PG, I used a rendering group id of 1 for the sprites, to make sure that they are rendered last:

Also, this could help:

2 Likes

Thanks Evgeni! I like this solution!