The technique suggested by m13r produces very nice renderings, but it requires 3 rendering passes and a lot of changes to the scene for each. This takes time and requires quite a bit of setup.
A simpler and honestly for some cases better result can be obtained with just two passes. Set both your background and ground plane to white, render, set them to black, render again. Lets say you toggle the setting here and generate two files, white.png
and black.png
using one or the other of those light definitions.
//#declare SceneLight = rgb<1,1,1>
#declare SceneLight = rgb<0,0,0>
background { color SceneLight }
plane {
y, 0
pigment {
color SceneLight
}
}
Now the two images and extract the difference using the two background technique documented here.
magick black.png white.png -alpha off \
\( -clone 0,1 -compose difference -composite -negate \) \
\( -clone 0,2 +swap -compose divide -composite \) \
-delete 0,1 +swap -compose CopyOpacity -composite \
transparent.png
The disadvantage of this method is that you have less flexibility over scene lighting and cannot pretend to reflect anything off the ground plane. If your objects are matte enough not to be seriously affected by scene background colors then this method might be for you. It my case it saved one time consuming rendering pass and a lot of scene object manipulation.