Evas masking: Simplify map masking shaders.

Use vertex shader for all coordinates computations.
This reduces the number of varyings used.
This commit is contained in:
Jean-Philippe Andre 2015-02-26 17:19:07 +09:00
parent 053430739e
commit b815f57078
9 changed files with 66 additions and 76 deletions

View File

@ -2711,14 +2711,13 @@ static const char const map_mask_frag_glsl[] =
"#endif\n"
"#endif\n"
"uniform sampler2D tex, texm;\n"
"varying vec2 tex_c;\n"
"varying vec4 mask_Position, col, mask_Absolute;\n"
"varying vec2 tex_c, tex_m;\n"
"varying vec4 col;\n"
"void main()\n"
"{\n"
" // FIXME: Use mask coordinates within its texture\n"
" // FIXME: Fix Mach band effect using proper 4-point color interpolation\n"
" vec2 mpos = vec2(mask_Position.xy - mask_Absolute.xy) * mask_Absolute.zw;\n"
" gl_FragColor = texture2D(tex, tex_c.xy).bgra * texture2D(texm, mpos).a * col;\n"
" gl_FragColor = texture2D(tex, tex_c).bgra * texture2D(texm, tex_m).a * col;\n"
"}\n";
Evas_GL_Program_Source shader_map_mask_frag_src =
{
@ -2734,8 +2733,8 @@ static const char const map_mask_vert_glsl[] =
"attribute vec4 vertex, color;\n"
"attribute vec2 tex_coord, tex_coordm, tex_sample, tex_coorda;\n"
"uniform mat4 mvp;\n"
"varying vec2 tex_c;\n"
"varying vec4 mask_Position, col, mask_Absolute;\n"
"varying vec2 tex_c, tex_m;\n"
"varying vec4 col;\n"
"void main()\n"
"{\n"
" gl_Position = mvp * vertex;\n"
@ -2744,8 +2743,8 @@ static const char const map_mask_vert_glsl[] =
" // tex_coorda contains the Y-invert flag\n"
" // tex_coordm contains the X,Y position of the mask\n"
" // tex_sample contains the W,H size of the mask (inverted)\n"
" mask_Position = mvp * vertex * vec4(tex_coorda.x * 0.5, tex_coorda.y * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);\n"
" mask_Absolute = vec4(tex_coordm, tex_sample); // x, y, 1/w, 1/h on canvas in GL coords\n"
" vec4 mask_Position = mvp * vertex * vec4(tex_coorda.x * 0.5, tex_coorda.y * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);\n"
" tex_m = vec2(mask_Position.xy - tex_coordm) * tex_sample;\n"
"}\n";
Evas_GL_Program_Source shader_map_mask_vert_src =
{
@ -2763,13 +2762,10 @@ static const char const map_mask_nomul_frag_glsl[] =
"#endif\n"
"#endif\n"
"uniform sampler2D tex, texm;\n"
"varying vec2 tex_c;\n"
"varying vec4 mask_Position, mask_Absolute;\n"
"varying vec2 tex_c, tex_m;\n"
"void main()\n"
"{\n"
" // FIXME: Use mask coordinates within its texture\n"
" vec2 mpos = vec2(mask_Position.xy - mask_Absolute.xy) * mask_Absolute.zw;\n"
" gl_FragColor = texture2D(tex, tex_c.xy).bgra * texture2D(texm, mpos).a;\n"
" gl_FragColor = texture2D(tex, tex_c).bgra * texture2D(texm, tex_m).a;\n"
"}\n";
Evas_GL_Program_Source shader_map_mask_nomul_frag_src =
{
@ -2783,17 +2779,18 @@ static const char const map_mask_nomul_vert_glsl[] =
"precision highp float;\n"
"#endif\n"
"attribute vec4 vertex;\n"
"attribute vec2 tex_coord, tex_coordm, tex_sample;\n"
"attribute vec2 tex_coord, tex_coordm, tex_sample, tex_coorda;\n"
"uniform mat4 mvp;\n"
"varying vec2 tex_c;\n"
"varying vec4 mask_Position, mask_Absolute;\n"
"varying vec2 tex_c, tex_m;\n"
"void main()\n"
"{\n"
" gl_Position = mvp * vertex;\n"
" tex_c = tex_coord;\n"
" // Assume Y-invert on mask, normalize (screen to texture mode coordinates)\n"
" mask_Position = mvp * vertex * vec4(0.5, -0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);\n"
" mask_Absolute = vec4(tex_coordm, tex_sample); // x, y, 1/w, 1/h on canvas in GL coords\n"
" // tex_coorda contains the Y-invert flag\n"
" // tex_coordm contains the X,Y position of the mask\n"
" // tex_sample contains the W,H size of the mask (inverted)\n"
" vec4 mask_Position = mvp * vertex * vec4(tex_coorda.x * 0.5, tex_coorda.y * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);\n"
" tex_m = vec2(mask_Position.xy - tex_coordm) * tex_sample;\n"
"}\n";
Evas_GL_Program_Source shader_map_mask_nomul_vert_src =
{
@ -2811,14 +2808,13 @@ static const char const map_mask_bgra_frag_glsl[] =
"#endif\n"
"#endif\n"
"uniform sampler2D tex, texm;\n"
"varying vec2 tex_c;\n"
"varying vec4 mask_Position, col, mask_Absolute;\n"
"varying vec2 tex_c, tex_m;\n"
"varying vec4 col;\n"
"void main()\n"
"{\n"
" // FIXME: Use mask coordinates within its texture\n"
" // FIXME: Fix Mach band effect using proper 4-point color interpolation\n"
" vec2 mpos = vec2(mask_Position.xy - mask_Absolute.xy) * mask_Absolute.zw;\n"
" gl_FragColor = texture2D(tex, tex_c.xy) * texture2D(texm, mpos).a * col;\n"
" gl_FragColor = texture2D(tex, tex_c) * texture2D(texm, tex_m).a * col;\n"
"}\n";
Evas_GL_Program_Source shader_map_mask_bgra_frag_src =
{
@ -2834,8 +2830,8 @@ static const char const map_mask_bgra_vert_glsl[] =
"attribute vec4 vertex, color;\n"
"attribute vec2 tex_coord, tex_coordm, tex_sample, tex_coorda;\n"
"uniform mat4 mvp;\n"
"varying vec2 tex_c;\n"
"varying vec4 mask_Position, col, mask_Absolute;\n"
"varying vec2 tex_c, tex_m;\n"
"varying vec4 col;\n"
"void main()\n"
"{\n"
" gl_Position = mvp * vertex;\n"
@ -2844,8 +2840,8 @@ static const char const map_mask_bgra_vert_glsl[] =
" // tex_coorda contains the Y-invert flag\n"
" // tex_coordm contains the X,Y position of the mask\n"
" // tex_sample contains the W,H size of the mask (inverted)\n"
" mask_Position = mvp * vertex * vec4(tex_coorda.x * 0.5, tex_coorda.y * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);\n"
" mask_Absolute = vec4(tex_coordm, tex_sample); // x, y, 1/w, 1/h on canvas in GL coords\n"
" vec4 mask_Position = mvp * vertex * vec4(tex_coorda.x * 0.5, tex_coorda.y * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);\n"
" tex_m = vec2(mask_Position.xy - tex_coordm) * tex_sample;\n"
"}\n";
Evas_GL_Program_Source shader_map_mask_bgra_vert_src =
{
@ -2863,13 +2859,10 @@ static const char const map_mask_bgra_nomul_frag_glsl[] =
"#endif\n"
"#endif\n"
"uniform sampler2D tex, texm;\n"
"varying vec2 tex_c;\n"
"varying vec4 mask_Position, mask_Absolute;\n"
"varying vec2 tex_c, tex_m;\n"
"void main()\n"
"{\n"
" // FIXME: Use mask coordinates within its texture\n"
" vec2 mpos = vec2(mask_Position.xy - mask_Absolute.xy) * mask_Absolute.zw;\n"
" gl_FragColor = texture2D(tex, tex_c.xy) * texture2D(texm, mpos).a;\n"
" gl_FragColor = texture2D(tex, tex_c) * texture2D(texm, tex_m).a;\n"
"}\n";
Evas_GL_Program_Source shader_map_mask_bgra_nomul_frag_src =
{
@ -2883,17 +2876,18 @@ static const char const map_mask_bgra_nomul_vert_glsl[] =
"precision highp float;\n"
"#endif\n"
"attribute vec4 vertex;\n"
"attribute vec2 tex_coord, tex_coordm, tex_sample;\n"
"attribute vec2 tex_coord, tex_coordm, tex_sample, tex_coorda;\n"
"uniform mat4 mvp;\n"
"varying vec2 tex_c;\n"
"varying vec4 mask_Position, mask_Absolute;\n"
"varying vec2 tex_c, tex_m;\n"
"void main()\n"
"{\n"
" gl_Position = mvp * vertex;\n"
" tex_c = tex_coord;\n"
" // Assume Y-invert on mask, normalize (screen to texture mode coordinates)\n"
" mask_Position = mvp * vertex * vec4(0.5, -0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);\n"
" mask_Absolute = vec4(tex_coordm, tex_sample); // x, y, 1/w, 1/h on canvas in GL coords\n"
" // tex_coorda contains the Y-invert flag\n"
" // tex_coordm contains the X,Y position of the mask\n"
" // tex_sample contains the W,H size of the mask (inverted)\n"
" vec4 mask_Position = mvp * vertex * vec4(tex_coorda.x * 0.5, tex_coorda.y * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);\n"
" tex_m = vec2(mask_Position.xy - tex_coordm) * tex_sample;\n"
"}\n";
Evas_GL_Program_Source shader_map_mask_bgra_nomul_vert_src =
{

View File

@ -6,12 +6,11 @@ precision mediump float;
#endif
#endif
uniform sampler2D tex, texm;
varying vec2 tex_c;
varying vec4 mask_Position, col, mask_Absolute;
varying vec2 tex_c, tex_m;
varying vec4 col;
void main()
{
// FIXME: Use mask coordinates within its texture
// FIXME: Fix Mach band effect using proper 4-point color interpolation
vec2 mpos = vec2(mask_Position.xy - mask_Absolute.xy) * mask_Absolute.zw;
gl_FragColor = texture2D(tex, tex_c.xy) * texture2D(texm, mpos).a * col;
gl_FragColor = texture2D(tex, tex_c) * texture2D(texm, tex_m).a * col;
}

View File

@ -6,11 +6,8 @@ precision mediump float;
#endif
#endif
uniform sampler2D tex, texm;
varying vec2 tex_c;
varying vec4 mask_Position, mask_Absolute;
varying vec2 tex_c, tex_m;
void main()
{
// FIXME: Use mask coordinates within its texture
vec2 mpos = vec2(mask_Position.xy - mask_Absolute.xy) * mask_Absolute.zw;
gl_FragColor = texture2D(tex, tex_c.xy) * texture2D(texm, mpos).a;
gl_FragColor = texture2D(tex, tex_c) * texture2D(texm, tex_m).a;
}

View File

@ -2,16 +2,18 @@
precision highp float;
#endif
attribute vec4 vertex;
attribute vec2 tex_coord, tex_coordm, tex_sample;
attribute vec2 tex_coord, tex_coordm, tex_sample, tex_coorda;
uniform mat4 mvp;
varying vec2 tex_c;
varying vec4 mask_Position, mask_Absolute;
varying vec2 tex_c, tex_m;
void main()
{
gl_Position = mvp * vertex;
tex_c = tex_coord;
// Assume Y-invert on mask, normalize (screen to texture mode coordinates)
mask_Position = mvp * vertex * vec4(0.5, -0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);
mask_Absolute = vec4(tex_coordm, tex_sample); // x, y, 1/w, 1/h on canvas in GL coords
// tex_coorda contains the Y-invert flag
// tex_coordm contains the X,Y position of the mask
// tex_sample contains the W,H size of the mask (inverted)
vec4 mask_Position = mvp * vertex * vec4(tex_coorda.x * 0.5, tex_coorda.y * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);
tex_m = vec2(mask_Position.xy - tex_coordm) * tex_sample;
}

View File

@ -4,8 +4,8 @@ precision highp float;
attribute vec4 vertex, color;
attribute vec2 tex_coord, tex_coordm, tex_sample, tex_coorda;
uniform mat4 mvp;
varying vec2 tex_c;
varying vec4 mask_Position, col, mask_Absolute;
varying vec2 tex_c, tex_m;
varying vec4 col;
void main()
{
gl_Position = mvp * vertex;
@ -16,6 +16,6 @@ void main()
// tex_coordm contains the X,Y position of the mask
// tex_sample contains the W,H size of the mask (inverted)
mask_Position = mvp * vertex * vec4(tex_coorda.x * 0.5, tex_coorda.y * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);
mask_Absolute = vec4(tex_coordm, tex_sample); // x, y, 1/w, 1/h on canvas in GL coords
vec4 mask_Position = mvp * vertex * vec4(tex_coorda.x * 0.5, tex_coorda.y * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);
tex_m = vec2(mask_Position.xy - tex_coordm) * tex_sample;
}

View File

@ -6,12 +6,11 @@ precision mediump float;
#endif
#endif
uniform sampler2D tex, texm;
varying vec2 tex_c;
varying vec4 mask_Position, col, mask_Absolute;
varying vec2 tex_c, tex_m;
varying vec4 col;
void main()
{
// FIXME: Use mask coordinates within its texture
// FIXME: Fix Mach band effect using proper 4-point color interpolation
vec2 mpos = vec2(mask_Position.xy - mask_Absolute.xy) * mask_Absolute.zw;
gl_FragColor = texture2D(tex, tex_c.xy).bgra * texture2D(texm, mpos).a * col;
gl_FragColor = texture2D(tex, tex_c).bgra * texture2D(texm, tex_m).a * col;
}

View File

@ -6,11 +6,8 @@ precision mediump float;
#endif
#endif
uniform sampler2D tex, texm;
varying vec2 tex_c;
varying vec4 mask_Position, mask_Absolute;
varying vec2 tex_c, tex_m;
void main()
{
// FIXME: Use mask coordinates within its texture
vec2 mpos = vec2(mask_Position.xy - mask_Absolute.xy) * mask_Absolute.zw;
gl_FragColor = texture2D(tex, tex_c.xy).bgra * texture2D(texm, mpos).a;
gl_FragColor = texture2D(tex, tex_c).bgra * texture2D(texm, tex_m).a;
}

View File

@ -2,16 +2,18 @@
precision highp float;
#endif
attribute vec4 vertex;
attribute vec2 tex_coord, tex_coordm, tex_sample;
attribute vec2 tex_coord, tex_coordm, tex_sample, tex_coorda;
uniform mat4 mvp;
varying vec2 tex_c;
varying vec4 mask_Position, mask_Absolute;
varying vec2 tex_c, tex_m;
void main()
{
gl_Position = mvp * vertex;
tex_c = tex_coord;
// Assume Y-invert on mask, normalize (screen to texture mode coordinates)
mask_Position = mvp * vertex * vec4(0.5, -0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);
mask_Absolute = vec4(tex_coordm, tex_sample); // x, y, 1/w, 1/h on canvas in GL coords
// tex_coorda contains the Y-invert flag
// tex_coordm contains the X,Y position of the mask
// tex_sample contains the W,H size of the mask (inverted)
vec4 mask_Position = mvp * vertex * vec4(tex_coorda.x * 0.5, tex_coorda.y * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);
tex_m = vec2(mask_Position.xy - tex_coordm) * tex_sample;
}

View File

@ -4,8 +4,8 @@ precision highp float;
attribute vec4 vertex, color;
attribute vec2 tex_coord, tex_coordm, tex_sample, tex_coorda;
uniform mat4 mvp;
varying vec2 tex_c;
varying vec4 mask_Position, col, mask_Absolute;
varying vec2 tex_c, tex_m;
varying vec4 col;
void main()
{
gl_Position = mvp * vertex;
@ -16,6 +16,6 @@ void main()
// tex_coordm contains the X,Y position of the mask
// tex_sample contains the W,H size of the mask (inverted)
mask_Position = mvp * vertex * vec4(tex_coorda.x * 0.5, tex_coorda.y * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);
mask_Absolute = vec4(tex_coordm, tex_sample); // x, y, 1/w, 1/h on canvas in GL coords
vec4 mask_Position = mvp * vertex * vec4(tex_coorda.x * 0.5, tex_coorda.y * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);
tex_m = vec2(mask_Position.xy - tex_coordm) * tex_sample;
}