Skip to content

Instantly share code, notes, and snippets.

@CyberShadow
Last active January 8, 2019 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CyberShadow/8b26f8e03add2ca692b531f8c8e3320e to your computer and use it in GitHub Desktop.
Save CyberShadow/8b26f8e03add2ca692b531f8c8e3320e to your computer and use it in GitHub Desktop.
PNG transparency demonstration (POV-Ray dice)
Input_File_Name=dice.pov
Initial_Frame=0
Final_Frame=1
# Draft
# Width=640
# Height=480
# Final
Width=800
Height=600
Antialias=true
Antialias_Threshold=0.001
Jitter=false
Antialias_Depth=5
Sampling_Method=2
Quality=11
#include "colors.inc"
camera {
location <-15, 0, 0>
direction <0, 0, 5>
look_at <0, 0, 0>
aperture 0.4
blur_samples 100
focal_point <-1, 0, 0>
}
background { color rgb <clock, clock, clock> }
light_source { <-9, 7, -6> color White }
light_source { <9, -7, 6> color White }
#declare DiceColor = color red 1 green .95 blue .65;
#declare DotColor = color red .1 green .1 blue .1;
#declare DiceBody = intersection {
box { <-1, -1, -1>, <1, 1, 1> scale 0.5 }
superellipsoid { <0.7, 0.7> scale 0.63 }
}
#declare Middle = sphere { <0, 0.6, 0>, 0.13 }
#declare Corners1 = union {
sphere { <-.25, .6, -.25>, 0.13 }
sphere { <.25, .6, .25>, 0.13 }
}
#declare Corners2 = union {
sphere { <-.25, .6, .25>, 0.13 }
sphere { <.25, .6, -.25>, 0.13 }
}
#declare Middles = union {
sphere { <-.25, .6, 0>, 0.13 }
sphere { <.25, .6, 0>, 0.13 }
}
#declare One = Middle
#declare Two = Corners1
#declare Three = union {
object { Middle }
object { Corners1 }
}
#declare Four = union {
object { Corners1 }
object { Corners2 }
}
#declare Five = union {
object { Four }
object { One }
}
#declare Six = union {
object { Corners1 }
object { Corners2 }
object { Middles }
}
#declare DiceInterior = interior { ior 1.5 }
#declare DiceFinish = finish { phong 0.1 specular 0.5 ambient 0.4 }
#macro Dice(Color)
difference {
object {
DiceBody
pigment { color Color filter 0.4 transmit 0.3 }
interior { DiceInterior }
finish { DiceFinish }
}
union {
object { One rotate -90*z }
object { Two }
object { Three rotate -90*x }
object { Four rotate 90*x }
object { Five rotate 180*x }
object { Six rotate 90*z }
pigment { White }
finish { ambient 0.5 roughness 0.5 }
}
bounded_by { box { <-0.52, -0.52, -0.52>, <0.52, 0.52, 0.52> } }
}
#end
object { Dice(color rgb <0.7, 0, 0>) rotate <195, -30, 10> }
object { Dice(color rgb <0, 0, 0.7>) rotate <30, 40, 50> translate <3.5, 1, 1> }
object { Dice(color rgb <0, 0.5, 0>) rotate <-40, 20, -120> translate <4.5, 1, -1> }
object { Dice(color rgb <0.5, 0.5, 0>) rotate <-10, 290, -30> translate <5.5 ,-0.8, 0> }
dice.png : dice0.png dice1.png
# mkalpha is https://github.com/CyberShadow/misc/blob/master/mkalpha.d
mkalpha dice0.png dice1.png dice.png
dice0.png dice1.png : dice.ini dice.pov
povray dice.ini
Re-render and calculate proper transparency.
POV-Ray seems to ignore the effects of transparency for translucent objects when calculating the output image alpha channel. Even though the dice are semi-transparent, this is not represented in the resulting PNG image.
Rectify this by performing two renders (with a fully-black and fully-white background), then calculate the correct alpha value with a separate tool, so that the dice appear properly translucent depending on the background the image is overlaid on.
Rendering is done with anti-aliasing with jitter disabled and a low recursion threshold, to avoid artifacts due to focal blur.
This version is better suited for illustrating the PNG file format's transparency feature, as more than just the dice's edges are transparent.
Source code, including render settings: https://gist.github.com/CyberShadow/8b26f8e03add2ca692b531f8c8e3320e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment