利用者:Sobotka/Alpha/Associated and Unassociated Alpha

提供: wiki
移動先: 案内検索

Update as of January 13, 2013

Color Unpremultiply has been 'baked' into the various image formats, and as such manual control of it should not be necessary. With that said, the information remains here for those interested in the lower level dynamics of alpha channels and color management / non linear color manipulations.

A Tale of Confusion and Mystery

This page may be expanded in the future. For the time being, it is here as a very simple illustration as to "correctness" in alpha channel compositing, with specific attention to Blender artists and file formats.

A Warning

It should be noted that Blender uses OpenGL acceleration throughout. This means that when you set your UV Image Viewer to display "Color and Alpha" with the checkerboard grid, you may never be able to correctly see how your image looks. If your image is unassociated alpha, it will display correctly. If your image is associated alpha, it will always show dark fringes as the over operation is currently enforced to be unassociated[1]

Do not rely on the "Color and Alpha" view for assessment until you are aware of this shortcoming.

About the Demonstrations

The images use foreground values that perfectly match the background image panes. Why? Because the impact of incorrect application of linearization order and double association are only applicable in semi-transparent regions. The foreground is heavily blurred to more greatly illustrate the cases and reveal correct expected behavior.

The demo file used in the foreground, as composited correctly against a traditional checkerboard:

Comparison of Linearization Orders

Predivide ("Color Unpremultiply")

There are two controls relating to alpha that operate per image in the UV Image Editor. Predivide, or "Color Unpremultiply" is beside the "Premultiply" toggle. Checking this box will unassociate the alpha from the RGB values prior to linearization. This will assert that your sRGB values are correctly mapped.

Normally I just click buttons until it looks right. Good?

You aren't alone. Many people start here. However, knowing what is going on regarding alpha is a very useful piece of knowledge that will impact all of your imaging. Worse, now that there are two buttons in the properties of the UV Image Editing panel, your time to randomly twiddle your buttons will have increased twofold. ;)

When should I toggle this option on?

When should I toggle Color Unpremultiply on for Import?

If your image has associated / premultiplied alpha and is stored in a non-linear format such as a typical TIFF, you should turn this option on per image via the UV Image Editor's Properties panel. Select the image from the drop down selection, open properties, and select "Color Unpremultiply". Do not toggle this option on if your file format stores RGB values in a linear fashion, such as within an EXR, or if the format stores alpha in an unassociated fashion, such as the PNG format.

The control for unpremultiply on input files is located in the Properties panel of the UV Image Editor.

When should I toggle Color Unpremultiply on for Export?

If you are saving a file with alpha to an associated file format such as TIFF, you must toggle the "Color Unpremultiply" option on via the Shading panel of the Properties pane. Do not toggle this option on if your file format stores RGB values in a linear fashion, such as within an EXR, or if the format stores alpha in an unassociated manner, such as the PNG format.

Care must also be taken if using the compositor to assure that any alpha channel you save is in accordance with the file format you are saving to. Blender will not adjust your alpha channel for you. For example, PNG by specification only stores unassociated alpha. This means that you must unassociate the alpha channel from the RGB values prior to saving. This is also why you should not Color Unpremultiply PNG output otherwise an incorrect doubling up of the dkivide will result.

The export option for unpremultiply is located in the Color Management panel of the Scene tab in the Properties pane.

What happens if I don't?

Your image will be incorrectly linearized with associated RGB values. Images speak louder than words. The following sample is from an image with associated alpha from a nonlinear format TIFF:

Comparison of Linearization Orders

Associated / Premultiplied

Incorrect handling of RGB associated values will result in similar over-darkening. While the overall visual result looks similar, the reason behind it isn't. Selecting "Premultiply" via the properties panel associates the alpha with the RGB values. In simple terms, this will multiply the alpha by the RGB values. This in precisely why the image will appear to darken on the semi-transparent pixels.

When should I toggle this button on?

This will depend on need and file format. As a general rule, know what format your alpha and RGB values are in prior to loading in Blender. This button shouldn't impact your compositing if you are aware of your alpha and RGB states. Do not toggle this option on if your RGB values are already associated.

What happens if I use it incorrectly?

Your image will become forcibly associated. In plain terms, this will multiply the alpha by the RGB values. If your image happens to already be associated, the image will be corrupted with a doubled up association. This is the classic over-darkening that many see in semi-transparent areas.

Again, an image speaks volumes. The following is the result for an image containing associated alpha:

Comparison of Linearization Orders

Arrgh. My new | old Blender images look odd! I'm still confused!

When linearization landed in Blender, there was no accounting for correctness of associated alpha images. This means that every single nonlinear image saved out of Blender was fundamentally broken. The following is a loose set of guidelines to achieve correctness on those older files as well as some tips for new files.

A Great Huge Warning

Blender is a powerful application. It does not force you to abide by specifications and can result in strangely mangled alpha channel files. The bottom line is that currently it is up to an artist to be aware of the specifications and create correct alpha accordingly.

PNG

The PNG Problem

The PNG specification states that alpha must be unassociated. If you have created a file that contains manual association of alpha with RGB values and saved it from Blender, you may not be able to open it with correct values in any other imaging application.

The PNG Solution

Take care to assert that your alpha and RGB values are unassociated before saving them from Blender. If you have already created incorrect PNGs from Blender, load them and unassociate the alpha via a manual divide or other technique and re-save as a PNG.

TIFF

The TIFF Problem

If you have saved previous images out of older versions of Blender prior to the predivide technique above, your images will be inherently mangled.

The TIFF Solution

The correct method to repair a broken TIFF with alpha would be to load it into Blender without Predivide selected. While an incorrect technique, this will effectively repair the broken TIFF within Blender. From there, you should select "Color Unpremultiply" from the Shading panel for saving output. Also note the warning on output alpha above. The specification for TIFF states that the default alpha channel should be associated alpha[2]. There is an extra flag that can indicate an unassociated opacity channel, but Blender is incapable of saving nor loading that channel.

EXR

EXRs store their data in a linear format. It is the closest format to Blender's internal representation of 32 bit per channel linear float.

The EXR Problem

Many view file formats as equivalent. Nothing could be further from the truth. With EXRs, Blender will not perform any linearization to the RGB values and this may cause confusion in conjunction with the above discussion regarding predivide.

The EXR solution

The concerns over pre-linearization predivide should not impact files stored in EXR format. However, the associated / unassociated alpha complexities will remain, as the EXR specification permits storage of alpha and RGB in either associated or unassociated alpha format. This again implies that the artist should be aware of the internal alpha representation for all of their assets.

TL; DR

Compositing is a nuanced art form. Be careful with your alpha / RGB combinations and pay attention to your file formats. Both unassociated and associated alpha / RGB fill different roles and needs in pipelines, and it is up to an artist to know the details of application.