Changed(added) precision qualifiers

Fixed discard fail
This commit is contained in:
Roman Sorokin 2014-07-29 18:55:55 +03:00 committed by Alex Zolotarev
parent 34c67ad4f1
commit 5caabc6062
3 changed files with 73 additions and 71 deletions

View file

@ -1,9 +1,8 @@
uniform sampler2D u_textures[8];
varying vec3 v_texcoord;
varying vec4 v_color;
varying vec4 v_outline_color;
varying lowp vec3 v_texcoord;
varying lowp vec4 v_color;
varying lowp vec4 v_outline_color;
const int Index0 = 0;
const int Index1 = 1;
@ -14,21 +13,21 @@ const int Index5 = 5;
const int Index6 = 6;
const int Index7 = 7;
const float OUTLINE_MIN_VALUE0 = 0.49;
const float OUTLINE_MIN_VALUE1 = 0.53;
const float OUTLINE_MAX_VALUE0 = 0.58;
const float OUTLINE_MAX_VALUE1 = 0.6;
const lowp float OUTLINE_MIN_VALUE0 = 0.49;
const lowp float OUTLINE_MIN_VALUE1 = 0.53;
const lowp float OUTLINE_MAX_VALUE0 = 0.58;
const lowp float OUTLINE_MAX_VALUE1 = 0.6;
vec4 colorize(vec4 baseColor)
lowp vec4 colorize(lowp vec4 baseColor)
{
vec4 outline = v_outline_color;
float alpha = 1.0 - baseColor.a;
lowp vec4 outline = v_outline_color;
lowp float alpha = 1.0 - baseColor.a;
if (alpha > OUTLINE_MAX_VALUE1)
return vec4(outline.rgb,0);
return vec4(outline.rgb, 0);
if (alpha > OUTLINE_MAX_VALUE0)
{
float oFactor=smoothstep(OUTLINE_MAX_VALUE1, OUTLINE_MAX_VALUE0, alpha );
lowp float oFactor = smoothstep(OUTLINE_MAX_VALUE1, OUTLINE_MAX_VALUE0, alpha );
return mix(vec4(outline.rgb,0), outline, oFactor);
}
if (alpha > OUTLINE_MIN_VALUE1)
@ -37,28 +36,28 @@ vec4 colorize(vec4 baseColor)
}
if (alpha > OUTLINE_MIN_VALUE0)
{
float oFactor=smoothstep(OUTLINE_MIN_VALUE0, OUTLINE_MIN_VALUE1, alpha );
lowp float oFactor = smoothstep(OUTLINE_MIN_VALUE0, OUTLINE_MIN_VALUE1, alpha );
return mix(v_color, outline, oFactor);
}
return v_color;
}
vec4 without_outline(vec4 baseColor)
lowp vec4 without_outline(lowp vec4 baseColor)
{
vec4 outline = v_outline_color;
float alpha = 1.0 - baseColor.a;
lowp vec4 outline = v_outline_color;
lowp float alpha = 1.0 - baseColor.a;
if (alpha > OUTLINE_MIN_VALUE0)
{
float oFactor=smoothstep(OUTLINE_MIN_VALUE0, OUTLINE_MIN_VALUE1, alpha );
return mix(v_color, vec4(1,1,1,0), oFactor);
lowp float oFactor = smoothstep(OUTLINE_MIN_VALUE0, OUTLINE_MIN_VALUE1, alpha );
return mix(v_color, vec4(1, 1, 1, 0), oFactor);
}
return v_color;
}
void main (void)
{
float alpha;
lowp float alpha;
int textureIndex = int(v_texcoord.z / 2.0);
if (textureIndex == Index0)
alpha = texture2D(u_textures[Index0], v_texcoord.xy).a;
@ -77,7 +76,7 @@ void main (void)
else if (textureIndex == Index7)
alpha = texture2D(u_textures[Index7], v_texcoord.xy).a;
float needOutline = (fract(v_texcoord.z / 2.0)) * 2.0;
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));
else

View file

@ -1,14 +1,14 @@
attribute vec4 a_position;
attribute vec4 a_texcoord;
attribute vec4 a_color;
attribute vec4 a_outline_color;
attribute highp vec4 a_position;
attribute lowp vec4 a_texcoord;
attribute lowp vec4 a_color;
attribute lowp vec4 a_outline_color;
uniform highp mat4 modelView;
uniform highp mat4 projection;
varying vec3 v_texcoord;
varying vec4 v_color;
varying vec4 v_outline_color;
varying lowp vec3 v_texcoord;
varying lowp vec4 v_color;
varying lowp vec4 v_outline_color;
void main()
{

View file

@ -3,56 +3,40 @@ 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 baseColor;
varying lowp vec4 outlineColor;
void sphere_join(vec2 xy)
void sphere_join(highp float gip2)
{
float r = v_radius.y;
float gip2 = xy.x*xy.x + xy.y*xy.y;
if(gip2 > r * r)
discard;
highp float r = v_radius.y;
gl_FragColor = baseColor;
if (gip2 > v_radius.w * v_radius.w)
{
gl_FragColor = vec4(outlineColor.rgb, outlineColor.a * (v_radius.y - sqrt(gip2)) / (v_radius.y - v_radius.w));
if (v_type.x > 0.6)
gl_FragColor = vec4(outlineColor.rgb, outlineColor.a * (v_radius.z - abs(v_dx * v_radius.z)) / r * 2.0);
}
else
{
gl_FragColor = baseColor;
if (gip2 > v_radius.w * v_radius.w)
if (v_type.x > 0.6)
{
gl_FragColor = vec4(outlineColor.rgb, outlineColor.a * (v_radius.y - sqrt(gip2)) / (v_radius.y - v_radius.w));
if (v_type.x > 0.6)
gl_FragColor = vec4(outlineColor.rgb, outlineColor.a * (v_radius.z - abs(v_dx * v_radius.z)) / r * 2.0);
}
else
{
gl_FragColor = baseColor;
if (v_type.x > 0.6)
{
if (abs(v_dx*v_radius.z) / 2.0 >= v_radius.z / 2.0 - r + v_radius.w)
gl_FragColor = vec4(outlineColor.rgb, outlineColor.a * (v_radius.z - abs(v_dx * v_radius.z)) / (r-v_radius.w));
else
gl_FragColor = baseColor;
}
if (abs(v_dx*v_radius.z) / 2.0 >= v_radius.z / 2.0 - r + v_radius.w)
gl_FragColor = vec4(outlineColor.rgb, outlineColor.a * (v_radius.z - abs(v_dx * v_radius.z)) / (r-v_radius.w));
else
gl_FragColor = baseColor;
}
}
}
void sphere_cap(float x, float y)
{
float sq = x*x + y*y;
if (sq >= v_radius.y * v_radius.y)
discard;
if (sq > v_radius.w * v_radius.w)
gl_FragColor = vec4(outlineColor.rgb, outlineColor.a * (v_radius.y - sqrt(sq)) / (v_radius.y - v_radius.w));
}
void main(void)
{
float r = v_radius.y;
float dist = abs(v_radius.x);
highp float r = v_radius.y;
highp float dist = abs(v_radius.x);
gl_FragColor = baseColor;
if (v_type.x > 0.5)
{
float coord = (v_dx + 1.0) * v_radius.y / 2.0;
highp float coord = (v_dx + 1.0) * v_radius.y / 2.0;
if (v_type.y > 0.5)
{
if (coord > v_radius.w)
@ -60,7 +44,7 @@ void main(void)
if (dist > v_radius.w)
{
float alpha = min((1.0 - (coord - v_radius.w) / (v_radius.y - v_radius.w)), (v_radius.y - dist) / (v_radius.y - v_radius.w));
lowp float alpha = min((1.0 - (coord - v_radius.w) / (v_radius.y - v_radius.w)), (v_radius.y - dist) / (v_radius.y - v_radius.w));
gl_FragColor = vec4(outlineColor.rgb, outlineColor.a * alpha);
}
@ -72,17 +56,22 @@ void main(void)
if (dist > v_radius.w)
{
float alpha = min(coord / (v_radius.y - v_radius.w), (v_radius.y - dist) / (v_radius.y - v_radius.w));
lowp float alpha = min(coord / (v_radius.y - v_radius.w), (v_radius.y - dist) / (v_radius.y - v_radius.w));
gl_FragColor = vec4(outlineColor.rgb, outlineColor.a * alpha);
}
}
}
else if (v_type.x < -0.5)
{
if (v_type.y > 0.5)
sphere_cap(dist, (v_dx + 1.0) * v_radius.y / 2.0);
else
sphere_cap(dist, v_radius.y - (v_dx + 1.0) * v_radius.y / 2.0);
highp float y = (v_dx + 1.0) * v_radius.y / 2.0;
if (v_type.y < 0.5)
y = v_radius.y - (v_dx + 1.0) * v_radius.y / 2.0;
highp float sq = dist*dist + y*y;
if (sq >= v_radius.y * v_radius.y)
discard;
if (sq > v_radius.w * v_radius.w)
gl_FragColor = vec4(outlineColor.rgb, outlineColor.a * (v_radius.y - sqrt(sq)) / (v_radius.y - v_radius.w));
}
else
{
@ -93,9 +82,23 @@ void main(void)
if (v_type.y>0.1)
{
if (v_dx >= 1.0)
sphere_join(vec2(dist, (v_dx - 1.0) * v_radius.z / 2.0));
{
highp float y = (v_dx - 1.0) * v_radius.z / 2.0;
highp float gip2 = dist*dist + y*y;
if(gip2 > v_radius.y * v_radius.y)
discard;
else
sphere_join(gip2);
}
else if (v_dx <= -1.0)
sphere_join(vec2(dist, (v_dx + 1.0) * v_radius.z / 2.0));
{
highp float y = (v_dx + 1.0) * v_radius.z / 2.0;
highp float gip2 = dist*dist + y*y;
if(gip2 > v_radius.y * v_radius.y)
discard;
else
sphere_join(gip2);
}
}
}
}