fix shaders for the transform tool

This commit is contained in:
2018-11-25 16:16:01 +01:00
parent a124d19bdc
commit 0d0cd3db7f
8 changed files with 100 additions and 98 deletions

View File

@@ -11,26 +11,25 @@ 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_f =
SHADER_VERSION
"uniform sampler2D tex;"
"in mediump vec3 uv;"
"in mediump vec2 uv;"
"out mediump vec4 frag;"
"void main(){"
//" frag = texture(tex, uv.xy/uv.z);"
" frag = texture(tex, uv.xy);"
" frag = texture(tex, uv);"
"}";
static const char* shader_uv_f =
SHADER_VERSION
"in mediump vec3 uv;"
"in mediump vec2 uv;"
"out mediump vec4 frag;"
"void main(){"
" frag = vec4(uv.xy, 0.0, 1.0);"
" frag = vec4(uv, 0.0, 1.0);"
"}";
// TEXTURE ALPHA
static const char* shader_alpha_f =
@@ -38,13 +37,13 @@ void App::initShaders()
"uniform sampler2D tex;\n"
"uniform mediump float alpha;\n"
"uniform bool highlight;\n"
"in mediump vec3 uv;\n"
"in mediump vec2 uv;\n"
"out mediump vec4 frag;\n"
"void main(){\n"
" mediump vec4 c = texture(tex, uv.xy);\n"
" mediump vec4 c = texture(tex, uv);\n"
" frag = highlight ? \n"
" vec4(clamp(vec3(.3)+c.rgb, vec3(0), vec3(1)), c.a) : \n"
" texture(tex, uv.xy) * vec4(1,1,1,alpha);\n"
" vec4(clamp(vec3(0.3) + c.rgb, vec3(0.0), vec3(1.0)), c.a) : \n"
" c * vec4(1.0, 1.0, 1.0, alpha);\n"
"}\n";
// TEXTURE ALPHA SEPARATED
static const char* shader_alpha_sep_f =
@@ -53,15 +52,15 @@ void App::initShaders()
"uniform sampler2D tex_alpha;\n"
"uniform mediump float alpha;\n"
"uniform bool highlight;\n"
"in mediump vec3 uv;\n"
"in mediump vec2 uv;\n"
"out mediump vec4 frag;\n"
"void main(){\n"
" mediump vec3 rgb = texture(tex, uv.xy).rgb;\n"
" mediump float a = texture(tex_alpha, uv.xy).a;\n"
" mediump vec3 rgb = texture(tex, uv).rgb;\n"
" mediump float a = texture(tex_alpha, uv).a;\n"
" mediump vec4 c = vec4(rgb, a);\n"
" frag = highlight ? \n"
" vec4(clamp(vec3(.3)+c.rgb, vec3(0), vec3(1)), c.a) : \n"
" texture(tex, uv.xy) * vec4(1,1,1,alpha);\n"
" vec4(clamp(vec3(0.3) + c.rgb, vec3(0.0), vec3(1.0)), c.a) : \n"
" texture(tex, uv) * vec4(1.0, 1.0, 1.0, alpha);\n"
"}\n";
// STROKE PREVIEW
static const char* shader_stroke_preview_f =
@@ -69,10 +68,10 @@ void App::initShaders()
"uniform sampler2D tex;\n"
"uniform mediump float alpha;\n"
"uniform mediump vec4 col;\n"
"in mediump vec3 uv;\n"
"in mediump vec2 uv;\n"
"out mediump vec4 frag;\n"
"void main(){\n"
" mediump float stroke = 1.0 - texture(tex, uv.xy).r;\n"
" mediump float stroke = 1.0 - texture(tex, uv).r;\n"
" frag = vec4(col.rgb, stroke * alpha);\n"
"}";
// TEXTURE COMP ERASE
@@ -80,14 +79,15 @@ void App::initShaders()
SHADER_VERSION
"uniform sampler2D tex;\n"
"uniform sampler2D tex_stroke;\n"
"uniform sampler2D tex_mask;\n"
"uniform mediump float alpha;\n"
"uniform bool lock;\n"
"in mediump vec3 uv;\n"
"uniform mediump vec2 resolution;\n"
"uniform bool fragUV2;\n"
"in mediump vec2 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 vec2 uv2 = fragUV2 ? (gl_FragCoord.st / resolution) : uv;\n"
" mediump vec4 base = texture(tex, uv2);\n"
" mediump vec4 stroke = texture(tex_stroke, uv);\n"
" mediump float a = base.a - (stroke.a * alpha);\n"
" frag = vec4(base.rgb, clamp(a, 0.0, 1.0));\n"
"}\n";
@@ -98,13 +98,13 @@ void App::initShaders()
"uniform sampler2D tex_stroke;\n"
"uniform sampler2D tex_mask;\n"
"uniform sampler2D tex_stencil;\n"
//"uniform image2D img_mixer;\n"
"uniform mediump float alpha;\n"
"uniform mediump int blend_mode;\n"
"uniform mediump vec2 resolution;\n"
"uniform bool lock;\n"
"uniform bool mask;\n"
"in mediump vec3 uv;\n"
"uniform bool fragUV2;\n"
"in mediump vec2 uv;\n"
"out mediump vec4 frag;\n"
"mediump vec4 blur(sampler2D t, mediump vec2 uv){\n"
" mediump vec4 sum = texture(t, uv);\n"
@@ -140,9 +140,10 @@ void App::initShaders()
"}\n"
"void main(){\n"
" mediump vec4 base = texture(tex, gl_FragCoord.st / resolution);\n"
" mediump vec4 stroke = texture(tex_stroke, uv.xy);\n"
" stroke.a = mask ? stroke.a * alpha * blur(tex_mask, uv.xy).r : stroke.a * alpha;\n"
" mediump vec2 uv2 = fragUV2 ? (gl_FragCoord.st / resolution) : uv;\n"
" mediump vec4 base = texture(tex, uv2);\n"
" mediump vec4 stroke = texture(tex_stroke, uv);\n"
" stroke.a = mask ? stroke.a * alpha * blur(tex_mask, uv2).r : stroke.a * alpha;\n"
" if (!lock && base.a == 0.0) { frag = stroke; return; }\n"
" mediump float contribution = (1.0 - base.a) * stroke.a;\n"
@@ -242,7 +243,7 @@ void App::initShaders()
" return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);"
"}"
"void main() {"
" mediump float sat = tan(atan(uv.y, uv.x)) *.5 + .5;"
" mediump float sat = tan(atan(uv.y, uv.x)) * 0.5 + 0.5;"
" frag = vec4(hsv2rgb(vec3(col.r, sat, uv.x)), 1.0);"
"}";