obsproject / obs-studio Public
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement non-default blending modes #5448
base: master
Are you sure you want to change the base?
Conversation
|
Thank you for putting in the effort to create this PR! I expect this will require extensive testing on Windows and Linux as they have sources that behave differently from macOS. Downloads: |
|
Thanks for testing @WizardCM ! I'm glad to see it's working on windows/d3d11. And yes, I had noticed some visual differences when comparing the results of the blending modes I've added, to those in Krita (Photoshop alternative) and Natron (Nuke alternative). I think the visual differences were down to either:
Instead of matching the blending mode names/behaviour to other apps, I aimed to match the results numerically to those described here, according to which ones I was able to implement using the programmable blending pipeline for both OpenGL and d3d11. I think the best way to ensure that the modes I've implemented are numerically correct, is to devise some kind of "test image" (similar to the rainbow + rubber duck image from the above docs, and my original forum post), and to compare the results of blending on the test image in OBS to results calculated mathematically (I'll try to think of something). |
|
Chiming in to say thank you for this work! |
|
thank you for this work! I was just looking for this feature, and it's cool that you've started work on this so recently. on Windows, the Additive, Subtractive, Darken, and Lighten modes work, but when I use Screen or Multiplicative, the image becomes invisible. here are the Windows screenshots you requested for your test: As you can see, "Screen" and "Multiply" show only the background image. if I drag the foreground image around, it just appears as a fully transparent box. poking around in the code, it seems like the issue seems to be with any blend modes that use |
|
oh! once the issues are resolved, I also might suggest adding "Soft Additive" and "2x Multiply". I believe these would be defined as: //Soft Additive
{
GS_BLEND_INVDSTCOLOR,
GS_BLEND_ONE,
GS_BLEND_OP_ADD,
}and //2x Multiply
{
GS_BLEND_DSTCOLOR,
GS_BLEND_SRCCOLOR,
GS_BLEND_OP_ADD,
}(these are adapted from the "Common blend types" section on this page: https://docs.unity3d.com/Manual/SL-Blend.html) |
|
Hi @awwbees, thanks for testing this! I'm not too sure why the Screen and Multiply blending modes are not working on Windows - all of the blending modes use the same functions for setting up the blending state, so there's very little that should go wrong between the different blending modes, but I'll try and reproduce it next time I'm able to access a Windows machine. Would you be able to post a log file from your OBS session? I presume the problem is limited to the d3d11 implementation, but I believe OBS can run on either d3d11 or OpenGL under Windows(?), so it'd be good to check. It may also be worth testing these modes with different images, or different source types. Here's some screenshots of the two additional blending modes you suggested, Soft Additive: Soft additive seems to produce the same result as my implementation of Screen, though I believe they should be different (Screen is implemented as I was able to workaround this in the regular Multiply mode by setting the destination blend factor to I'll leave it up to someone else to decide whether we should add these two additional modes - I've intentionally left out a few modes that could be implemented (divide, inverse-divide, reverse-subtract) as I didn't want to introduce too many new options, and some modes have limited practical use. |
sure thing! I'm new to the world of OBS dev... is there a doc on how to do this? or maybe you just want me to post stdout? |
|
@awwbees I'm not sure how to access it on windows, but it should be available from the toolbar/menubar: |
|
aha! yes, the log certainly looks relevant: and I switched over to opengl and thing appear to function correctly, save for some weirdness at the edges in Multiply: I tried to build in Debug mode to see if I could learn more about the "Failed to create blend state" errors, but I hit some linker errors, looks like I'd need to futz with my config to get Debug working. but, in my case, switching over to opengl appears to be a sufficient solution to get what I want. |
|
although... "Screen" and "Additive" appear to look identical in all scenarios I've seen, so maybe something is still not right. |
Ah, that's useful - If it's hitting the codepath I expect it to, then error code 0x80070057 suggests invalid arguments are being passed to CreateBlendState. Fortunately there aren't too many parameters to this function, so it'll be a case of checking whether what's being set in libobs-d3d11/d3d11-subsystem.cpp:gs_device::AddBlendState makes sense - I'll try and get OBS building on a windows machine and take a look. Thanks again for your help! |
|
Ok, I think I've got a lead on what the issue is (which thankfully won't require me to set up an OBS build on windows to test): This github issue hits a suspiciously similar problem, and thankfully the solution is explained in the comments - we're setting an invalid blend factor for the I should be able to solve this by specifying the colour and alpha blend factors seperately in libobs/obs-scene.c:obs_blend_mode_params, which thankfully I'll be able to test on OpenGL |
|
one very minor bug I noticed: duplicating a layer doesn't duplicate its blend mode settings, it just defaults to "Normal". I'm not sure if this is indicative of other serialization issues. |






























Description
Implements non-default blending modes for sources, allowing for compositing functionality similar to Photoshop/Nuke etc.

The implemented blending modes are:
Screenshots of each mode's behaviour are available here.
Blending modes have been implemented to leverage the existing blend state functionality, so changes to allow the blending equation's operation type to be modified have been added. Each blending mode is a preset combination of the blending equation's source/destination factors and operation, so the number of modes implemented is somewhat limited. Non-default blending modes require scene items to be rendered to a texture (using the same render pipeline for non-default scale filtering modes), but are otherwise 'free' from a performance point of view.
Motivation and Context
How Has This Been Tested?
I've only tested these changes on macOS, cherry-picked onto this branch to allow me to build on my device. As such, the d3d11 changes are untested.
Blending mode settings have been tested in scene loading/saving.
Tested with image sources, media sources, window capture sources, and display capture sources.
Types of changes
Checklist:
The text was updated successfully, but these errors were encountered: