Closed FiniteSingularity closed 8 months ago
This PR should fix #11 and #30
Also, you can test the difference in color. Grab a source, apply a color correction to it and set the alpha to 0.5. Then after the color correction filter, add a user defined shader (with just the default passthrough shader). The colors should remain unchanged (this is the new behavior).
Now, at the top of your user defined shader text, add #define USE_PM_ALPHA 1
. You should notice the colors darken a bit. This is the old behavior.
In the rendering pipeline, OBS passes color values with pre-multiplied alpha to filters. This can cause issues with custom shaders, if the input source has intermediate (translucent) alpha values, and causes the colors of the source to darken in the shader.
This PR changes the rendering process of shaderfilter to first grab the input texture using OBS's
DrawAlphaDivide
pass-through shader to undo the alpha pre-multiplication. This new input texture is then passed through the custom shader, and finally is rendered out to the source chain with a newdraw_output
function.Since there are existing custom shaders where users have correct for pre-multiplied alpha in their shader, there is also a new pre-processor macro:
#define USE_PM_ALPHA 1
that turns off this correction. For those shaders that have internally corrected, this will be a breaking change, as they will need to either remove the code that corrects for pre-multiplied alpha, or they will need to add#define USE_PM_ALPHA 1
near the top of their shader file.Finally, this PR updates the readme file to give some documentation on the basic pre-processor macros available:
#include
,#define
, and#define USE_PM_ALPHA 1
.