Keep a set of objects from casting shadows while having a shadow I am making an animation in Blender 2.82 that shows the Earth and the Moon orbiting around the Sun. For clarity, I want to avoid the Earth and the Moon to cast shadows on each other because I made them move in the same plane. I use the Cycles rendering engine.

In a previous version, the Earth and the Moon were single spheres. In the “Visibility” section of the “Object” panel, unchecking the “Shadow” box did the job.



However, I wanted something more realistic and followed the Blender Guru tutorial on how to make a realistic Earth so now the Earth is 3 concentric sphere and everything I tried did not give the right result. (Note that I did not follow the tutorial for the atmosphere: mine has a volume scatter shader only.) The Moon is still a single sphere so the problem is with the Earth only.

What I would like is a way to tell Blender that the 3 Earth spheres can have shadows casted on them, cast shadows on themselves, but not on other objects.



This is what I have now, physically correct but the moon is not visible due to she shadow (it’s located on the missing arc of the blue circle):



My first try was unchecking the “Shadow” box just for the surface. The moon is then visible but the night side of the Earth becomes reddish and it’s not realistic at all. With the box unchecked for the surface, the clouds and the atmosphere, the Earth is invisible except a few reflections, but the moon looks as wanted:



Then, with every boxes for the Earth checked, I tried to prevent the light source to cast shadows. The Moon looks great and the Earth is quite good but its shadow is way too light:



This last try would be perfect if the shadow on the night side was darker.
I’m answering my own question. The solution was found while working on the compositing phase.

It is possible to do this using view layers and compositing. It is necessary to create an masking object, in this case a sphere centered on the Earth and with the same size as the atmosphere, with all needed relations to follow it during animation. Then, in the “Object” panel, the “Visibility” section is set like this:



The “Holdout” makes the masking sphere appear like the background (in this case transparent, as usual with view layers). In unchecked every other boxes except “Camera” to avoid interference with lighting.