Shaders changed to use texture of colors

This commit is contained in:
Roman Sorokin 2014-09-15 12:58:42 +03:00 committed by Alex Zolotarev
parent 09e13c7196
commit 980dc30a5d
9 changed files with 54 additions and 31 deletions

View file

@ -1,6 +1,6 @@
varying lowp vec3 v_texcoord;
varying lowp vec4 v_color;
varying lowp vec4 v_outline_color;
varying lowp vec4 v_colors;
varying mediump float v_index;
~getTexel~
@ -13,7 +13,9 @@ const lowp float GLYPH_MAX_VALUE = 0.6;
lowp vec4 colorize(lowp vec4 baseColor)
{
lowp vec4 outline = v_outline_color;
int textureIndex = int(v_index);
lowp vec4 outline = getTexel(textureIndex, v_colors.zw);
lowp vec4 base = getTexel(textureIndex, v_colors.xy);
lowp float alpha = 1.0 - baseColor.a;
if (alpha > OUTLINE_MAX_VALUE1)
@ -30,32 +32,35 @@ lowp vec4 colorize(lowp vec4 baseColor)
if (alpha > OUTLINE_MIN_VALUE0)
{
lowp float oFactor = smoothstep(OUTLINE_MIN_VALUE0, OUTLINE_MIN_VALUE1, alpha );
return mix(v_color, outline, oFactor);
return mix(base, outline, oFactor);
}
return v_color;
return base;
}
lowp vec4 without_outline(lowp vec4 baseColor)
{
lowp vec4 outline = v_outline_color;
int textureIndex = int(v_index);
lowp vec4 base = getTexel(textureIndex, v_colors.xy);
lowp float alpha = 1.0 - baseColor.a;
if (alpha > GLYPH_MIN_VALUE)
{
lowp float oFactor = smoothstep(GLYPH_MIN_VALUE, GLYPH_MAX_VALUE, alpha );
return mix(v_color, vec4(1, 1, 1, 0), oFactor);
return mix(base, vec4(1, 1, 1, 0), oFactor);
}
return v_color;
return base;
}
void main (void)
{
int textureIndex = int(v_texcoord.z / 2.0);
int textureIndex2 = int(v_index);
lowp vec4 base = getTexel(textureIndex2, v_colors.xy);
mediump float alpha = getTexel(textureIndex, v_texcoord.xy).a;
lowp float needOutline = (fract(v_texcoord.z / 2.0)) * 2.0;
if (needOutline > 0.5)
gl_FragColor = colorize(vec4(v_color.rgb, v_color.a*alpha));
gl_FragColor = colorize(vec4(base.rgb, base.a*alpha));
else
gl_FragColor = without_outline(vec4(v_color.rgb, v_color.a*alpha));
gl_FragColor = without_outline(vec4(base.rgb, base.a*alpha));
}

View file

@ -1,20 +1,20 @@
attribute highp vec4 a_position;
attribute lowp vec4 a_texcoord;
attribute lowp vec4 a_color;
attribute lowp vec4 a_outline_color;
attribute mediump float a_index;
uniform highp mat4 modelView;
uniform highp mat4 projection;
varying lowp vec3 v_texcoord;
varying lowp vec4 v_color;
varying lowp vec4 v_outline_color;
varying lowp vec4 v_colors;
varying mediump float v_index;
void main()
{
gl_Position = (vec4(a_position.zw, 0, 0) + (vec4(a_position.xy, a_texcoord.w, 1) * modelView)) * projection;
v_texcoord = a_texcoord.xyz;
v_color = a_color;
v_outline_color = a_outline_color;
v_colors = a_color;
v_index = a_index;
}

View file

@ -8,12 +8,17 @@ varying MAXPREC vec4 v_radius;
varying MAXPREC vec4 v_centres;
varying MAXPREC vec2 v_type;
varying lowp vec4 baseColor;
varying lowp vec4 outlineColor;
varying lowp vec4 v_colors;
varying lowp float v_index;
~getTexel~
void sphere_join(MAXPREC float gip2)
{
MAXPREC float r = v_radius.y;
int textureIndex = int(v_index);
lowp vec4 baseColor = getTexel(textureIndex, v_colors.xy);
lowp vec4 outlineColor = getTexel(textureIndex, v_colors.zw);
gl_FragColor = baseColor;
if (gip2 > v_radius.w * v_radius.w)
{
@ -36,6 +41,9 @@ void sphere_join(MAXPREC float gip2)
void main(void)
{
int textureIndex = int(v_index);
lowp vec4 baseColor = getTexel(textureIndex, v_colors.xy);
lowp vec4 outlineColor = getTexel(textureIndex, v_colors.zw);
MAXPREC float r = v_radius.y;
MAXPREC float dist = abs(v_radius.x);
gl_FragColor = baseColor;

View file

@ -2,16 +2,16 @@ attribute highp vec4 position;
attribute highp vec4 deltas;
attribute highp vec4 width_type;
attribute highp vec4 centres;
attribute highp vec4 color1;
attribute highp vec4 color2;
attribute lowp vec4 colors;
attribute mediump float index;
varying highp float v_dx;
varying highp vec4 v_radius;
varying highp vec4 v_centres;
varying highp vec2 v_type;
varying highp vec4 baseColor;
varying highp vec4 outlineColor;
varying lowp vec4 v_colors;
varying mediump float v_index;
uniform highp mat4 modelView;
uniform highp mat4 projection;
@ -43,6 +43,6 @@ void main(void)
v_centres.zw = centr2;
v_type = width_type.yz;
baseColor = color1;
outlineColor = color2;
v_colors = colors;
v_index = index;
}

View file

@ -1,10 +1,14 @@
attribute vec4 a_position;
attribute vec4 a_normal;
attribute vec3 a_color_index;
uniform mat4 modelView;
uniform mat4 projection;
varying mediump vec3 v_color_index;
void main(void)
{
gl_Position = ((a_position * modelView) + a_normal) * projection;
v_color_index = a_color_index;
}

View file

@ -1,20 +1,20 @@
attribute vec2 a_position;
attribute vec4 a_texcoord;
attribute vec4 a_color;
attribute vec4 a_outline_color;
attribute float a_index;
uniform highp mat4 modelView;
uniform highp mat4 projection;
varying vec3 v_texcoord;
varying vec4 v_color;
varying vec4 v_outline_color;
varying lowp vec4 v_colors;
varying mediump float v_index;
void main()
{
gl_Position = vec4(a_position, a_texcoord.w, 1) * modelView * projection;
v_texcoord = a_texcoord.xyz;
v_color = a_color;
v_outline_color = a_outline_color;
v_colors = a_color;
v_index = a_index;
}

View file

@ -1,9 +1,13 @@
attribute vec4 a_position;
attribute vec3 a_color_index;
uniform mat4 modelView;
uniform mat4 projection;
varying mediump vec3 v_color_index;
void main(void)
{
gl_Position = a_position * modelView * projection;
v_color_index = a_color_index;
}

View file

@ -1,6 +1,9 @@
uniform lowp vec4 u_color;
varying mediump vec3 v_color_index;
~getTexel~
void main(void)
{
gl_FragColor = u_color;
int textureIndex = int(v_color_index.z);
gl_FragColor = getTexel(textureIndex, v_color_index.xy);
}

View file

@ -10,7 +10,6 @@ varying MAXPREC float v_textureIndex;
void main(void)
{
lowp vec4 color;
int textureIndex = int(v_textureIndex);
gl_FragColor = getTexel(textureIndex, v_texCoords);
}