Forum: Poser - OFFICIAL


Subject: setting light shadow parameter problem...

dennisharoldsen opened this issue on Jan 28, 2008 ยท 12 posts


bagginsbill posted Wed, 30 January 2008 at 5:30 PM

Cool - glad it worked.

Regarding rendering on black...

For pixels that are completely filled or unfilled, this is not an issue. It either is 0% of your render in it or 100% of your rendered pixel in it.

But what about fringe pixels - pixels that are only partially filled by your 3D content? Poser figures out what percentage is filled, and puts that in for the alpha value. But it also writes a color in the color channel. In doing so, it will pre-blend your currently configured background color with the 3D color for that pixel.

If you render against white (RGB 255,255,255), and the pixel is of a blue object (RGB 0,0,255), and the 3d object only fills 50% of the pixel, Poser will record RGB(127, 127, 255) in that pixel of the color map. When you finally compose that with your background image, the math comes out wrong. You end up with a gray fringe around your cutout.

You can see an example of this mistake HERE

That is why you must render with BLACK. Black is RGB 0 0 0 and means that only the true color of your 3D object is recorded.

This is called a pre-multiplied color channel. I'm not sure if you're writing your own code to do the compositing, or you're using some other code. I don't remember the details of the WIN32 API but I've done this before. You need to tell Windows that you have a ALPHA_PRE_MULT type of image. (Again, I can't remember the exact name of the flag.)

If you correctly set the flag, then when you DrawBitmapAlpha (or whatever the function is called) it does the right thing.

Mathematically, given B for your background photo pixel, and F for your foreground (rendered) pixel, and A as the Alpha (opacity) value, compositing is done like this:

(1 - A) * B + A * F

That is the generalized blending or interpolation formula.

But the PRE_MULTIPLIED version is simpler because A * F has already been written into the PNG file. So the correct blending formula is:

(1 - A) * B + F

Windows will choose the second form if you correctly tell it that your color channel is pre-multiplied. Note that this is faster, too, because there is only 1 multiply, not 2.


Renderosity forum reply notifications are wonky. If I read a follow-up in a thread, but I don't myself reply, then notifications no longer happen AT ALL on that thread. So if I seem to be ignoring a question, that's why. (Updated September 23, 2019)