implement blend mode selection in shader and fix alpha lock
This commit is contained in:
@@ -84,6 +84,7 @@ void App::initShaders()
|
||||
"uniform sampler2D tex_stencil;\n"
|
||||
//"uniform image2D img_mixer;\n"
|
||||
"uniform mediump float alpha;\n"
|
||||
"uniform mediump int blend_mode;\n"
|
||||
"uniform bool lock;\n"
|
||||
"uniform bool mask;\n"
|
||||
"in mediump vec3 uv;\n"
|
||||
@@ -100,10 +101,16 @@ void App::initShaders()
|
||||
" sum += textureOffset(t, uv, ivec2( 1, 1));\n"
|
||||
" return sum / vec4(9.0);\n"
|
||||
"}\n"
|
||||
"vec3 blend_colorDodge(vec4 base, vec4 stroke, float alpha_tot) { return mix(stroke.rgb, mix(base.rgb, base.rgb/(1.0-stroke.rgb), stroke.a/alpha_tot), base.a/alpha_tot); }\n"
|
||||
"vec3 blend_normal(vec4 base, vec4 stroke, float alpha_tot) { return mix(base.rgb, stroke.rgb, stroke.a/alpha_tot); }\n"
|
||||
"vec3 blend_multiply(vec4 base, vec4 stroke, float alpha_tot) { return mix(stroke.rgb, mix(base.rgb, base.rgb*stroke.rgb, stroke.a/alpha_tot), base.a/alpha_tot); }\n"
|
||||
"vec3 blend_screen(vec4 base, vec4 stroke, 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); }\n"
|
||||
"vec3 blend_normal(vec4 base, vec4 stroke, float alpha_tot) { return mix(base.rgb, stroke.rgb, stroke.a/alpha_tot); }\n"
|
||||
"vec3 blend_colorDodge(vec4 base, vec4 stroke, float alpha_tot) { return mix(stroke.rgb, mix(base.rgb, base.rgb/(1.0-stroke.rgb), stroke.a/alpha_tot), base.a/alpha_tot); }\n"
|
||||
"vec3 blend(vec4 base, vec4 stroke, float alpha_tot, int mode) { switch(mode){\n"
|
||||
" case 0: return blend_normal(base, stroke, alpha_tot);"
|
||||
" case 1: return blend_multiply(base, stroke, alpha_tot);"
|
||||
" case 2: return blend_screen(base, stroke, alpha_tot);"
|
||||
" case 3: return blend_colorDodge(base, stroke, alpha_tot);"
|
||||
"}}\n"
|
||||
"void main(){\n"
|
||||
" mediump vec2 uv2 = gl_FragCoord.st / vec2(2048) * 20.0;\n"
|
||||
" mediump vec4 base = texture(tex, uv.xy);\n"
|
||||
@@ -111,10 +118,10 @@ void App::initShaders()
|
||||
" mediump float stencil = pow(texture(tex_stencil, uv2).r, 8.0);\n"
|
||||
" stroke.a = mask ? stroke.a * alpha * blur(tex_mask, uv.xy).r : stroke.a * alpha;\n"
|
||||
|
||||
" if (base.a == 0.0) { frag = stroke; return; }\n"
|
||||
" if (!lock && base.a == 0.0) { frag = stroke; return; }\n"
|
||||
" mediump float contribution = (1.0 - base.a) * stroke.a;\n"
|
||||
" mediump float alpha_tot = base.a + contribution;"
|
||||
" mediump vec3 rgb = blend_screen(base, stroke, alpha_tot);\n"
|
||||
" mediump vec3 rgb = blend(base, stroke, alpha_tot, blend_mode);\n"
|
||||
" frag = vec4(rgb, (lock ? base.a : alpha_tot));\n"
|
||||
"}\n";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user