2
$\begingroup$

I just selected some pixels in Photoshop and deleted them, so this part became transparent. I save it as PNG. And imported this image as texture for cycles material.

What surprised me is a "Material" and "Texture" view in 3D window, that displays pixels that should not exist anymore in the image.

From result it seems to me like Ph deleted completely only all pixels (color information) out of a box (rectangle) that determinate pixels with alpha. And for pixels inside this "non alpha" box he kept colors and alpha info.

Blender than displays only color info without alpha inside this rectangle. That is probably a bug, but I just even didn't know that PNG saves this pixels as well.

Am'I right? Or what is going on here?

Since the node tree consists from a "Transparent" shader as well, it displays alpha right, but not in a "Texture" method anyway.

Note: Render is OK.

So, the questions are:

  • How PNG file stores color/transparent data (this doesn't seem to be blender related, but only blender displays data in that way for me)

  • Is this behaviour expected or is it a bug? (or any other user fault :)

enter image description here

Edit: probably more descriptive illustration enter image description here

$\endgroup$
2
  • $\begingroup$ I added one screen, probably more descriptive the issue. $\endgroup$
    – vklidu
    Commented Mar 21, 2018 at 16:33
  • $\begingroup$ Deleting Pixels in Adobe Photoshop (APS)with a image that has an Alpha Channel (may) simply turn on the alpha to (~1.00). There may be no reason to change the RGB at all. Unviewed data in APS may still exist, and might be useful to fill their needs. You might consider filling the unwanted areas with Black in APS to change the RGB Channels, to convince yourself of this. APS can separate channels for you as well. In Blender, Alpha is information which is (optionally) used and this can be used to great effect for animation. In Blender Alpha is an option not a requirement. $\endgroup$ Commented Mar 21, 2018 at 16:34

1 Answer 1

6
$\begingroup$

The issue is one of the many problems with the PNG format: Unassociated Alpha

Blender will display the RGB information because it is part of the file and the alpha channel has not been associated correctly, and Blender expects associated alpha.

Quoting from the PNG specifications:

PNG uses "unassociated" or "non-premultiplied" alpha so that images with separate transparency masks can be stored losslessly.

An alpha value of zero represents full transparency, and a value of (2^bitdepth)-1 represents a fully opaque pixel. Intermediate values indicate partially transparent pixels that can be combined with a background image to yield a composite image. (Thus, alpha is really the degree of opacity of the pixel. But most people refer to alpha as providing transparency information, not opacity information, and we continue that custom here.)

The color values stored for a pixel are not affected by the alpha value assigned to the pixel. This rule is sometimes called "unassociated" or "non-premultiplied" alpha.

"premultiplied alpha", stores pixel values premultiplied by the alpha fraction; in effect, the image is already composited against a black background

A different way to think about the problem is to blender sees the RGB information on those pixels as luminous and transparent at the same time... (like the fire on a candle, for example).

What would happen if you switch from Straigth Alpha to Premultiplied?

Not a real solution, because the RGB information is still there (though this will display correctly in rendered view). When you premultiply blender would expect black instead of RGB information.

enter image description here

The proper way to deal with this situation is to multiply the alpha with the RGB information.

Split the RGB information, use a converter>math node in multiply mode to multiply the information of each channel by alpha and recombine the RGB channels.

enter image description here

(click on the image to enlarge)

Or use the color and alpha information on a color Mix node in multiply mode and use 1 as factor.

enter image description here


Other ways to use unassociated alpha information.

Unassociated alpha could then be thought as a mask to determine how two elemements mix. White (1) would be one element, black (0) would be the other and any shade of gray would be a partial mix.

enter image description here

You can then use such a mask to control the mix between two different shaders(like emission and transparent) plugging alpha directly as a factor for the mix.

enter image description here

Or if what you need is to control the color of the sader only, use a color mix factor and have the alpha information work as a mask for the mix.

enter image description here


Further reading

Why does blender then use associated alpha and why shouldn't I use PNGs you might be asking...

Quoting from this very clever answer:

  • ONLY associated alpha (often called pre multiplied) allows the compositing of pixels that are luminous and transparent (Like halos, blurs, fire, glares, etc) so choose a file format that supports associated alpha (the most common for visual effects is EXR)

  • It's impossible to produce that kind of alpha blending with unassociated alpha, so formats like PNG are completely ruled out.

  • Image editing programs like Photoshop and GIMP work internally with unassociated alpha, so they are not suitable for compositing that kind of effects with alpha blending. You need to cheat and use an RGB only image with an addition instead (those programs are also likely to destroy the RGB information of every pixel with alpha=0, so be careful).

Suggested links:

https://wiki.blender.org/index.php/User:Sobotka/Alpha/Associated_and_Unassociated_Alpha

and

Compsiting Digital Images, by Porter & Duff

$\endgroup$
2
  • $\begingroup$ Thank you for this deep inside view. But why blender differs in results for texture / material / render type view? I know material use OpenGL end render Cycles, but I don't think it's a big deal to handle alpha in the same way. Right? $\endgroup$
    – vklidu
    Commented Mar 21, 2018 at 21:40
  • $\begingroup$ @vklidu it's up to you how you use it. But it is important to know the difference. Blender does have some issues in how it displays alpha (blender.stackexchange.com/questions/57816/…) The key point is that some images can only be done properly using associated alpha, and cannot be stored in a format as PNG. $\endgroup$
    – user1853
    Commented Mar 21, 2018 at 21:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .