Hide part of lines behind a sphere, from a shader

Hello,
I have a semi transparent globe where I draw line between cities. As the sphere is semi transparent I would like to hide the part of the lines which are actually behind the sphere.
Here is my issue :


I already have a shader on the line, so I thought using some computations to discard the gl_FragColor but I can’t get the right approach to do it ?
In my mind it’s like having some “fog” implementation i.e. hide the pixels based on the distance from the camera.

Any idea on how to achieve that ?
thanks,
G.

Hi!
Here is an option with points: Way to hide Points if geometry is seen from backside? - #8 by prisoner849

Thank you for the response.
This is actually what I’m using on my sphere (in order to reduce the opacity of points in the backside), but I think the problem is different here.
From my understanding, your option works when we are on the same geometry, but in my case the lines are different geometries than the sphere. I actually need to detect when when some points of my lines are occulted by the sphere, from the camera point of view. (knowing that my sphere is in the center of the scene and have a radius of 1)

In the shader, you can get the depth(distance from the camera) by vViewPosition.z, and the camera position in cameraPosition, so discard based on that.
Also, I guess in this case you can use Material.clippingPlanes to discard points, with the plane updating when the camera moves.

2 Likes