#!/bin/sh
# -------------------------------------------------------------------------
#
#  renders a POV-Ray scene in different variants
#  and combines them to an icon with transparency
#
#   Usage:
#
#     render_icon.sh Scene Image Render_Options
#
#   where 'Scene' is the name of the scene
#   and 'Image the prefix for the images to generate
#
#   requires ImageMagick tools
#
# -------------------------------------------------------------------------

POVRAY=megapov

SCENE=$1
IMAGE=$2
OPTIONS="$3"

$POVRAY -i${SCENE} $OPTIONS +fn -o${IMAGE}_alpha.png DECLARE=Variant=1 +ua
$POVRAY -i${SCENE} $OPTIONS +fn -o${IMAGE}_bkg.png DECLARE=Variant=2
$POVRAY -i${SCENE} $OPTIONS +fn -o${IMAGE}_shadow.png DECLARE=Variant=3

convert -channel R -separate ${IMAGE}_bkg.png ${IMAGE}_r.png
convert -channel G -separate ${IMAGE}_bkg.png ${IMAGE}_g.png
convert -channel B -separate ${IMAGE}_bkg.png ${IMAGE}_b.png
convert -depth 8 -channel RGBA -combine ${IMAGE}_r.png ${IMAGE}_g.png ${IMAGE}_b.png ${IMAGE}_shadow.png ${IMAGE}_bkg2.png
composite -depth 8 -compose over ${IMAGE}_alpha.png ${IMAGE}_bkg2.png ${IMAGE}.png

rm -f ${IMAGE}_bkg2.png ${IMAGE}_r.png ${IMAGE}_g.png ${IMAGE}_b.png
