Povray transparent background with shadows

3.7k Views Asked by At

I'd like to use Pov-Ray to generate pictures that can be used in a website on any background color. The pictures need to have a transparent background, but with reflection and shadows cast on a transparent plane surface.

In Pov-Ray (3.7), you can set the background transparent by setting Output_Alpha=True in the povray.ini file and outputting as a png file.

You can even get transparent reflective surfaces by using the color Clear on a plane (or any other object). But if you set the color of an object to Clear, no shadows are cast on it.

Is it possible to cast shadows on transparent objects?

2

There are 2 best solutions below

0
On

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.

0
On

You could render the shadows and objects separately and merge the resulting images as shown here.