fix border clamp problem, add tmp layer special blending on stroke commit
This commit is contained in:
@@ -159,15 +159,11 @@ void App::initShaders()
|
||||
static const char* shader_stroke_v =
|
||||
SHADER_VERSION
|
||||
"uniform mat4 mvp;\n"
|
||||
"uniform vec2 tof;\n"
|
||||
"uniform vec2 tsz;\n"
|
||||
"in vec4 pos;\n"
|
||||
"in vec2 uvs;\n"
|
||||
"out vec2 uv1;\n"
|
||||
"out vec2 uv2;\n"
|
||||
"out vec2 uv;\n"
|
||||
"void main(){\n"
|
||||
" uv1 = uvs;\n"
|
||||
" uv2 = tof + tsz * uvs;\n"
|
||||
" uv = uvs;\n"
|
||||
" gl_Position = mvp * vec4(pos.xyz, 1.0);\n"
|
||||
"}\n";
|
||||
static const char* shader_stroke_f =
|
||||
@@ -177,20 +173,15 @@ void App::initShaders()
|
||||
"uniform mediump vec4 col;\n"
|
||||
"uniform mediump vec2 resolution;\n"
|
||||
"uniform mediump float alpha;\n"
|
||||
"in mediump vec2 uv1;\n"
|
||||
"in mediump vec2 uv2;\n"
|
||||
"in mediump vec2 uv;\n"
|
||||
"out mediump vec4 frag;\n"
|
||||
"void main(){\n"
|
||||
" mediump vec2 uv2 = gl_FragCoord.st / resolution;\n"
|
||||
" mediump float brush = ( 1.0 - texture(tex, uv1).r ) * alpha;\n"
|
||||
" mediump float brush = ( 1.0 - texture(tex, uv).r ) * alpha;\n"
|
||||
" mediump vec4 bg = texture(tex_bg, uv2);\n"
|
||||
" mediump vec3 rgb = mix( bg.rgb, col.rgb, clamp( brush/(brush + bg.a), 0.0, 1.0 ) );\n"
|
||||
" mediump float a = bg.a + (1.0 - bg.a) * brush;\n"
|
||||
" frag = vec4(rgb, a);\n"
|
||||
|
||||
// " mediump vec4 bg = texture(tex_bg, uv.xy);"
|
||||
// " mediump float a = (1.0 - texture(tex, uv.xy).r) * alpha;"
|
||||
// " frag = bg;// * vec4(col.rgb, a);\n"
|
||||
"}\n";
|
||||
|
||||
// STROKE LAYER BLEND
|
||||
@@ -199,25 +190,26 @@ void App::initShaders()
|
||||
"uniform mat4 mvp;"
|
||||
"in vec4 pos;"
|
||||
"in vec2 uvs;"
|
||||
"out vec3 uv;"
|
||||
"out vec2 uv;"
|
||||
"void main(){"
|
||||
" uv = vec3(uvs, pos.w);"
|
||||
" uv = uvs;"
|
||||
" gl_Position = mvp * vec4(pos.xyz, 1.0);"
|
||||
"}";
|
||||
static const char* shader_stroke_layer_f =
|
||||
SHADER_VERSION
|
||||
"uniform mediump sampler2D tex_fg;" // foreground
|
||||
"uniform mediump sampler2D tex_bg;" // canvas
|
||||
"uniform mediump float alpha;" // opacity
|
||||
"in mediump vec3 uv;"
|
||||
"out mediump vec4 frag;"
|
||||
"void main(){"
|
||||
" mediump vec4 c1 = texture2D(tex_fg, uv);"
|
||||
" mediump vec4 c2 = texture2D(tex_bg, uv);"
|
||||
" mediump float t = clamp(c1.a / (c1.a + c2.a), 0.0, 1.0));"
|
||||
" mediump vec3 rgb = mix(c1.rgb, c2.rgb, t);"
|
||||
" frag = vec4(rgb, c1.a + c2.a);"
|
||||
"}";
|
||||
"uniform mediump sampler2D tex;\n"
|
||||
"uniform mediump sampler2D tex_bg;\n"
|
||||
"uniform mediump vec2 resolution;\n"
|
||||
"uniform mediump float alpha;\n"
|
||||
"in mediump vec2 uv;\n"
|
||||
"out mediump vec4 frag;\n"
|
||||
"void main(){\n"
|
||||
" mediump vec4 fg = texture(tex, uv);\n"
|
||||
" mediump vec4 bg = texture(tex_bg, uv);\n"
|
||||
" mediump vec3 rgb = mix( bg.rgb, fg.rgb, clamp( fg.a/(fg.a + bg.a), 0.0, 1.0 ) );\n"
|
||||
" mediump float a = bg.a + (1.0 - bg.a) * fg.a;\n" // this can be optimized as lerp/mix(1, fg.a, bg.a)
|
||||
" frag = vec4(rgb, a);\n"
|
||||
"}\n";
|
||||
|
||||
LOG("initializing shaders");
|
||||
if (!ShaderManager::create(kShader::Texture, shader_v, shader_f))
|
||||
|
||||
Reference in New Issue
Block a user