- Home /
Masking objects with alpha gradient at intersection
I've been looking for a method to mask 3d objects when they are outside a defined mesh, but in a way that is more visually appealing than a direct cut along the intersection. The goal is that when an object is intersecting with a specific mesh (e.g. a sphere or cube), the object will be blended to be transparent in a direction away from the intersection. When the object is completely inside the mesh it will be visible, and outside of course invisible. The end use of this is for a diorama-like map that is only shown in a specific bubble.
Below is the best I can do to try and visualize this. The image on the left is a top down view of what I'm trying to achieve. Dotted lines represent a transparent portion of an object, the black dotted line represents the boundary/clipping/masking object (in this case a cylinder). The image on the right is a cross section of the red cube.
Note that the gradient on the red cube follows the curve of the masking object. If an object were to fill the entire masking object (e.g. a flat plane that is much bigger than the object), the mask would continue around the edge of the masking object.
Originally I had the idea of using a depth mask shader, but this didn't really contribute in any way towards the alpha of the masked object, just if pixels were shown or not. Beyond that, a shader-based solution is probably what I'm looking for, but I really have no idea what to look into or where to start.
Any thoughts/ideas/direction would be much appreciated.