implement the complete stroke shader with custom blending mode
This commit is contained in:
@@ -157,6 +157,44 @@ void App::initShaders()
|
||||
|
||||
// STROKE
|
||||
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"
|
||||
"void main(){\n"
|
||||
" uv1 = uvs;\n"
|
||||
" uv2 = tof + tsz * uvs;\n"
|
||||
" gl_Position = mvp * vec4(pos.xyz, 1.0);\n"
|
||||
"}\n";
|
||||
static const char* shader_stroke_f =
|
||||
SHADER_VERSION
|
||||
"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 uv1;\n"
|
||||
"in mediump vec2 uv2;\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 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
|
||||
static const char* shader_stroke_layer_v =
|
||||
SHADER_VERSION
|
||||
"uniform mat4 mvp;"
|
||||
"in vec4 pos;"
|
||||
@@ -166,16 +204,19 @@ void App::initShaders()
|
||||
" uv = vec3(uvs, pos.w);"
|
||||
" gl_Position = mvp * vec4(pos.xyz, 1.0);"
|
||||
"}";
|
||||
static const char* shader_stroke_f =
|
||||
static const char* shader_stroke_layer_f =
|
||||
SHADER_VERSION
|
||||
"uniform mediump sampler2D tex;"
|
||||
"uniform mediump vec4 col;"
|
||||
"uniform mediump float alpha;"
|
||||
"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 float a = (1.0 - texture(tex, uv.xy).r) * alpha;"
|
||||
" frag = vec4(col.rgb, a);"
|
||||
" 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);"
|
||||
"}";
|
||||
|
||||
LOG("initializing shaders");
|
||||
@@ -195,6 +236,8 @@ 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::StrokeLayer, shader_stroke_layer_v, shader_stroke_layer_f))
|
||||
LOG("Failed to create shader StrokeLayer");
|
||||
LOG("shaders initialized");
|
||||
}
|
||||
|
||||
@@ -475,13 +518,6 @@ void App::init()
|
||||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
||||
#endif
|
||||
|
||||
//int n;
|
||||
//glGetIntegerv(GL_NUM_EXTENSIONS, &n);
|
||||
//for (int i = 0; i < n; i++)
|
||||
//{
|
||||
// const unsigned char* s = glGetStringi(GL_EXTENSIONS, i);
|
||||
// LOG("GL ext %03d: %s\n", i, s);
|
||||
//}
|
||||
LOG("GL version: %s", glGetString(GL_VERSION));
|
||||
LOG("GL vendor: %s", glGetString(GL_VENDOR));
|
||||
LOG("GL renderer: %s", glGetString(GL_RENDERER));
|
||||
|
||||
Reference in New Issue
Block a user