BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.25k stars 4.61k forks source link

Issue with blend filters and GPUImageSolidColorGenerator #1257

Open ShayDavidson opened 11 years ago

ShayDavidson commented 11 years ago

I'm trying to create filter which uses a Multiply blend filter with an image output and a color layer with a certain alpha ('translated' to Photoshop, imagine I have a single-colored layer at X% opacity, set to Multiply blend mode on top of another layer).

I'm using this code:

+ (GPUImageOutput*)colorMultiplyBlendFilter:(GPUImageOutput*)output color:(UIColor*)color {

    GPUImageSolidColorGenerator *solidColor = [GPUImageSolidColorGenerator new];
    [solidColor setColorRed:color.red green:color.green blue:color.blue alpha:COLOR_ALPHA];
    [output addTarget:solidColor];

    GPUImageTwoInputFilter* blendFilter = [GPUImageMultiplyBlendFilter new];
    [output blendFilter];
    [solidColor blendFilter];

    return blendFilter;
}

The problem was that the multiply effect with the color is too bright or saturated. So I played a bit with the alpha, and found out that even if COLOR_ALPHA is 0.0f the output still gets colored a tiny bit and hence the brightness I saw earlier.

Notice I'm using the initial output itself as a source for the single color filter (so its output will be at the same size of the initial output).

I'm probably doing something wrong and there's a better way to achieve this, but I can't find any.

yudun1989 commented 10 years ago

I have the same problem. i've changed the alpha value but seems not work after blend with other pics

BradLarson commented 10 years ago

Try changing the line

    gl_FragColor = overlayer * base + overlayer * (1.0 - base.a) + base * (1.0 - overlayer.a);

to

    gl_FragColor = (overlayer * base.a) * (base * overlayer.a) + overlayer * (1.0 - base.a) + base * (1.0 - overlayer.a);

in GPUImageMultiplyBlendFilter.m and see if that makes things better. If so, I can tweak the shaders in the framework.

SteveLiddell commented 9 years ago

This fixes the issue for me - i'd love for this to be implemented on the other shaders too if possible. Many thanks.

SteveLiddell commented 9 years ago

If there is anyone out there that is able to help with this (Brad?). I have some budget for a paid solution (that can be added to the open source project if Brad wants it)