diff options
author | ExMix <rahuba.youri@mapswithme.com> | 2014-11-18 11:34:39 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:32:54 +0300 |
commit | 8d76e8fee45818e2970b0c821d1c49b979800fc5 (patch) | |
tree | 1cafdb7dc7d8087f6b398fd741d4a993f455abcd /drape | |
parent | e8aa9f19fca234d583bd8f4d39dbab667d6b452c (diff) |
[drape] use max precision for all data expect final color. In future it can be optimized, but now lowp on old devices leads to:
- wrong texel fetch
- performance degradation
Diffstat (limited to 'drape')
-rw-r--r-- | drape/shader.cpp | 8 | ||||
-rwxr-xr-x | drape/shaders/font_fragment_shader.fsh | 41 | ||||
-rwxr-xr-x | drape/shaders/font_vertex_shader.vsh | 26 | ||||
-rw-r--r-- | drape/shaders/line_fragment_shader.fsh | 105 | ||||
-rw-r--r-- | drape/shaders/line_vertex_shader.vsh | 40 | ||||
-rw-r--r-- | drape/shaders/normalize_vertex_shader.vsh | 10 | ||||
-rwxr-xr-x | drape/shaders/path_font_vertex_shader.vsh | 18 | ||||
-rw-r--r-- | drape/shaders/simple_vertex_shader.vsh | 10 | ||||
-rw-r--r-- | drape/shaders/solid_color_fragment_shader.fsh | 10 | ||||
-rw-r--r-- | drape/shaders/texturing_fragment_shader.fsh | 12 | ||||
-rw-r--r-- | drape/shaders/texturing_vertex_shader.vsh | 22 |
11 files changed, 157 insertions, 145 deletions
diff --git a/drape/shader.cpp b/drape/shader.cpp index 9a0f40a4d3..8af53238de 100644 --- a/drape/shader.cpp +++ b/drape/shader.cpp @@ -4,8 +4,6 @@ #include "../base/assert.hpp" #include "../base/string_utils.hpp" - - namespace dp { @@ -40,11 +38,11 @@ void ResolveGetTexel(string & result, string const & sampler, int count) result.append("uniform sampler2D u_textures[").append(to_string(count)).append("];\n"); // Function signature - result.append(MEDIUM_P).append(" vec4 getTexel(int ").append(texIndex).append(", ") - .append(LOW_P).append(" vec2 ").append(texCoord).append("){ \n"); + result.append(LOW_P).append(" vec4 getTexel(int ").append(texIndex).append(", ") + .append(MAXPREC_P).append(" vec2 ").append(texCoord).append("){ \n"); // Declare result var; - result.append(MEDIUM_P).append(" vec4 ").append(answer).append(";\n"); + result.append(LOW_P).append(" vec4 ").append(answer).append(";\n"); for (uint32_t i = 0; i < count; ++i) { diff --git a/drape/shaders/font_fragment_shader.fsh b/drape/shaders/font_fragment_shader.fsh index 2213132d7f..044d66f2ce 100755 --- a/drape/shaders/font_fragment_shader.fsh +++ b/drape/shaders/font_fragment_shader.fsh @@ -1,6 +1,14 @@ -varying lowp vec3 v_texcoord; -varying lowp vec4 v_colors; -varying mediump float v_index; +#ifdef GL_FRAGMENT_PRECISION_HIGH + #define MAXPREC highp +#else + #define MAXPREC mediump +#endif + +precision MAXPREC float; + +varying vec3 v_texcoord; +varying vec4 v_colors; +varying float v_index; ~getTexel~ @@ -11,13 +19,13 @@ const lowp float OUTLINE_MAX_VALUE1 = 0.95; const lowp float GLYPH_MIN_VALUE = 0.45; const lowp float GLYPH_MAX_VALUE = 0.6; -lowp vec4 colorize(lowp vec4 base, lowp vec4 outline, lowp float alpha) +vec4 colorize(vec4 base, vec4 outline, float alpha) { if (alpha > OUTLINE_MAX_VALUE1) return vec4(outline.rgb, 0); if (alpha > OUTLINE_MAX_VALUE0) { - lowp float oFactor = smoothstep(OUTLINE_MAX_VALUE1, OUTLINE_MAX_VALUE0, alpha ); + float oFactor = smoothstep(OUTLINE_MAX_VALUE1, OUTLINE_MAX_VALUE0, alpha ); return mix(vec4(outline.rgb,0), outline, oFactor); } if (alpha > OUTLINE_MIN_VALUE1) @@ -26,17 +34,17 @@ lowp vec4 colorize(lowp vec4 base, lowp vec4 outline, lowp float alpha) } if (alpha > OUTLINE_MIN_VALUE0) { - lowp float oFactor = smoothstep(OUTLINE_MIN_VALUE0, OUTLINE_MIN_VALUE1, alpha ); + float oFactor = smoothstep(OUTLINE_MIN_VALUE0, OUTLINE_MIN_VALUE1, alpha ); return mix(base, outline, oFactor); } return base; } -lowp vec4 without_outline(lowp vec4 base, lowp float alpha) +vec4 without_outline(vec4 base, float alpha) { if (alpha > GLYPH_MIN_VALUE) { - lowp float oFactor = smoothstep(GLYPH_MIN_VALUE, GLYPH_MAX_VALUE, alpha ); + float oFactor = smoothstep(GLYPH_MIN_VALUE, GLYPH_MAX_VALUE, alpha ); return mix(base, vec4(1, 1, 1, 0), oFactor); } return base; @@ -46,13 +54,16 @@ void main (void) { int shapeIndex = int(v_texcoord.z / 2.0); int colorIndex = int(v_index); - lowp vec4 base = getTexel(colorIndex, v_colors.xy); - lowp vec4 outline = getTexel(colorIndex, v_colors.zw); - mediump float alpha = getTexel(shapeIndex, v_texcoord.xy).a; + vec4 base = getTexel(colorIndex, v_colors.xy);; + vec4 outline = getTexel(colorIndex, v_colors.zw); + float alpha = getTexel(shapeIndex, v_texcoord.xy).a; - lowp float needOutline = (fract(v_texcoord.z / 2.0)) * 2.0; + float needOutline = (fract(v_texcoord.z / 2.0)) * 2.0; + vec4 finalColor; if (needOutline > 0.5) - gl_FragColor = colorize(base, outline, 1.0 - base.a*alpha); + finalColor = colorize(base, outline, 1.0 - base.a*alpha); else - gl_FragColor = without_outline(base, 1.0 - base.a*alpha); -} + finalColor = without_outline(base, 1.0 - base.a*alpha); + + gl_FragColor = finalColor; +} diff --git a/drape/shaders/font_vertex_shader.vsh b/drape/shaders/font_vertex_shader.vsh index d7ddece594..d21867074a 100755 --- a/drape/shaders/font_vertex_shader.vsh +++ b/drape/shaders/font_vertex_shader.vsh @@ -1,14 +1,22 @@ -attribute highp vec4 a_position; -attribute lowp vec4 a_texcoord; -attribute lowp vec4 a_color; -attribute mediump float a_index; +#ifdef GL_FRAGMENT_PRECISION_HIGH + #define MAXPREC highp +#else + #define MAXPREC mediump +#endif -uniform highp mat4 modelView; -uniform highp mat4 projection; +precision MAXPREC float; -varying lowp vec3 v_texcoord; -varying lowp vec4 v_colors; -varying mediump float v_index; +attribute vec4 a_position; +attribute vec4 a_texcoord; +attribute vec4 a_color; +attribute float a_index; + +uniform mat4 modelView; +uniform mat4 projection; + +varying vec3 v_texcoord; +varying vec4 v_colors; +varying float v_index; void main() { diff --git a/drape/shaders/line_fragment_shader.fsh b/drape/shaders/line_fragment_shader.fsh index f4f4cbc42c..49be8f77af 100644 --- a/drape/shaders/line_fragment_shader.fsh +++ b/drape/shaders/line_fragment_shader.fsh @@ -3,106 +3,45 @@ #else #define MAXPREC mediump #endif -varying MAXPREC float v_dx; -varying MAXPREC vec4 v_radius; -varying MAXPREC vec2 v_type; -varying lowp vec3 v_color; -varying lowp vec3 v_mask; +precision MAXPREC float; -~getTexel~ +varying float v_dx; +varying vec4 v_radius; +varying vec2 v_type; -void sphere_join(MAXPREC float gip2, lowp vec4 baseColor, lowp vec4 outlineColor) -{ - MAXPREC float r = v_radius.y; - 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 - { - 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)); - } - } -} +varying vec3 v_color; +varying vec3 v_mask; + +~getTexel~ void main(void) { - lowp float alfa = getTexel(int(v_mask.z), v_mask.xy).a; - lowp vec4 color = getTexel(int(v_color.z), v_color.xy) * alfa; - lowp vec4 outlineColor = vec4(0.0, 0.0, 0.0, 0.0); - MAXPREC float r = v_radius.y; - MAXPREC float dist = abs(v_radius.x); - gl_FragColor = color; - if (v_type.x > 0.5) - { - MAXPREC float coord = (v_dx + 1.0) * v_radius.y / 2.0; - if (v_type.y > 0.5) - { - if (coord > v_radius.w) - gl_FragColor = vec4(outlineColor.rgb, outlineColor.a * (1.0 - (coord - v_radius.w) / (v_radius.y - v_radius.w))); - - if (dist > 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); - } - - } - else - { - if (coord < v_radius.y - v_radius.w) - gl_FragColor = vec4(outlineColor.rgb, outlineColor.a * coord / (v_radius.y - v_radius.w)); + float r = v_radius.y; + float dist = abs(v_radius.x); - if (dist > 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.x < -0.5) { - MAXPREC float y = (v_dx + 1.0) * v_radius.y / 2.0; + 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; - MAXPREC float sq = dist*dist + y*y; + 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 { - if (dist > v_radius.w) - gl_FragColor = vec4(outlineColor.rgb, outlineColor.a * (v_radius.y - dist) / (v_radius.y - v_radius.w)); - - if (v_type.y>0.1) + if (v_type.y > 0.1 && abs(v_dx) >= 1.0) { - if (v_dx >= 1.0) - { - MAXPREC float y = (v_dx - 1.0) * v_radius.z / 2.0; - MAXPREC float gip2 = dist*dist + y*y; - if(gip2 > v_radius.y * v_radius.y) - discard; - else - sphere_join(gip2, color, outlineColor); - } - else if (v_dx <= -1.0) - { - MAXPREC float y = (v_dx + 1.0) * v_radius.z / 2.0; - MAXPREC float gip2 = dist*dist + y*y; - if(gip2 > v_radius.y * v_radius.y) - discard; - else - sphere_join(gip2, color, outlineColor); - } + float y = (v_dx + 1.0 * sign(v_dx)) * v_radius.z / 2.0; + float gip2 = dist * dist + y * y; + if(gip2 > v_radius.y * v_radius.y) + discard; } } + + vec4 color = getTexel(int(v_color.z), v_color.xy); + color.a = getTexel(int(v_mask.z), v_mask.xy).a; + gl_FragColor = color; } diff --git a/drape/shaders/line_vertex_shader.vsh b/drape/shaders/line_vertex_shader.vsh index 2a1741f5fb..ce49980ef1 100644 --- a/drape/shaders/line_vertex_shader.vsh +++ b/drape/shaders/line_vertex_shader.vsh @@ -1,19 +1,27 @@ -attribute highp vec4 a_position; -attribute highp vec4 a_deltas; -attribute highp vec4 a_width_type; -attribute highp vec4 a_centres; -attribute lowp vec3 a_color; -attribute lowp vec3 a_mask; - -varying highp float v_dx; -varying highp vec4 v_radius; -varying highp vec2 v_type; - -varying lowp vec3 v_color; -varying lowp vec3 v_mask; - -uniform highp mat4 modelView; -uniform highp mat4 projection; +#ifdef GL_FRAGMENT_PRECISION_HIGH + #define MAXPREC highp +#else + #define MAXPREC mediump +#endif + +precision MAXPREC float; + +attribute vec4 a_position; +attribute vec4 a_deltas; +attribute vec4 a_width_type; +attribute vec4 a_centres; +attribute vec3 a_color; +attribute vec3 a_mask; + +varying float v_dx; +varying vec4 v_radius; +varying vec2 v_type; + +varying vec3 v_color; +varying vec3 v_mask; + +uniform mat4 modelView; +uniform mat4 projection; void main(void) { diff --git a/drape/shaders/normalize_vertex_shader.vsh b/drape/shaders/normalize_vertex_shader.vsh index 972d02f2d0..e01042715e 100644 --- a/drape/shaders/normalize_vertex_shader.vsh +++ b/drape/shaders/normalize_vertex_shader.vsh @@ -1,3 +1,11 @@ +#ifdef GL_FRAGMENT_PRECISION_HIGH + #define MAXPREC highp +#else + #define MAXPREC mediump +#endif + +precision MAXPREC float; + attribute vec4 a_position; attribute vec4 a_normal; attribute vec3 a_color_index; @@ -5,7 +13,7 @@ attribute vec3 a_color_index; uniform mat4 modelView; uniform mat4 projection; -varying mediump vec3 v_color_index; +varying vec3 v_color_index; void main(void) { diff --git a/drape/shaders/path_font_vertex_shader.vsh b/drape/shaders/path_font_vertex_shader.vsh index 9fbfb7802d..9fdfda5781 100755 --- a/drape/shaders/path_font_vertex_shader.vsh +++ b/drape/shaders/path_font_vertex_shader.vsh @@ -1,19 +1,27 @@ +#ifdef GL_FRAGMENT_PRECISION_HIGH + #define MAXPREC highp +#else + #define MAXPREC mediump +#endif + +precision MAXPREC float; + attribute vec2 a_position; attribute vec4 a_texcoord; attribute vec4 a_color; attribute float a_index; -uniform highp mat4 modelView; -uniform highp mat4 projection; +uniform mat4 modelView; +uniform mat4 projection; varying vec3 v_texcoord; -varying lowp vec4 v_colors; -varying mediump float v_index; +varying vec4 v_colors; +varying float v_index; void main() { gl_Position = vec4(a_position, a_texcoord.w, 1) * modelView * projection; - + v_texcoord = a_texcoord.xyz; v_colors = a_color; v_index = a_index; diff --git a/drape/shaders/simple_vertex_shader.vsh b/drape/shaders/simple_vertex_shader.vsh index e9fa036e28..6a93085bdf 100644 --- a/drape/shaders/simple_vertex_shader.vsh +++ b/drape/shaders/simple_vertex_shader.vsh @@ -1,10 +1,18 @@ +#ifdef GL_FRAGMENT_PRECISION_HIGH + #define MAXPREC highp +#else + #define MAXPREC mediump +#endif + +precision MAXPREC float; + attribute vec4 a_position; attribute vec3 a_color_index; uniform mat4 modelView; uniform mat4 projection; -varying mediump vec3 v_color_index; +varying vec3 v_color_index; void main(void) { diff --git a/drape/shaders/solid_color_fragment_shader.fsh b/drape/shaders/solid_color_fragment_shader.fsh index 31935ad7ef..7995a6d7de 100644 --- a/drape/shaders/solid_color_fragment_shader.fsh +++ b/drape/shaders/solid_color_fragment_shader.fsh @@ -1,4 +1,12 @@ -varying mediump vec3 v_color_index; +#ifdef GL_FRAGMENT_PRECISION_HIGH + #define MAXPREC highp +#else + #define MAXPREC mediump +#endif + +precision MAXPREC float; + +varying vec3 v_color_index; ~getTexel~ diff --git a/drape/shaders/texturing_fragment_shader.fsh b/drape/shaders/texturing_fragment_shader.fsh index 3a62a3d95a..279e5cf599 100644 --- a/drape/shaders/texturing_fragment_shader.fsh +++ b/drape/shaders/texturing_fragment_shader.fsh @@ -1,5 +1,13 @@ -varying lowp vec2 v_texCoords; -varying lowp float v_textureIndex; +#ifdef GL_FRAGMENT_PRECISION_HIGH + #define MAXPREC highp +#else + #define MAXPREC mediump +#endif + +precision MAXPREC float; + +varying vec2 v_texCoords; +varying float v_textureIndex; ~getTexel~ diff --git a/drape/shaders/texturing_vertex_shader.vsh b/drape/shaders/texturing_vertex_shader.vsh index 45ac865d60..97fc691f19 100644 --- a/drape/shaders/texturing_vertex_shader.vsh +++ b/drape/shaders/texturing_vertex_shader.vsh @@ -1,12 +1,20 @@ -attribute lowp vec4 a_position; -attribute lowp vec2 a_normal; -attribute lowp vec3 a_texCoords; +#ifdef GL_FRAGMENT_PRECISION_HIGH + #define MAXPREC highp +#else + #define MAXPREC mediump +#endif -uniform highp mat4 modelView; -uniform highp mat4 projection; +precision MAXPREC float; -varying lowp vec2 v_texCoords; -varying lowp float v_textureIndex; +attribute vec4 a_position; +attribute vec2 a_normal; +attribute vec3 a_texCoords; + +uniform mat4 modelView; +uniform mat4 projection; + +varying vec2 v_texCoords; +varying float v_textureIndex; void main(void) { |