glsl-blend
glsl-blend copied to clipboard
Blend Normal with Alpha
Is it possible to use the Normal Blend.. but if the blend texture has parts that are alpha 0.0 show the basetexture below?
Just like putting a image that has transparent parts ON TOP of a base image. But the opacity of both images is 100%. so you are able to see both at the same time.
Indeed! I would love for all of the blend modes to take the alpha of the textures into account!
This works for transparent images and any blend mode:
float blendOpac = blendLayerOpacity * blend.a;
vec4 outCol;
outCol.rgb = blendScreen(base.rgb, blend.rgb, blendOpac); // works for any blendMode
outCol.a = blendOpac + base.a;
@felixturner Awesome, thank you for writing this up! I'll be putting it into use shortly :-)
Hello! I thought I'd share my approach. I made it comparing to Photopea as a reference. I realized what Photopea does (and I'm assuming Photoshop does too, I don't have access to the software right now) is basically layer the blend texture over the base texture wherever the base texture is transparent. I'll use darken as an example:
vec4 blendDarken(vec4 base, vec4 blend, float opacity){
blend.a *= opacity;
vec4 blended = vec4(blendDarken(base.rgb, blend.rgb, opacity), 1.0);
vec4 over = blend+(base*(1.0-blend.a));
return mix(blended, over, 1.0-base.a);
}
Edit: This method assumes the function will be receiving values with premultiplied alpha