77 lines
2.1 KiB
GLSL
77 lines
2.1 KiB
GLSL
mediump vec3 blend_normal(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
|
|
{
|
|
return mix(
|
|
base.rgb,
|
|
stroke.rgb,
|
|
stroke.a/alpha_tot
|
|
);
|
|
}
|
|
|
|
mediump vec3 blend_multiply(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
|
|
{
|
|
return mix(
|
|
stroke.rgb,
|
|
mix(
|
|
base.rgb,
|
|
base.rgb*stroke.rgb,
|
|
stroke.a/alpha_tot
|
|
),
|
|
base.a/alpha_tot
|
|
);
|
|
}
|
|
|
|
mediump vec3 blend_screen(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
|
|
{
|
|
return mix(
|
|
stroke.rgb,
|
|
mix(
|
|
base.rgb,
|
|
1.0-(1.0-base.rgb)*(1.0-stroke.rgb),
|
|
stroke.a/alpha_tot
|
|
),
|
|
base.a/alpha_tot
|
|
);
|
|
}
|
|
|
|
mediump vec3 blend_colorDodge(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
|
|
{
|
|
return mix(
|
|
stroke.rgb,
|
|
mix(
|
|
base.rgb,
|
|
base.rgb/(1.0-stroke.rgb),
|
|
stroke.a/alpha_tot
|
|
),
|
|
base.a/alpha_tot
|
|
);
|
|
}
|
|
|
|
mediump vec3 blend_overlay(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
|
|
{
|
|
return mix(
|
|
stroke.rgb,
|
|
mix(
|
|
base.rgb,
|
|
mix(
|
|
2.0*base.rgb*stroke.rgb,
|
|
1.0-2.0*(1.0-base.rgb)*(1.0-stroke.rgb),
|
|
floor(base.rgb*2.0)
|
|
),
|
|
stroke.a/alpha_tot
|
|
),
|
|
base.a/alpha_tot
|
|
);
|
|
}
|
|
|
|
mediump vec4 blend(mediump vec4 base, mediump vec4 stroke, int mode)
|
|
{
|
|
mediump float contribution = (1.0 - base.a) * stroke.a;
|
|
mediump float alpha_tot = base.a + contribution;
|
|
if (mode == 0) return vec4(blend_normal(base, stroke, alpha_tot), alpha_tot);
|
|
else if (mode == 1) return vec4(blend_multiply(base, stroke, alpha_tot), alpha_tot);
|
|
else if (mode == 2) return vec4(blend_screen(base, stroke, alpha_tot), alpha_tot);
|
|
else if (mode == 3) return vec4(blend_colorDodge(base, stroke, alpha_tot), alpha_tot);
|
|
else if (mode == 4) return vec4(blend_overlay(base, stroke, alpha_tot), alpha_tot);
|
|
else return vec4(1.0, 0.0, 0.0, 1.0);
|
|
}
|