Skip to content

Blending mode Darken makes transparency solid black #6591

Closed as not planned
Closed as not planned

Description

@SuslikV

Operating System Info

Other

Other OS

Any OS

OBS Studio Version

Git

OBS Studio Version (Other)

29782cd

OBS Studio Log URL

about:blank

OBS Studio Crash Log URL

No response

Expected Behavior

Blending mode Darken shouldn't touch transparent areas of the source when the effect applied.

Current Behavior

When Blending mode Darken applied to the source the transparent areas of the source turns solid black.

  1. Image source (PNG image with alpha):
    Blending test
    Blending Mode->Darken
  2. placed over the solid Color source: #d1d1d1
  3. results in the wrong rendering (black color where the transparency was):
    OBS de11632a9 Blending Screenshot

Steps to Reproduce

  1. Add new Color source
  2. Add PNG image with transparency as source and place it over the Color source (from p1)
  3. Right-click over the image source (from p2) and select Blending Mode->Darken

Observe like any transparency of the source (p2) in the preview of OBS turns solid black.

Anything else we should know?

Developers aware of the issue, it was mentioned in the:
#5448 (comment)
https://obsproject.com/forum/threads/source-blending-modes.148443/#post-542783
Let's hope it will be tracked a bit better now.

Image editors (like GIMP): produces correct picture (the Darken blending applied for the upper layer, here the result is nonlinear):
Blending Darken expected result

Note: If you don't have any picture with alpha - use Text (GDI+) source - it has transparency by default.

Activity

  1. jpark37 commented on Jun 5, 2022

    @jpark37
    Contributor

    The alpha-correct versions of darken/lighten require an extra draw because they can't be expressed with a standard fixed-function blend. It's doable, but it's not just swapping in the correct the blend enum values.

    From https://www.w3.org/TR/SVGCompositing/

    Sca: Premultiplied source color component
    Sa: Source opacity component
    Dca: Premultiplied destination color component
    Da: Destination opacity component

    Darken

    Dca' = min(Sca × Da, Dca × Sa) + Sca × (1 - Da) + Dca × (1 - Sa)
    Da'  = Sa + Da - Sa × Da 
    

    Ligthen

    Dca' = max(Sca × Da, Dca × Sa) + Sca × (1 - Da) + Dca × (1 - Sa)
    Da'  = Sa + Da - Sa × Da 
    
  2. Bombe commented on Oct 15, 2022

    @Bombe

    It doesn’t only happen with Darken, Normal is also affected by this. I have a scene that contains a browser source with transparent background color (via custom CSS) and in older versions (pre-27, I think) that transparency was applied as expected when the scene was included in other scenes but since 27 (again, I think it was 27) I have to choose blend mode “Screen” to get the same effect.

  3. jpark37 commented on Oct 16, 2022

    @jpark37
    Contributor

    I have a scene that contains a browser source

    This ticket is about a blend mode situation that OBS doesn't fully support. Your issue is likely that OBS had changed alpha blending to be performed linearly, which web browsers do not.

    If you are on OBS 28, you can get "web" blending behavior by selecting Blending Method -> SRGB Off from the source context menu. If you need more help, this ticket probably isn't the place for it.

  4. RytoEX commented on Jan 27, 2023

    @RytoEX
    Member

    cc @jw0z96 since they implemented the feature.

    As far as I understand it, this would require implementing an extra render to texture to make this work as desired, and that work is non-trivial.

  5. jw0z96 commented on Feb 4, 2023

    @jw0z96
    Contributor

    I've not given it too much thought, but you'd probably need to re-implement the blending equations in a fragment shader to overcome the limitations of trying to express this functionality with fixed-function blending - which would require an extra draw, and for both the source and the scene/background to be available for texture sampling. The latter would likely require a non-trivial rework of the scene rendering pipeline in order for the previously rendered parts of the background to be rendered to texture.

    It looks like render to texture is already enabled for sources using non-default blending, but I'm not sure how you'd achieve the same for the scene/background.

    cc @jpark37 In case they have any suggestions for how this could be achieved

  6. jpark37 commented on Feb 4, 2023

    @jpark37
    Contributor

    It's pretty much what you would think. Need to modify obs-scene.c and friends to do the extra draw with a custom shader, perhaps modifying default.effect to add a new technique, and tweaking the blend state. It's more work than I want to bite off to implement and regression test for a feature that I'm not personally interested in on a project that's just a hobby for me.

  7. RytoEX commented on Feb 6, 2023

    @RytoEX
    Member

    I've not given it too much thought, but you'd probably need to re-implement the blending equations in a fragment shader to overcome the limitations of trying to express this functionality with fixed-function blending - which would require an extra draw, and for both the source and the scene/background to be available for texture sampling. The latter would likely require a non-trivial rework of the scene rendering pipeline in order for the previously rendered parts of the background to be rendered to texture.

    It looks like render to texture is already enabled for sources using non-default blending, but I'm not sure how you'd achieve the same for the scene/background.

    It's starting to sound like this is, for better or worse, "working as intended/designed" and that would make this a feature request rather than a bug.

  8. jw0z96 commented on Feb 6, 2023

    @jw0z96
    Contributor

    I'd say there's still a bug here, given that users expect behaviour comparable to photoshop etc. when using the 'darken' blending mode on sources with transparency, but it's probably "working as expected" given the limitations of the current implementation.

    Implementing blending in the way discussed in this thread makes the implementation of this feature a lot more complex (in comparison to my original PR, which was pretty tiny), and as far as i'm aware would only really benefit a narrow set of use cases.

  9. RytoEX commented on Feb 13, 2023

    @RytoEX
    Member

    it's probably "working as expected" given the limitations of the current implementation.

    If it is working as designed/implemented, and I understand that that is the case, then I'm going to close this. It is unfortunate that user expectations, when compared to how this works in web browsers or other software, does not align with the functionality in OBS, but OBS is not a web browser. If someone wants to expand the implementation, they are free to do so and open a Pull Request.

  10. SuslikV commented on Mar 1, 2023

    @SuslikV
    ContributorAuthor

    Better to hide the feature from the user, than leave it faulty.

    Few thoughts below.
    The "Dark" - is only effect that has impact on transparency.
    You can always add feature later.

    q:

    1. Who will use faulty feature?
    2. How often the mentioned effects are used by users in OBS?
    3. Who asked for the feature and where it helpful?

    answ:

    1. Not me.
    2. Better to prepare all assets ("flat" them) before running the stream. "Live/realtime" effects always slower.
    3. Watermarking? I cannot find better answer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions