- sort planets from back to front
- for each planet:
- duplicate the camera, set znear/zfar to match planet
- clear the z and stencil buffers, but not the color buffer
- render the ground
- render the atmosphere
- render the clouds and the rest
Remarks:
1. The znear value is set to the closest distance between the camera and the atmosphere. If the camera is inside the atmosphere, it is set to a constant.
2. The zfar value is set to the longest distance between the camera and the atmosphere (basically, the symetrical point on the other side of the planet).
3. Since the znear/zfar change for every planet, the zbuffer values become obsolete between many planets, and rendering has to be done from back to front.
4. By rendering the ground first, early-rejection of the atmosphere or cloud pixels can happen.
Maybe that's not worth the effort/overhead. Just a thought :)