Partial invisible

an object for example, a cube, moves from the left to the right, until it reaches a plane vertical to its moving direction. how to make the part which crosses the plane be invisible but leaving the other part visible? is there any related api?

It sounds like clipping planes are what you seek: Using Clipping Planes | Babylon.js Documentation

it may solve my problem. thank you very much @inteja .

@inteja it doesn’t work. All objects divided by the clip plane will be invisible. what I wanted is that only the specific object will be partially visible and partially invisible, leaving all other background objects untouched. Does any one can help?

That linked documentation page explains exactly how to do this with an example - “Clipping Planes Example 2”. Note that the sphere is clipped but the ground plane is not.

1 Like

Not sure what your issue with the answer above is? May be you don’t want to clip it with a plane, but rather some other mesh?
I guess the above is the simplest and most recommendable but if you need some other object to act as a mask there are still other solutions (including this small hack below). You could also use renderingGroupID or work it through a material/shader.
Not sure if I can really recommend the simple hack below (based on the rendering order and depth of alpha blended and opaque meshes) but I guess it could do the trick depending on your use case:

Edit: Oh, and I nearly forgot, Welcome to our Community and … have a great day :sunglasses:

Edit1: Here’s quickly a derivative of the above small ‘hack’ :grin:. Still a hack but a little more recommendable. Using a texture and setting the texture as alpha will make the rendering go through the alpha test. Less likely to create bugs or artefacts.

Note that since 5.0 you can define the clip planes through the material:


Thanks @Evgeni_Popov! I didn’t know this.

And I did not remember it lol