Alpha channel color output #53265

Closed
opened 2017-11-07 20:28:42 +01:00 by Konstantins Visnevskis · 10 comments

System Information
Win8.1x64, 3x gtx580

Blender Version
2.79

Short description of error
For the long time I was wondering why is it impossible to render alpha-translucent colors in blender. It seemed like an obvious case of incorrect choice of premultiplication on my part, however regardless of what nodes or math I applied to output channels, the best I could do was faking it to look less prominent for each particular case.

So now I tried just outputting pure rgba(1, .5, .25, .25). Which in render view and upon saving gets outputted as a pure grey (or white with <1 alpha). This happens after all the node transformations have been done as in the nodes the color is recoverable, however once if it gets to "composite" view and/or saving, some color transformation gets applied affecting colors by intermediate alpha values. I get that color space transformations are unavoidable, however no possible transformation leading to particular result can be right.

Switching "View" color space from default/raw to others produces seemingly correct result for respective color spaces, but default/raw output, desaturates colors of low-intermediate alpha for some reason.

Not sure if somehow relevant - the Alpha Over compositing node produces alike result before even composite if the render image is being composited over a zero-alpha-white, while keeping everything intact over zero-alpha-black. That is - final output in semi transparent areas acts as if the image was composited over zero-alpha-white or gray before viewing/saving.

Exact steps for others to reproduce the error
color.blend

  • Render -> output is grey
**System Information** Win8.1x64, 3x gtx580 **Blender Version** 2.79 **Short description of error** For the long time I was wondering why is it impossible to render alpha-translucent colors in blender. It seemed like an obvious case of incorrect choice of premultiplication on my part, however regardless of what nodes or math I applied to output channels, the best I could do was faking it to look less prominent for each particular case. So now I tried just outputting pure rgba(1, .5, .25, .25). Which in render view and upon saving gets outputted as a pure grey (or white with <1 alpha). This happens after all the node transformations have been done as in the nodes the color is recoverable, however once if it gets to "composite" view and/or saving, some color transformation gets applied affecting colors by intermediate alpha values. I get that color space transformations are unavoidable, however no possible transformation leading to particular result can be right. Switching "View" color space from default/raw to others produces seemingly correct result for respective color spaces, but default/raw output, desaturates colors of low-intermediate alpha for some reason. Not sure if somehow relevant - the Alpha Over compositing node produces alike result before even composite if the render image is being composited over a zero-alpha-white, while keeping everything intact over zero-alpha-black. That is - final output in semi transparent areas acts as if the image was composited over zero-alpha-white or gray before viewing/saving. **Exact steps for others to reproduce the error** [color.blend](https://archive.blender.org/developer/F1103282/color.blend) - Render -> output is grey

Changed status to: 'Open'

Changed status to: 'Open'

Added subscriber: @KonstantinsVisnevskis

Added subscriber: @KonstantinsVisnevskis

Added subscriber: @brecht

Added subscriber: @brecht

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Brecht Van Lommel self-assigned this 2017-11-12 20:20:35 +01:00

There's no bug here as far as I can tell, but some more user control would be good. See also the discussion in #52680.

Fundamentally, it is impossible to do correct color management on images with alpha. Only when the background color is known can this be done, so when doing color management on such images Blender does a kind of thing that looks OK-ish on most backgrounds but is now quite correctly. Better may be to make some setting for this, there is no way to always automatically do the expected thing.

Further, Blender rendering and compositing works with premultiplied alpha. That means a color like (1, .5, .25, .25) is interpreted as (4, 2, 1) without alpha, and such very bright values get clipped by the default view transform. A different view transform can better preserve such HDR colors.

There's no bug here as far as I can tell, but some more user control would be good. See also the discussion in #52680. Fundamentally, it is impossible to do correct color management on images with alpha. Only when the background color is known can this be done, so when doing color management on such images Blender does a kind of thing that looks OK-ish on most backgrounds but is now quite correctly. Better may be to make some setting for this, there is no way to always automatically do the expected thing. Further, Blender rendering and compositing works with premultiplied alpha. That means a color like (1, .5, .25, .25) is interpreted as (4, 2, 1) without alpha, and such very bright values get clipped by the default view transform. A different view transform can better preserve such HDR colors.

Thanks for the link and I understand the problems with background-color/premultiplication, but it seems taken a bit to extreme.
Whether the render layer is being passed into compositing premultiplied or not is a matter of preference, as long as it's consistent, but unless I fail to see something else, explicit values and channel transforms shouldn't be affected by any post processing "behind the scenes" before final output.
That is - nodes like "Combine RGBA" (maybe Color Input) shouldn't do any post-processing on values passed to them. In contrast, a "Set Alpha" node can be expected to do premultiplication as the user just expects it to work within given color system (which as you said is premultiplied), but nodes like "Separate/Combine RGBA" imply and are needed so that manual transforms can be made. And, I mean - it's not exactly manual, if it's being automatically transformed on the spot :)
Sure it'd be great to have a fancy "unpremultiplied" checkbox here and there, but given there are options to do something alike to math on channels, there should be no obstacle to output anything imaginable without the checkbox, by doing manually at least.

Edit: said is valid at least for alpha. I do realize colors can get very non-linear and basically unmanageable by average user, but that shouldn't be the case for alpha.

Thanks for the link and I understand the problems with background-color/premultiplication, but it seems taken a bit to extreme. Whether the render layer is being passed into compositing premultiplied or not is a matter of preference, as long as it's consistent, but unless I fail to see something else, explicit values and channel transforms shouldn't be affected by any post processing "behind the scenes" before final output. That is - nodes like "Combine RGBA" (maybe Color Input) shouldn't do any post-processing on values passed to them. In contrast, a "Set Alpha" node can be expected to do premultiplication as the user just expects it to work within given color system (which as you said is premultiplied), but nodes like "Separate/Combine RGBA" imply and are needed so that manual transforms can be made. And, I mean - it's not exactly manual, if it's being automatically transformed on the spot :) Sure it'd be great to have a fancy "unpremultiplied" checkbox here and there, but given there are options to do something alike to math on channels, there should be no obstacle to output anything imaginable without the checkbox, by doing manually at least. Edit: said is valid at least for alpha. I do realize colors can get very non-linear and basically unmanageable by average user, but that shouldn't be the case for alpha.

There is no post processing on the Combined RGBA colors, it assumes premultiplied RGBA as input and passes those values straight on. In the render you are mixing with a Transparent BSDF, which changes the RGBA values going into the compositor, multiplying the RGB value from emission by 0.25.

Maybe you are expecting the Combine RGBA node to multiply the RGB values by A = 0.25 automatically? The problem with doing that is that chaining Separate and Combine RGBA will then alter the RGBA values.

There is no post processing on the Combined RGBA colors, it assumes premultiplied RGBA as input and passes those values straight on. In the render you are mixing with a Transparent BSDF, which changes the RGBA values going into the compositor, multiplying the RGB value from emission by 0.25. Maybe you are expecting the Combine RGBA node to multiply the RGB values by A = 0.25 automatically? The problem with doing that is that chaining Separate and Combine RGBA will then alter the RGBA values.

BSDF transparency is another can of worms I wouldn't touch. I was referring to input value of rgba(1, 0.5, 0.25, 0.25) fed directly into compositing Combine RGBA, resulting in grey (transparent white) output (at least in the output file), which I though from your comment is due to clipping of premultiplication. Which it seems shouldn't happen.

BSDF transparency is another can of worms I wouldn't touch. I was referring to input value of rgba(1, 0.5, 0.25, 0.25) fed directly into compositing Combine RGBA, resulting in grey (transparent white) output (at least in the output file), which I though from your comment is due to clipping of premultiplication. Which it seems shouldn't happen.

It's not the premultiplication that clips it, but the color management view transform, which works on the unpremultiplied (1/0.25, 0.5/0.25, 0.25/0.25) = (4, 2, 1) values.

It's not the premultiplication that clips it, but the color management view transform, which works on the unpremultiplied (1/0.25, 0.5/0.25, 0.25/0.25) = (4, 2, 1) values.

Thanks for patient replies!

If anyone ends up here trying to render transparency+emission glowy-thingy layer with alpha, the way it looks without alpha (on black),
here's the node setup that may help outputting something closer:
color2.blend
Works for transparency+emission shaders only. The idea is to use pixel's hsv(value) as alpha as it closer matches material's emissivity (needs to go through gamma of about 0.5 for external software). Setting hsv(value) to >1 to lose transparency color attenuation and multiplying resulting r,g,b with alpha to counter view transform premultiplication. A bit of cheating with curves, can be disabled. Matches default input of GIMP, AE.
Won't look like transparency in viewport exactly as the checker bg is brighter, but it's close.

Thanks for patient replies! If anyone ends up here trying to render transparency+emission glowy-thingy layer with alpha, the way it looks without alpha (on black), here's the node setup that may help outputting something closer: [color2.blend](https://archive.blender.org/developer/F1131084/color2.blend) Works for transparency+emission shaders only. The idea is to use pixel's hsv(value) as alpha as it closer matches material's emissivity (needs to go through gamma of about 0.5 for external software). Setting hsv(value) to >1 to lose transparency color attenuation and multiplying resulting r,g,b with alpha to counter view transform premultiplication. A bit of cheating with curves, can be disabled. Matches default input of GIMP, AE. Won't look like transparency in viewport exactly as the checker bg is brighter, but it's close.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#53265
No description provided.