使用GPUImage
我正嘗試複製具有不透明度的Photoshop Lighten混合模式。不幸的是,alpha通道使用GPUImageLightenBlendFilter
沒有效果。帶不透明度的GPUImageLightenBlendFilter
布拉德證實有可能與阿爾法問題: GPUImage's GPUImageOpacityFilter not behaving as expected, doesn't change alpha channel
我已經成功地複製使用CoreImage
,尊重Alpha值PS混合。
CIImage *ciImage1 = [[CIImage alloc] initWithImage:input1];
CIImage *ciImage2 = [[CIImage alloc] initWithImage:input2];
// Alpha adjustment for input1
CIFilter *alphaFilter = [CIFilter filterWithName:@"CIColorMatrix"];
CGFloat rgba[4] = { 0.0, 0.0, 0.0, 0.5 };
CIVector *alphaVector = [CIVector vectorWithValues:rgba count:4];
[alphaFilter setValue:alphaVector forKey:@"inputAVector"];
[alphaFilter setValue:ciImage1 forKey:kCIInputImageKey];
// Lighten blend
CIFilter *blendFilter = [CIFilter filterWithName:@"CILightenBlendMode"];
[blendFilter setValue:alphaFilter.outputImage forKey:kCIInputImageKey];
[blendFilter setValue:ciImage2 forKey:kCIInputBackgroundImageKey];
有很多GPUImage
2個版本我已經嘗試(他們使用不同的方法調整阿爾法input1
)。
GPUImagePicture *input1 = [[GPUImagePicture alloc] initWithImage:input1];
GPUImagePicture *input2 = [[GPUImagePicture alloc] initWithImage:input2];
// Alpha adjustment for input1
GPUImageOpacityFilter *alphaFilter = [GPUImageOpacityFilter new];
alphaFilter.opacity = 0.5;
[input1 addTarget:alphaFilter];
// Lighten blend
GPUImageLightenBlendFilter *blendFilter = [GPUImageLightenBlendFilter new];
[alphaFilter addTarget:blendFilter];
[input2 addTarget:blendFilter];
或:
GPUImagePicture *input1 = [[GPUImagePicture alloc] initWithImage:input1];
GPUImagePicture *input2 = [[GPUImagePicture alloc] initWithImage:input2];
// Alpha adjustment for input1
GPUImageColorMatrixFilter *alphaFilter = [GPUImageColorMatrixFilter new];
alphaFilter.colorMatrix = (GPUMatrix4x4) {
{ 1.0, 0.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0, 0.0 },
{ 0.0, 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.5 }
};
[input1 addTarget:alphaFilter];
// Lighten blend
GPUImageLightenBlendFilter *blendFilter = [GPUImageLightenBlendFilter new];
[alphaFilter addTarget:blendFilter];
[input2 addTarget:blendFilter];
兩個GPUImage
實現返回輸出彷彿阿爾法爲input1
是1.0
。
我已經在不同的來源地看着變亮混合模式文檔在互聯網上,他們都使用這個公式:
max(blend, base)
綜觀實施GPUImageLightenBlendFilter
着色器也使用了相同的公式:
lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
lowp vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2);
gl_FragColor = max(textureColor, textureColor2);
但是,似乎Photoshop和CoreImage
有一些額外的操作與阿爾法(可能類似於Gimp:https://github.com/GNOME/gimp/blob/783bbab8a889d4eba80b6a83f2e529937a73a471/app/operations/gimpoperationlightenonlymode.c)。
任何人都有想法如何在GPUImageLightenBlendFilter
公式中包含alpha通道?
感謝您的着色器代碼。 – pirags