Rendering transparent icons with POV-Ray
POV-Ray can be a very nice tool for generating high quality graphics for websites, program icons and user interface elements. Most of the images on this website for example are made with POV-Ray. But although it is straight away to render images with alpha channel (transparency) in POV-Ray using this feature to generate graphics that blend well with the background requires some more hand work.
This tutorial explains this process using the KIO-POV logo as an example.
On the right you can see the plain scene for the logo. The logo is standing on a white plane so the background of the image is white and the logo is casting a shadow on the plane. See the source code of this scene for more details.
To render the scene with a transparent background you have to add the
To get both the shadow and the transparent background you have to do multiple renders and combine them. In the scene we therefore define 3 constants for the three renders to create:
#declare VARIANT_ALPHA=1; // alpha render (for foreground)
and set up a symbol
render needed is the one above for the logo itself. Then we have to render the scene with only the shadow. For this the
In addition we render a shadow mask to steer the transparency of the shadow. The shadow itself should be partly transparent while the rest of the background is completely transparent. To get such an image the we modify the previous setup with a different finish for the plane and turn off radiosity.
The resulting background plane definition looks like
See the complete scene for the other differences.
The three renders can be combined to a single image with a image editing program of your choice. The third variant should be added to the second(background) variant as alpha channel and the first(foreground) variant is copied on top of that. Using the ImageMagick tools this task and the three renders can be issued with a simple shell script. The resulting image can be found in large on the right and with various background colors below.
Of course the sample scene only shows the simplest possible way to generate such an image. To speed up the different render variants it can be useful to change the finishes of the logo elements to something plain in the shadow and background variants. If the logo object penetrates the ground plane it has to be clipped in the foreground variant to get a correct image.
The scene file used here requires MegaPOV to render for the following purposes:
- HDRI lighting using a light probe from Jaime's site. The scene can also be rendered without HDRI but the quality of the result will suffer.
no_radiosityflag. In official POV-Ray
no_imageimplies no radiosity so removing an object from direct view also removes it from radiosity calculation. This problem can be worked around by using the radiosity
load_filefunctions but using MegaPOV is more convenient.
- Tone Mapping feature which can help to ensure high antialiasing quality with strong contrasts in scenes.