add ComboBox node, add blend modes button in stroke panel, move brush shader code to ShaderManager and avoid the same shader being recompiled many times
This commit is contained in:
@@ -100,9 +100,10 @@ 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_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_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_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"
|
||||
"void main(){\n"
|
||||
" mediump vec2 uv2 = gl_FragCoord.st / vec2(2048) * 20.0;\n"
|
||||
" mediump vec4 base = texture(tex, uv.xy);\n"
|
||||
@@ -113,7 +114,7 @@ void App::initShaders()
|
||||
" if (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_multiply(base, stroke, alpha_tot);\n"
|
||||
" mediump vec3 rgb = blend_screen(base, stroke, alpha_tot);\n"
|
||||
" frag = vec4(rgb, (lock ? base.a : alpha_tot));\n"
|
||||
"}\n";
|
||||
|
||||
@@ -330,6 +331,38 @@ void App::initShaders()
|
||||
" frag = texture(tex, dir);\n"
|
||||
"}";
|
||||
|
||||
// STROKE - INSTANCED
|
||||
static const char* shader_stroke_inst_v =
|
||||
SHADER_VERSION
|
||||
"in vec4 pos;"
|
||||
"in vec2 uvs;"
|
||||
"in mat4 a_mvp;"
|
||||
"in float a_flow;"
|
||||
"out vec3 uv;"
|
||||
"out float alpha;"
|
||||
"void main(){"
|
||||
" uv = vec3(uvs, pos.w);"
|
||||
" alpha = a_flow;"
|
||||
" gl_Position = a_mvp * vec4(pos.xyz, 1.0);"
|
||||
"}";
|
||||
static const char* shader_stroke_inst_f =
|
||||
SHADER_VERSION
|
||||
"uniform mediump sampler2D tex;"
|
||||
"uniform mediump sampler2D tex_stencil;\n"
|
||||
"uniform mediump vec4 col;"
|
||||
"uniform mediump vec2 resolution;\n"
|
||||
"uniform mediump vec2 stencil_offset;\n"
|
||||
"uniform mediump float stencil_alpha;\n"
|
||||
"in mediump float alpha;"
|
||||
"in mediump vec3 uv;"
|
||||
"out mediump vec4 frag;"
|
||||
"void main(){"
|
||||
" mediump vec2 uv2 = gl_FragCoord.st / resolution;\n"
|
||||
" mediump float stencil = 1.0 - (texture(tex_stencil, (uv2+stencil_offset)).r * 0.9) * stencil_alpha;\n"
|
||||
" mediump float a = (1.0 - texture(tex, uv.xy).r) * alpha * stencil;"
|
||||
" frag = vec4(col.rgb, a);"
|
||||
"}";
|
||||
|
||||
LOG("initializing shaders");
|
||||
if (!ShaderManager::create(kShader::Texture, shader_v, shader_f))
|
||||
LOG("Failed to create shader Texture");
|
||||
@@ -359,6 +392,8 @@ void App::initShaders()
|
||||
LOG("Failed to create shader Checkerboard");
|
||||
if (!ShaderManager::create(kShader::Equirect, shader_equirect_v, shader_equirect_f))
|
||||
LOG("Failed to create shader Equirect");
|
||||
if (!ShaderManager::create(kShader::BrushStroke, shader_stroke_inst_v, shader_stroke_inst_f))
|
||||
LOG("Failed to create shader BrushStroke");
|
||||
LOG("shaders initialized");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user