implement frame buffer fetch extension for iOS, change composition on stroke drawing and commit, add rename layer dialog
This commit is contained in:
@@ -43,6 +43,49 @@ void App::initShaders()
|
||||
"void main(){\n"
|
||||
" frag = texture(tex, uv.xy) * vec4(1,1,1,alpha);\n"
|
||||
"}\n";
|
||||
// TEXTURE COMP ERASE
|
||||
static const char* shader_comp_erase_f =
|
||||
SHADER_VERSION
|
||||
"uniform sampler2D tex;\n"
|
||||
"uniform sampler2D tex_stroke;\n"
|
||||
"uniform mediump float alpha;\n"
|
||||
"uniform bool lock;\n"
|
||||
"in mediump vec3 uv;\n"
|
||||
"out mediump vec4 frag;\n"
|
||||
"void main(){\n"
|
||||
" mediump vec4 base = texture(tex, uv.xy);\n"
|
||||
" mediump vec4 stroke = texture(tex_stroke, uv.xy);\n"
|
||||
" mediump float a = base.a - (stroke.a * alpha);\n"
|
||||
" frag = vec4(base.rgb, clamp(a, 0.0, 1.0));\n"
|
||||
"}\n";
|
||||
// TEXTURE COMP DRAW
|
||||
static const char* shader_comp_draw_f =
|
||||
SHADER_VERSION
|
||||
"uniform sampler2D tex;\n"
|
||||
"uniform sampler2D tex_stroke;\n"
|
||||
"uniform mediump float alpha;\n"
|
||||
"uniform bool lock;\n"
|
||||
"in mediump vec3 uv;\n"
|
||||
"out mediump vec4 frag;\n"
|
||||
"void main(){\n"
|
||||
" mediump vec4 base = texture(tex, uv.xy);\n"
|
||||
" 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"
|
||||
"}\n";
|
||||
|
||||
// TEXTURE ATLAS
|
||||
static const char* shader_atlas_v =
|
||||
@@ -164,26 +207,40 @@ void App::initShaders()
|
||||
"}\n";
|
||||
static const char* shader_stroke_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"
|
||||
" 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"
|
||||
" if (fg.a < (1.0/255.0)) { frag = bg; return; }\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;"
|
||||
" mediump vec3 rgb = mix(bg.rgb, fg.rgb, fg.a / alpha_tot);\n"
|
||||
" frag = vec4(rgb, 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"
|
||||
@@ -191,32 +248,51 @@ void App::initShaders()
|
||||
"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)) { frag = bg; return; }\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, min(alpha_tot, msk.a));\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";
|
||||
|
||||
@@ -233,19 +309,36 @@ void App::initShaders()
|
||||
"}";
|
||||
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"
|
||||
" if (fg.a < (1.0/255.0)) { frag = bg; 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, alpha_tot);\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 =
|
||||
@@ -304,6 +397,10 @@ void App::initShaders()
|
||||
LOG("Failed to create shader Texture");
|
||||
if (!ShaderManager::create(kShader::TextureAlpha, shader_v, shader_alpha_f))
|
||||
LOG("Failed to create shader TextureAlpha");
|
||||
if (!ShaderManager::create(kShader::CompErase, shader_v, shader_comp_erase_f))
|
||||
LOG("Failed to create shader CompErase");
|
||||
if (!ShaderManager::create(kShader::CompDraw, shader_v, shader_comp_draw_f))
|
||||
LOG("Failed to create shader CompDraw");
|
||||
if (!ShaderManager::create(kShader::Color, shader_color_v, shader_color_f))
|
||||
LOG("Failed to create shader Color");
|
||||
if (!ShaderManager::create(kShader::ColorQuad, shader_color_quad_v, shader_color_quad_f))
|
||||
|
||||
Reference in New Issue
Block a user