Screenshot with Alpha not saving properly

Am I missing something here.

When I used Alpha=1 with my colors and materials, the saved file through screenshot looks exactly the same as the one rendered at the outset in the main window.

But when I used Alpha less than 1 with my colors and materials, the saved file through the screenshot function looks way more opaque that the one rendered at the outset in the main window.

I am using the following:

    base.graphicsEngine.renderFrame() 
    saved = base.win.saveScreenshot(Filename(filename))

Thanks in advance.

Hmm, for one, are you writing a .png file? If you write a .jpg file, framebuffer alpha information will be lost, since .jpg files do not support an alpha channel.

I am writing into a .png file

You see this behaviour because of the way colour blending works:

fbcolor = objcolor * objcolor.a + fbcolor * (1-a)

This basically means that the following ends up getting written to the framebuffer for a transparent object:

fbcolor.a = objcolor.a^2 + fbcolor.a - fbcolor.a^2

This is a side effect of transparency blending. The solution to this is to specify the alpha and RGB blend functions separately, but this is not supported in Panda3D today. I’ll put it on my todo list.

I guess this explains the problem. Thank you

Are there any image formats that can overcome the blending problem?

Well, you could use any format that doesn’t support alpha (like jpeg) to avoid having alpha in the first place, but otherwise, no.

I implemented this a while ago, but forgot to mention it. Will be in 1.10.0.