code cleanup and improve brush direction

This commit is contained in:
2019-02-11 18:39:26 +01:00
parent 97c3ac0d19
commit 171ab31b47
5 changed files with 97 additions and 144 deletions

View File

@@ -27,13 +27,15 @@
"{ return mix(stroke.rgb, mix(base.rgb, base.rgb/(1.0-stroke.rgb), stroke.a/alpha_tot), base.a/alpha_tot); }\n"\
"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); }\n"\
"mediump vec3 blend(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot, int mode) {\n"\
" if (mode == 0) return blend_normal(base, stroke, alpha_tot);\n"\
" else if (mode == 1) return blend_multiply(base, stroke, alpha_tot);\n"\
" else if (mode == 2) return blend_screen(base, stroke, alpha_tot);\n"\
" else if (mode == 3) return blend_colorDodge(base, stroke, alpha_tot);\n"\
" else if (mode == 4) return blend_overlay(base, stroke, alpha_tot);\n"\
" else return blend_multiply(base, stroke, alpha_tot);\n"\
"mediump vec4 blend(mediump vec4 base, mediump vec4 stroke, int mode) {\n"\
" mediump float contribution = (1.0 - base.a) * stroke.a;\n"\
" mediump float alpha_tot = base.a + contribution;\n"\
" if (mode == 0) return vec4(blend_normal(base, stroke, alpha_tot), alpha_tot);\n"\
" else if (mode == 1) return vec4(blend_multiply(base, stroke, alpha_tot), alpha_tot);\n"\
" else if (mode == 2) return vec4(blend_screen(base, stroke, alpha_tot), alpha_tot);\n"\
" else if (mode == 3) return vec4(blend_colorDodge(base, stroke, alpha_tot), alpha_tot);\n"\
" else if (mode == 4) return vec4(blend_overlay(base, stroke, alpha_tot), alpha_tot);\n"\
" else return vec4(1, 0, 0, 1);\n"\
"}\n"
#define SHADER_FUNCTION_HSV \
@@ -115,9 +117,8 @@ void App::initShaders()
"#endif\n"
" mediump vec4 fg = vec4(texture(tex, uv).rgb, texture(tex_alpha, uv).a);\n"
" if (fg.a == 0.0) { frag = bg; return; }\n"
" mediump float contribution = (1.0 - bg.a) * fg.a;\n"
" mediump float alpha_tot = bg.a + contribution;\n"
" frag = vec4(blend(bg, fg, alpha_tot, blend_mode), alpha_tot * alpha);\n"
" mediump vec4 blended = blend(bg, fg, blend_mode);\n"
" frag = vec4(blended.rgb, blended.a * alpha);\n"
"}\n";
static const char* shader_uv_f =
SHADER_VERSION
@@ -207,14 +208,17 @@ void App::initShaders()
"uniform sampler2D tex;\n"
"uniform sampler2D tex_stroke;\n"
"uniform sampler2D tex_mask;\n"
"uniform sampler2D tex_dual;\n"
//"uniform sampler2D tex_stencil;\n"
"uniform mediump float alpha;\n"
"uniform mediump float stroke_alpha;\n"
"uniform mediump int blend_mode;\n"
"uniform mediump int dual_blend_mode;\n"
"uniform mediump vec2 resolution;\n"
"uniform bool lock;\n"
"uniform bool mask;\n"
"uniform bool fragUV2;\n"
"uniform bool useDual;\n"
"in mediump vec2 uv;\n"
"out mediump vec4 frag;\n"
SHADER_FUNCTION_BLUR
@@ -225,10 +229,8 @@ void App::initShaders()
" mediump vec4 stroke = texture(tex_stroke, uv);\n"
" stroke.a = mask ? stroke.a * stroke_alpha * blur(tex_mask, uv2).r : stroke.a * stroke_alpha;\n"
" if (!lock && base.a == 0.0) { frag = stroke * vec4(1.0, 1.0, 1.0, alpha); return; }\n"
" mediump float contribution = (1.0 - base.a) * stroke.a;\n"
" mediump float alpha_tot = base.a + contribution;\n"
" mediump vec3 rgb = blend(base, stroke, alpha_tot, blend_mode);\n"
" frag = vec4(rgb, (lock ? base.a : alpha_tot) * alpha);\n"
" mediump vec4 blended = blend(base, stroke, blend_mode);\n"
" frag = vec4(blended.rgb, (lock ? base.a : blended.a) * alpha);\n"
"}\n";
// TEXTURE ATLAS