remove unused shaders, fix color blending algorithm in shader
This commit is contained in:
@@ -76,19 +76,10 @@ void App::initShaders()
|
||||
" mediump vec4 stroke = texture(tex_stroke, uv.xy);\n"
|
||||
" stroke.a = stroke.a * alpha;\n"
|
||||
|
||||
" if (lock){\n"
|
||||
" mediump float alpha_tot = stroke.a + (1.0 - stroke.a) * base.a;"
|
||||
" mediump vec3 rgb = mix(base.rgb, stroke.rgb, stroke.a / alpha_tot);\n"
|
||||
" frag = vec4(rgb, base.a);\n"
|
||||
" } else {\n"
|
||||
" mediump float alpha_tot = stroke.a + (1.0 - stroke.a) * base.a;"
|
||||
" mediump vec3 rgb = mix(base.rgb, stroke.rgb, stroke.a / alpha_tot);\n"
|
||||
" frag = vec4(rgb, alpha_tot);\n"
|
||||
" }\n"
|
||||
|
||||
// " mediump float alpha_tot = stroke.a + (1.0 - stroke.a) * base.a;"
|
||||
// " mediump vec3 rgb = mix(base.rgb, stroke.rgb, stroke.a / alpha_tot);\n"
|
||||
// " frag = vec4(rgb, alpha_tot);\n"
|
||||
" mediump float contribution = (1.0 - base.a) * stroke.a;\n"
|
||||
" mediump float alpha_tot = base.a + contribution;"
|
||||
" mediump vec3 rgb = mix(base.rgb, stroke.rgb, stroke.a / alpha_tot);\n"
|
||||
" frag = vec4(rgb, lock ? base.a : alpha_tot);\n"
|
||||
"}\n";
|
||||
|
||||
// TEXTURE ATLAS
|
||||
@@ -213,9 +204,9 @@ void App::initShaders()
|
||||
"}\n";
|
||||
static const char* shader_stroke_f =
|
||||
SHADER_VERSION
|
||||
#ifdef __IOS__
|
||||
#ifdef __IOS__
|
||||
"#extension GL_EXT_shader_framebuffer_fetch : enable\n"
|
||||
#endif
|
||||
#endif
|
||||
"uniform mediump sampler2D tex;\n"
|
||||
"uniform mediump sampler2D tex_bg;\n"
|
||||
"uniform mediump vec4 col;\n"
|
||||
@@ -223,130 +214,26 @@ void App::initShaders()
|
||||
"uniform mediump float alpha;\n"
|
||||
"in mediump vec2 uv;\n"
|
||||
"in mediump float q;\n"
|
||||
#ifdef __IOS__
|
||||
#ifdef __IOS__
|
||||
"inout mediump vec4 frag;\n"
|
||||
#else
|
||||
#else
|
||||
"out mediump vec4 frag;\n"
|
||||
#endif
|
||||
#endif
|
||||
"void main(){\n"
|
||||
" mediump vec2 uv2 = gl_FragCoord.st / resolution;\n"
|
||||
" mediump float brush_alpha = ( 1.0 - texture(tex, uv/q).r ) * alpha;\n"
|
||||
" mediump vec4 fg = vec4(col.rgb, brush_alpha);\n"
|
||||
#ifdef __IOS__
|
||||
#ifdef __IOS__
|
||||
" mediump vec4 bg = frag;\n"
|
||||
#else
|
||||
#else
|
||||
" mediump vec4 bg = texture(tex_bg, uv2);\n"
|
||||
#endif
|
||||
//" if (fg.a < 1.0/255.0) { frag = bg; return; }\n"
|
||||
" mediump float alpha_tot = fg.a + (1.0 - fg.a) * bg.a;"
|
||||
#endif
|
||||
" if (fg.a == 1.0/255.0) { frag = bg; return; }\n"
|
||||
" mediump float contribution = max((1.0 - bg.a) * fg.a, 1.0/255.0);\n"
|
||||
" mediump float alpha_tot = bg.a + contribution;"
|
||||
" mediump vec3 rgb = mix(bg.rgb, fg.rgb, fg.a / alpha_tot);\n"
|
||||
" frag = vec4(rgb, clamp(alpha_tot, 0.0, 1.0));\n"
|
||||
"}\n";
|
||||
// ALPHA LOCK
|
||||
static const char* shader_stroke_lock_f =
|
||||
SHADER_VERSION
|
||||
#ifdef __IOS__
|
||||
"#extension GL_EXT_shader_framebuffer_fetch : enable\n"
|
||||
#endif
|
||||
"uniform mediump sampler2D tex;\n"
|
||||
"uniform mediump sampler2D tex_bg;\n"
|
||||
"uniform mediump sampler2D tex_mask;\n"
|
||||
"uniform mediump vec4 col;\n"
|
||||
"uniform mediump vec2 resolution;\n"
|
||||
"uniform mediump float alpha;\n"
|
||||
"in mediump vec2 uv;\n"
|
||||
#ifdef __IOS__
|
||||
"inout mediump vec4 frag;\n"
|
||||
#else
|
||||
"out mediump vec4 frag;\n"
|
||||
#endif
|
||||
"void main(){\n"
|
||||
" mediump vec2 uv2 = gl_FragCoord.st / resolution;\n"
|
||||
" mediump float brush_alpha = ( 1.0 - texture(tex, uv).r ) * alpha;\n"
|
||||
" mediump vec4 fg = vec4(col.rgb, brush_alpha);\n"
|
||||
#ifdef __IOS__
|
||||
" mediump vec4 bg = frag;\n"
|
||||
#else
|
||||
" mediump vec4 bg = texture(tex_bg, uv2);\n"
|
||||
#endif
|
||||
" mediump vec4 msk = texture(tex_mask, uv2);\n"
|
||||
//" if (fg.a < (1.0/255.0)) { return; }\n"
|
||||
" mediump float alpha_tot = fg.a + (1.0 - fg.a) * bg.a;"
|
||||
" mediump vec3 rgb = mix(bg.rgb, fg.rgb, fg.a / alpha_tot);\n"
|
||||
" frag = vec4(rgb, msk.a);\n"
|
||||
"}\n";
|
||||
// ERASER
|
||||
static const char* shader_stroke_erase_f =
|
||||
SHADER_VERSION
|
||||
#ifdef __IOS__
|
||||
"#extension GL_EXT_shader_framebuffer_fetch : enable\n"
|
||||
#endif
|
||||
"uniform mediump sampler2D tex;\n"
|
||||
"uniform mediump sampler2D tex_bg;\n"
|
||||
"uniform mediump vec4 col;\n"
|
||||
"uniform mediump vec2 resolution;\n"
|
||||
"uniform mediump float alpha;\n"
|
||||
"in mediump vec2 uv;\n"
|
||||
#ifdef __IOS__
|
||||
"inout mediump vec4 frag;\n"
|
||||
#else
|
||||
"out mediump vec4 frag;\n"
|
||||
#endif
|
||||
"void main(){\n"
|
||||
" mediump vec2 uv2 = gl_FragCoord.st / resolution;\n"
|
||||
" mediump float brush_alpha = ( 1.0 - texture(tex, uv).r ) * alpha;\n"
|
||||
#ifdef __IOS__
|
||||
" mediump vec4 bg = frag;\n"
|
||||
#else
|
||||
" mediump vec4 bg = texture(tex_bg, uv2);\n"
|
||||
#endif
|
||||
" frag = vec4(bg.rgb, bg.a - bg.a * brush_alpha);\n"
|
||||
"}\n";
|
||||
|
||||
// STROKE LAYER BLEND
|
||||
static const char* shader_stroke_layer_v =
|
||||
SHADER_VERSION
|
||||
"uniform mat4 mvp;"
|
||||
"in vec4 pos;"
|
||||
"in vec2 uvs;"
|
||||
"out vec2 uv;"
|
||||
"void main(){"
|
||||
" uv = uvs;"
|
||||
" gl_Position = mvp * vec4(pos.xyz, 1.0);"
|
||||
"}";
|
||||
static const char* shader_stroke_layer_f =
|
||||
SHADER_VERSION
|
||||
#ifdef __IOS__
|
||||
"#extension GL_EXT_shader_framebuffer_fetch : enable\n"
|
||||
#endif
|
||||
"uniform mediump sampler2D tex;\n"
|
||||
"uniform mediump sampler2D tex_bg;\n"
|
||||
"uniform mediump vec2 resolution;\n"
|
||||
"uniform mediump float alpha;\n"
|
||||
"uniform bool lock;\n"
|
||||
"uniform bool erase;\n"
|
||||
"in mediump vec2 uv;\n"
|
||||
#ifdef __IOS__
|
||||
"inout mediump vec4 frag;\n"
|
||||
#else
|
||||
"out mediump vec4 frag;\n"
|
||||
#endif
|
||||
"void main(){\n"
|
||||
" mediump vec4 fg = texture(tex, uv) * vec4(1,1,1,alpha);\n"
|
||||
#ifdef __IOS__
|
||||
" mediump vec4 bg = frag;\n"
|
||||
#else
|
||||
" mediump vec4 bg = texture(tex_bg, uv);\n"
|
||||
#endif
|
||||
//" if (fg.a < (1.0/255.0)) { frag = bg; return; }\n"
|
||||
" if (erase){\n"
|
||||
" frag = vec4(bg.rgb, bg.a - fg.a);\n"
|
||||
" } else {\n"
|
||||
" mediump float alpha_tot = fg.a + (1.0 - fg.a) * bg.a;"
|
||||
" mediump vec3 rgb = mix(bg.rgb, fg.rgb, fg.a / alpha_tot);\n"
|
||||
" frag = vec4(rgb, lock ? bg.a : alpha_tot);\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
|
||||
static const char* shader_checkerboard_v =
|
||||
SHADER_VERSION
|
||||
@@ -422,12 +309,6 @@ void App::initShaders()
|
||||
LOG("Failed to create shader Atlas");
|
||||
if (!ShaderManager::create(kShader::Stroke, shader_stroke_v, shader_stroke_f))
|
||||
LOG("Failed to create shader Stroke");
|
||||
if (!ShaderManager::create(kShader::StrokeLock, shader_stroke_v, shader_stroke_lock_f))
|
||||
LOG("Failed to create shader StrokeLock");
|
||||
if (!ShaderManager::create(kShader::StrokeErase, shader_stroke_v, shader_stroke_erase_f))
|
||||
LOG("Failed to create shader StrokeErase");
|
||||
if (!ShaderManager::create(kShader::StrokeLayer, shader_stroke_layer_v, shader_stroke_layer_f))
|
||||
LOG("Failed to create shader StrokeLayer");
|
||||
if (!ShaderManager::create(kShader::Checkerboard, shader_checkerboard_v, shader_checkerboard_f))
|
||||
LOG("Failed to create shader Checkerboard");
|
||||
if (!ShaderManager::create(kShader::Equirect, shader_equirect_v, shader_equirect_f))
|
||||
|
||||
Reference in New Issue
Block a user