Spatial rendering of meshes (Inside Sphere)

Godot Version

4.3

Question

I want to render only the part of objects that are inside of a sphere. Where the objects intersect with the sphere, the sphere should be rendered. The image is an example of of similar effect.

Any idea?

I considered two tasks here:
First, render the meshes only inside the sphere (done).
Second, render the sphere only inside the meshes (?).

Cheers

Hi.
what you need is the depth map.

You want to render only the parts of the sphere that are futher away from the camera then the rest. So where sphere-z > depth-map-z. Since you backface cull the sphere the faces in the back always point away.
But this will only work if all other objects are closed surfaces and you never enter the others meshes volume with the camera.

There may be some flicker around the edges of the sphere because of z-fighting.

Thanks for replying!

I tried this. The problem I’m facing is: I don’t want to draw the meshes outside the sphere. So they don’t show up in the depth map. And then the sphere is always closer to the cam. Any idea here?