Blend modes are broken #75844

Closed
opened 2020-04-17 20:00:33 +02:00 by Richard Antalik · 55 comments

System Information
Operating system: Windows-10-10.0.18362-SP0 64 Bits
Graphics card: Radeon RX550/550 Series ATI Technologies Inc. 4.5.13587 Core Profile Context 20.4.1 26.20.15029.20013

Blender Version
Broken: version: 2.90 (sub 0), branch: arcpatch-D7314 (modified), commit date: 2020-04-17 15:25, hash: 0e2de2b212
Worked: Never

Short description of error
Output of various blend modes is different depending on whether byte or float image is blended
Right now I am not sure which result is correct (or if any)

In example file Blend is set to Linear burn with brush strength of 0.5 (I assume this will give brush pixels alpha of 0.5)

I have found this bug while working on D7314, so I can work on fixing blend modes as well, or at least I would like to be involved in how this will be fixed. Of course, if this is actually bug and not only me being dumb.

Exact steps for others to reproduce the error
#75844.blend

  • Open file
  • Paint both textures with pre-set brush

Result is different

As a consequence, some blend modes also work unexpected in the Video Sequence Editor, see #76376, #74440, #79333 for details.
Also note that this was once changed in fdee84fd56, so we are now in a "fix-for-fix" scenario...

**System Information** Operating system: Windows-10-10.0.18362-SP0 64 Bits Graphics card: Radeon RX550/550 Series ATI Technologies Inc. 4.5.13587 Core Profile Context 20.4.1 26.20.15029.20013 **Blender Version** Broken: version: 2.90 (sub 0), branch: arcpatch-[D7314](https://archive.blender.org/developer/D7314) (modified), commit date: 2020-04-17 15:25, hash: `0e2de2b212` Worked: Never **Short description of error** Output of various blend modes is different depending on whether byte or float image is blended Right now I am not sure which result is correct (or if any) In example file Blend is set to Linear burn with brush strength of 0.5 (I assume this will give brush pixels alpha of 0.5) I have found this bug while working on [D7314](https://archive.blender.org/developer/D7314), so I can work on fixing blend modes as well, or at least I would like to be involved in how this will be fixed. Of course, if this is actually bug and not only me being dumb. **Exact steps for others to reproduce the error** [#75844.blend](https://archive.blender.org/developer/F8479363/T75844.blend) - Open file - Paint both textures with pre-set brush Result is different As a consequence, some blend modes also work unexpected in the Video Sequence Editor, see #76376, #74440, #79333 for details. Also note that this was once changed in fdee84fd56, so we are now in a "fix-for-fix" scenario...
Author
Member

Added subscriber: @iss

Added subscriber: @iss

#88407 was marked as duplicate of this issue

#88407 was marked as duplicate of this issue

#86367 was marked as duplicate of this issue

#86367 was marked as duplicate of this issue

#85996 was marked as duplicate of this issue

#85996 was marked as duplicate of this issue

#79333 was marked as duplicate of this issue

#79333 was marked as duplicate of this issue

#74440 was marked as duplicate of this issue

#74440 was marked as duplicate of this issue

#78727 was marked as duplicate of this issue

#78727 was marked as duplicate of this issue

Added subscriber: @brecht

Added subscriber: @brecht

There is also difference in color space, blending in sRGB or linear color will not give the same results.

There is also difference in color space, blending in sRGB or linear color will not give the same results.

Added subscriber: @RomanKornev

Added subscriber: @RomanKornev

Related #75875

Related #75875
Author
Member

In #75844#912453, @brecht wrote:
There is also difference in color space

Not really in example file you are comparing results in the same colorspace.

Math for blend_color_linearburn_byte():

      const int temp = max_ii(src1[i] + src2[i] - 255, 0);
      dst[i] = (uchar)((temp * fac + src1[i] * mfac) / 255);

And float blend_color_linearburn_float():

      const float temp = max_ff(src1[i] + src2[i] - 1.0f, 0.0f);
      dst[i] = (temp * fac + src1[i] * mfac);

Regardless of corectness, both should output consistent result within bounds precision.

Following texture paint code, color values of brush are multiplied by "Strength" or "blend factor" in IMB_rectblend(), but this will be done once again in blend_color_linearburn_float() so result is wrong.
With some tweaking(multiplying only alpha, but for input2) to VSE code - apply_blend_function_float() and using Color Mix strip, output of byte and float versions are consistent.

But then looking at blend_color_add_float() for example, src1- [x] is used for premultiplication. This very much looks like a mistake. Condition expression suggests that as well. Either src2- [x] should be used, or it should be assumed that src2 color is already mutiplied by "blend factor"

  if (src2[3] != 0.0f) {
    /* unpremul > add > premul, simplified */
    dst[0] = src1[0] + src2[0] * src1[3];
    dst[1] = src1[1] + src2[1] * src1[3];
    dst[2] = src1[2] + src2[2] * src1[3];
    dst[3] = src1[3];
  }

Resolution proposal:

  • Always apply "blend factor" to src2 and expect it there.
  • Decide if "blend factor" is applied in float blend functions or not. Is there convention for this?

Note: these functions seems to be only used for VSE and texture paint.

> In #75844#912453, @brecht wrote: > There is also difference in color space Not really in example file you are comparing results in the same colorspace. Math for `blend_color_linearburn_byte()`: ``` const int temp = max_ii(src1[i] + src2[i] - 255, 0); dst[i] = (uchar)((temp * fac + src1[i] * mfac) / 255); ``` And float `blend_color_linearburn_float()`: ``` const float temp = max_ff(src1[i] + src2[i] - 1.0f, 0.0f); dst[i] = (temp * fac + src1[i] * mfac); ``` Regardless of corectness, both should output consistent result within bounds precision. Following texture paint code, color values of brush are multiplied by "Strength" or "blend factor" in `IMB_rectblend()`, but this will be done once again in `blend_color_linearburn_float()` so result is wrong. With some tweaking(multiplying only alpha, but for input2) to VSE code - `apply_blend_function_float()` and using Color Mix strip, output of byte and float versions are consistent. But then looking at `blend_color_add_float()` for example, `src1- [x]` is used for premultiplication. This very much looks like a mistake. Condition expression suggests that as well. Either `src2- [x]` should be used, or it should be assumed that src2 color is already mutiplied by "blend factor" ``` if (src2[3] != 0.0f) { /* unpremul > add > premul, simplified */ dst[0] = src1[0] + src2[0] * src1[3]; dst[1] = src1[1] + src2[1] * src1[3]; dst[2] = src1[2] + src2[2] * src1[3]; dst[3] = src1[3]; } ``` Resolution proposal: - Always apply "blend factor" to `src2` and expect it there. - Decide if "blend factor" is applied in float blend functions or not. Is there convention for this? Note: these functions seems to be only used for VSE and texture paint.
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Member

I guess this can be confirmed.

I guess this can be confirmed.

Added subscriber: @jehan

Added subscriber: @jehan
Author
Member

Added subscribers: @Aryeom, @Sergey, @Jeroen-Bakker

Added subscribers: @Aryeom, @Sergey, @Jeroen-Bakker
Member

Added subscribers: @tintwotin, @XB982

Added subscribers: @tintwotin, @XB982
Member

Added subscriber: @febby

Added subscriber: @febby
Member

And since this is a regression in a way (partially caused by fdee84fd56) I dare setting this to High -- @iss, correct me if I am wrong...

And since this is a regression in a way (partially caused by fdee84fd56) I dare setting this to High -- @iss, correct me if I am wrong...

Removed subscriber: @tintwotin

Removed subscriber: @tintwotin

A detailed analyse of effect strips and strip settings duplicates(and defunct blend modes and other bugs):
https://devtalk.blender.org/t/design-proposal-effect-strips-vs-strip-settings/11987

On top of this, most effect strips doesn't seem to be multi-threaded:
https://blender.community/c/rightclickselect/QLfbbc/

A detailed analyse of effect strips and strip settings duplicates(and defunct blend modes and other bugs): https://devtalk.blender.org/t/design-proposal-effect-strips-vs-strip-settings/11987 On top of this, most effect strips doesn't seem to be multi-threaded: https://blender.community/c/rightclickselect/QLfbbc/
Author
Member

In #75844#986479, @lichtwerk wrote:
And since this is a regression in a way (partially caused by fdee84fd56) I dare setting this to High -- @iss, correct me if I am wrong...

I mean it is core functionality, that is broken, but it is broken for quite some time. I will try to fix this soon

> In #75844#986479, @lichtwerk wrote: > And since this is a regression in a way (partially caused by fdee84fd56) I dare setting this to High -- @iss, correct me if I am wrong... I mean it is core functionality, that is broken, but it is broken for quite some time. I will try to fix this soon
Richard Antalik self-assigned this 2020-08-10 11:16:59 +02:00

@iss, do you think fixing this issue is something doable/safe for 2.90?

@iss, do you think fixing this issue is something doable/safe for 2.90?
Author
Member

In #75844#993763, @Sergey wrote:
@iss, do you think fixing this issue is something doable/safe for 2.90?

I think so, will continue with fix today or tomorrow and see how review will go. I don't think it would be catastrophic if it gets committed only in 2.91 though.

> In #75844#993763, @Sergey wrote: > @iss, do you think fixing this issue is something doable/safe for 2.90? I think so, will continue with fix today or tomorrow and see how review will go. I don't think it would be catastrophic if it gets committed only in 2.91 though.

Ok, for now putting to 2.90 workboard.
If the fix goes deeper or requires more time, will re-schedule the release and priority.

Ok, for now putting to 2.90 workboard. If the fix goes deeper or requires more time, will re-schedule the release and priority.
Contributor

Added subscriber: @Gilberto.R

Added subscriber: @Gilberto.R

Thanks for working on this.
Will the fix also take care of the common non-linear blending issue?
Currently in blender, with alpha over blend mode and with a gaussian blur effect :
blur black silhouette.jpg

Thanks for working on this. Will the fix also take care of the common non-linear blending issue? Currently in blender, with alpha over blend mode and with a gaussian blur effect : ![blur black silhouette.jpg](https://archive.blender.org/developer/F9088596/blur_black_silhouette.jpg)
Member

Added subscriber: @EAW

Added subscriber: @EAW
Member

Added subscribers: @Gurra, @mano-wii, @tintwotin

Added subscribers: @Gurra, @mano-wii, @tintwotin
Member

Added subscriber: @DMan

Added subscriber: @DMan
Member

@iss: did you have a chance to give this another look?

@iss: did you have a chance to give this another look?
Member

Added subscriber: @DragonLEE

Added subscriber: @DragonLEE
Member

Yet another release with this in...

Yet another release with this in...
UPBGE version working https://dev-files.blender.org/file/data/annrdtbtae7neo4zestd/PHID-FILE-yf6umhiziguhfmepqtdl/Blend_Modes.jpg

Added subscriber: @Harti

Added subscriber: @Harti

Now that is a sad story overall.

Now that is a sad story overall.

Added subscriber: @jc4d

Added subscriber: @jc4d

Hi, it's still broken in 2.93.4.

Hi, it's still broken in 2.93.4.

And, for that matter, in 3.0.0 (2021-09-29, 367775ac6a)

In #75844#1228187, @jc4d wrote:
Hi, it's still broken in 2.93.4.

And, for that matter, in 3.0.0 (2021-09-29, 367775ac6a2d) > In #75844#1228187, @jc4d wrote: > Hi, it's still broken in 2.93.4.

Added subscriber: @jenkm

Added subscriber: @jenkm

Added subscriber: @Tora-Victoria

Added subscriber: @Tora-Victoria

Still broken in 3.0

Only possible to adjust opacity in cross - not in difference, add etc. Just kicks in - no transition.

Still broken in 3.0 Only possible to adjust opacity in cross - not in difference, add etc. Just kicks in - no transition.

As I wrote in September, it didn't work for me either in 3.0.0, but it seems to be finally working now in today's build of 3.1.0.

As I wrote in September, it didn't work for me either in 3.0.0, but it seems to be finally working now in today's build of 3.1.0.

Well I am using 3.1.0 Alpha and the transition is not working there - just kicks in, no transition if you choose other than cross blending mode

Well I am using 3.1.0 Alpha and the transition is not working there - just kicks in, no transition if you choose other than cross blending mode

Have you tried building it today? I'm on 3.1.0 Alpha (2022-01-02, 8be217ada5) on Linux, and for the first time ever Overlay, Difference, Add, etc. do come in gradually, instead of just 'kicking in,' like you say.

Have you tried building it today? I'm on 3.1.0 Alpha (2022-01-02, 8be217ada575) on Linux, and for the first time ever Overlay, Difference, Add, etc. do come in gradually, instead of just 'kicking in,' like you say.

I should perhaps say that I am checking this in the VSE, perhaps this hasn't been fixed in other places where blend modes are used...

I should perhaps say that I am checking this in the VSE, perhaps this hasn't been fixed in other places where blend modes are used...

I am using mac and video editing. I just tried this today. Using Blender as VSE for the first time coming from Premiere.

I am using mac and video editing. I just tried this today. Using Blender as VSE for the first time coming from Premiere.
Author
Member

I have fixed issue with blend factor few days ago, there are still some issues though so I haven't closed this task yet. For most cases this could be considered as resolved in 3.1 alpha.

I will add more fixes and close soon.

I have fixed issue with blend factor few days ago, there are still some issues though so I haven't closed this task yet. For most cases this could be considered as resolved in 3.1 alpha. I will add more fixes and close soon.
Author
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Author
Member

I have pushed fixes to resolve blending issues:
bdcc258305
9c85acf61d
d2cc672b0c

In addition, I have added visual tests to SVN with what I think is good state and also reference images made with GIMP - rBL62783.

There are differences between byte and float blend modes still, but this is mostly due to way how color values and alpha are handled internally - Linear premultiplied vs sRGB straight.

Running tests with GIMP image results as reference will also reveal differences, but this seems to be due to how values are handled there. I would expect EXR's to blend exacly in these 2 programs, but they do not even if blend functions use same formula, so this is not issue with blend modes.

I have pushed fixes to resolve blending issues: bdcc258305 9c85acf61d d2cc672b0c In addition, I have added visual tests to SVN with what I think is good state and also reference images made with GIMP - rBL62783. There are differences between byte and float blend modes still, but this is mostly due to way how color values and alpha are handled internally - Linear premultiplied vs sRGB straight. Running tests with GIMP image results as reference will also reveal differences, but this seems to be due to how values are handled there. I would expect EXR's to blend exacly in these 2 programs, but they do not even if blend functions use same formula, so this is not issue with blend modes.

Hi Richard

Perhaps I was not clear about the blend issue. I lust downloaded the newest version of Blender 3.1.0 Alpha and tested the blend feature. Now when loading in images in VSE images are loaded in as Alpha Over. The Alpha Over works fine per se, as do all the other blending modes. The issue here is that only the Alpha Over and Cross blending modes can be animated and get a transition - all the other modes are still either on or off. The transition is still not working. So the issue is not solved.

Tested on a mac with PNG and JPG images.

Hi Richard Perhaps I was not clear about the blend issue. I lust downloaded the newest version of Blender 3.1.0 Alpha and tested the blend feature. Now when loading in images in VSE images are loaded in as Alpha Over. The Alpha Over works fine per se, as do all the other blending modes. The issue here is that only the Alpha Over and Cross blending modes can be animated and get a transition - all the other modes are still either on or off. The transition is still not working. So the issue is not solved. Tested on a mac with PNG and JPG images.
Author
Member

@Tora-Victoria I would recommend to make new report. Please share build hash (When you click on Help > Report a Bug it will be filled automatically) attach blend file with 2 color strips not blending properly or images if you want. Testing with ea8d749587 I can't see any issues with blend modes in side panel or using colormix effect. So not sure if I am checking same issue as you.

@Tora-Victoria I would recommend to make new report. Please share build hash (When you click on Help > Report a Bug it will be filled automatically) attach blend file with 2 color strips not blending properly or images if you want. Testing with ea8d749587dd I can't see any issues with blend modes in side panel or using colormix effect. So not sure if I am checking same issue as you.

I´ll do that - cheers

I´ll do that - cheers

Here is the link if you would like to read my report on the issue:

https://developer.blender.org/T94625

Here is the link if you would like to read my report on the issue: https://developer.blender.org/T94625
Thomas Dinges added this to the 2.93 LTS milestone 2023-02-07 18:46:39 +01:00
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
17 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#75844
No description provided.