Skip to content
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

Blend Normal with Alpha #6

Open
omarojo opened this issue Aug 21, 2019 · 4 comments
Open

Blend Normal with Alpha #6

omarojo opened this issue Aug 21, 2019 · 4 comments

Comments

@omarojo
Copy link

omarojo commented Aug 21, 2019

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.

@iangilman
Copy link

Indeed! I would love for all of the blend modes to take the alpha of the textures into account!

@felixturner
Copy link

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;

@iangilman
Copy link

@felixturner Awesome, thank you for writing this up! I'll be putting it into use shortly :-)

@geikha
Copy link

geikha commented Feb 2, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants