all blending modes for pattern and dual brush

This commit is contained in:
2019-02-22 02:26:25 +01:00
parent 39ee7289c5
commit 876c002616
11 changed files with 75 additions and 21 deletions

View File

@@ -64,14 +64,14 @@ void main()
if (pattern_contr != 0.5)
patt = contrast1(patt, pattern_contr);
//mediump float pa = (1.0 - patt) * pow(pattern_depth, 0.25) + (stroke.a * pattern_depth * 10.0);
mediump float pa = pow((1.0 - patt), max(1.0, (1.0 - pattern_depth) * 10.0)) * pow(pattern_depth, 0.25) + (stroke.a * pattern_depth * 5.0);
stroke.a = mix(pa * stroke.a, stroke.a, 0.0);
//mediump float pa = pow((1.0 - patt), max(1.0, (1.0 - pattern_depth) * 10.0)) * pow(pattern_depth, 0.25) + (stroke.a * pattern_depth * 5.0);
stroke.a = blend_stroke(stroke.a, patt, pattern_depth, patt_blend_mode);
}
if (use_dual)
{
mediump vec4 dual = texture(tex_dual, uv);
stroke.a = blend_stroke(stroke.a, dual.a * dual_alpha, dual_blend_mode);
stroke.a = blend_stroke(stroke.a, dual.a, dual_alpha, dual_blend_mode);
}
stroke.a = mask ? stroke.a * stroke_alpha * blur(tex_mask, uv).r : stroke.a * stroke_alpha;

View File

@@ -1,9 +1,55 @@
mediump float blend_stroke(mediump float base, mediump float stroke, int mode)
mediump float blend_stroke_screen(mediump float base, mediump float stroke)
{
if (mode == 0) /* normal */ return (base + stroke) * 0.5;
else if (mode == 1) /* multiply */ return base * stroke;
else if (mode == 2) /* screen */ return 1.0-(1.0-base)*(1.0-stroke);
else if (mode == 3) /* color-dodge */ return base/(1.0-stroke);
else if (mode == 4) /* overlay */ return mix(2.0*base*stroke, 1.0-2.0*(1.0-base)*(1.0-stroke), floor(base*2.0));
return clamp(base + stroke - (base * stroke), 0.0, 1.0);
}
mediump float blend_stroke_hard_light(mediump float base, mediump float stroke)
{
if (stroke < 0.5)
return max(1.0, base * (stroke * 2.0)); // multiply
else
return blend_stroke_screen(base, 2.0 * stroke - 1.0);
}
mediump float blend_stroke_hard_mix(mediump float base, mediump float stroke)
{
return base + stroke > 0.5 ? 1.0 : 0.0;
}
mediump float blend_stroke_color_dodge(mediump float base, mediump float stroke)
{
if (base == 0.0)
return 0.0;
else if (stroke == 1.0)
return 1.0;
else
return min(1.0, base / (1.0 - stroke));
}
mediump float blend_stroke_linear_height(mediump float base, mediump float stroke, mediump float depth)
{
mediump float partial = (1.0 - stroke) * pow(depth, 0.25) + (base * depth * 10.0);
return stroke * partial;
}
mediump float blend_stroke_height(mediump float base, mediump float stroke, mediump float depth)
{
mediump float A = pow((1.0 - stroke), max(1.0, (1.0 - depth) * 10.0)) * pow(depth, 0.25);
mediump float B = (base * depth * 5.0);
return stroke * (A + B);
}
mediump float blend_stroke(mediump float base, mediump float stroke, mediump float depth, int mode)
{
if (mode == 0) /* normal */ return mix(base, stroke, depth);
else if (mode == 1) /* multiply */ return mix(base, base * stroke, depth);
else if (mode == 2) /* subtract */ return mix(base, max(0.0, base - stroke), depth);
else if (mode == 3) /* darken */ return mix(base, min(base, stroke), depth);
else if (mode == 4) /* overlay */ return mix(base, blend_stroke_hard_light(stroke, base), depth);
else if (mode == 5) /* col-dodge */ return mix(base, blend_stroke_color_dodge(stroke, base), depth);
else if (mode == 6) /* lin-burn */ return mix(base, clamp(stroke + base - 1.0, 0.0, 1.0), depth);
else if (mode == 7) /* hard-mix */ return mix(base, blend_stroke_hard_mix(base, stroke), depth);
else if (mode == 8) /* lin-height */ return blend_stroke_linear_height(base, stroke, depth);
else if (mode == 9) /* height */ return blend_stroke_height(base, stroke, depth);
else return 1.0;
}

View File

@@ -22,6 +22,7 @@ void main()
#include "include/ext-fb-fetch.glsl"
#include "include/rand.glsl"
#include "include/color.glsl"
#include "include/blend-stroke.glsl"
uniform mediump sampler2D tex;
uniform mediump sampler2D tex_bg;
@@ -41,6 +42,7 @@ uniform mediump float pattern_contr;
uniform mediump float pattern_depth;
uniform mediump vec2 pattern_offset;
uniform mediump bool pattern_invert;
uniform mediump int patt_blend_mode;
in mediump vec2 uv;
in mediump vec2 uv_2;
@@ -68,7 +70,7 @@ void main()
patt = brightness1(patt, 1.0 - pattern_bright);
if (pattern_contr != 0.5)
patt = contrast1(patt, pattern_contr);
fg.a = mix(fg.a, fg.a * patt, pattern_depth);
fg.a = blend_stroke(fg.a, patt, pattern_depth, patt_blend_mode);
}
#if defined(GL_EXT_shader_framebuffer_fetch)