diff options
author | Ansis Brammanis <brammanis@gmail.com> | 2017-06-14 12:23:00 -0400 |
---|---|---|
committer | Ansis Brammanis <brammanis@gmail.com> | 2017-06-15 15:24:50 -0400 |
commit | 4f3fe87df660ac5e0177eac28630906e3762e2c4 (patch) | |
tree | b20af6b68e38fc4e4ae4294b1fab71fc04f0d3e5 | |
parent | 56f5bbafa5adaeab53cde3246b94bf1a45894554 (diff) | |
download | qtlocation-mapboxgl-4f3fe87df660ac5e0177eac28630906e3762e2c4.tar.gz |
fix shader generation script and regenerate shaders
-rwxr-xr-x | scripts/generate-shaders.js | 4 | ||||
-rw-r--r-- | src/mbgl/shaders/circle.cpp | 54 | ||||
-rw-r--r-- | src/mbgl/shaders/collision_box.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/shaders/fill.cpp | 12 | ||||
-rw-r--r-- | src/mbgl/shaders/fill_extrusion.cpp | 16 | ||||
-rw-r--r-- | src/mbgl/shaders/fill_extrusion_pattern.cpp | 12 | ||||
-rw-r--r-- | src/mbgl/shaders/fill_outline.cpp | 12 | ||||
-rw-r--r-- | src/mbgl/shaders/fill_outline_pattern.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/shaders/fill_pattern.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/shaders/line.cpp | 20 | ||||
-rw-r--r-- | src/mbgl/shaders/line_pattern.cpp | 16 | ||||
-rw-r--r-- | src/mbgl/shaders/line_sdf.cpp | 20 | ||||
-rw-r--r-- | src/mbgl/shaders/symbol_icon.cpp | 10 | ||||
-rw-r--r-- | src/mbgl/shaders/symbol_sdf.cpp | 12 |
14 files changed, 161 insertions, 45 deletions
diff --git a/scripts/generate-shaders.js b/scripts/generate-shaders.js index 159817f62f..3507774fd8 100755 --- a/scripts/generate-shaders.js +++ b/scripts/generate-shaders.js @@ -86,7 +86,7 @@ uniform ${precision} ${type} u_${name}; const a_type = type === "float" ? "vec2" : "vec4"; if (fragmentPragmas.has(name)) { return operation === "define" ? ` -#ifdef HAS_UNIFORM_u_${name} +#ifndef HAS_UNIFORM_u_${name} uniform lowp float a_${name}_t; attribute ${precision} ${a_type} a_${name}; varying ${precision} ${type} ${name}; @@ -102,7 +102,7 @@ uniform ${precision} ${type} u_${name}; `; } else { return operation === "define" ? ` -#ifdef HAS_UNIFORM_u_${name} +#ifndef HAS_UNIFORM_u_${name} uniform lowp float a_${name}_t; attribute ${precision} ${a_type} a_${name}; #else diff --git a/src/mbgl/shaders/circle.cpp b/src/mbgl/shaders/circle.cpp index 2e0c76122c..8f61ce9dfd 100644 --- a/src/mbgl/shaders/circle.cpp +++ b/src/mbgl/shaders/circle.cpp @@ -22,6 +22,7 @@ varying highp vec4 color; uniform highp vec4 u_color; #endif + #ifndef HAS_UNIFORM_u_radius uniform lowp float a_radius_t; attribute mediump vec2 a_radius; @@ -30,6 +31,7 @@ varying mediump float radius; uniform mediump float u_radius; #endif + #ifndef HAS_UNIFORM_u_blur uniform lowp float a_blur_t; attribute lowp vec2 a_blur; @@ -38,6 +40,7 @@ varying lowp float blur; uniform lowp float u_blur; #endif + #ifndef HAS_UNIFORM_u_opacity uniform lowp float a_opacity_t; attribute lowp vec2 a_opacity; @@ -46,6 +49,7 @@ varying lowp float opacity; uniform lowp float u_opacity; #endif + #ifndef HAS_UNIFORM_u_stroke_color uniform lowp float a_stroke_color_t; attribute highp vec4 a_stroke_color; @@ -54,6 +58,7 @@ varying highp vec4 stroke_color; uniform highp vec4 u_stroke_color; #endif + #ifndef HAS_UNIFORM_u_stroke_width uniform lowp float a_stroke_width_t; attribute mediump vec2 a_stroke_width; @@ -62,6 +67,7 @@ varying mediump float stroke_width; uniform mediump float u_stroke_width; #endif + #ifndef HAS_UNIFORM_u_stroke_opacity uniform lowp float a_stroke_opacity_t; attribute lowp vec2 a_stroke_opacity; @@ -70,71 +76,79 @@ varying lowp float stroke_opacity; uniform lowp float u_stroke_opacity; #endif -varying vec3 v_data; -void main(void) { +varying vec2 v_extrude; +varying lowp float v_antialiasblur; +void main(void) { + #ifndef HAS_UNIFORM_u_color color = unpack_mix_vec4(a_color, a_color_t); #else highp vec4 color = u_color; #endif + #ifndef HAS_UNIFORM_u_radius radius = unpack_mix_vec2(a_radius, a_radius_t); #else mediump float radius = u_radius; #endif + #ifndef HAS_UNIFORM_u_blur blur = unpack_mix_vec2(a_blur, a_blur_t); #else lowp float blur = u_blur; #endif + #ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, a_opacity_t); #else lowp float opacity = u_opacity; #endif + #ifndef HAS_UNIFORM_u_stroke_color stroke_color = unpack_mix_vec4(a_stroke_color, a_stroke_color_t); #else highp vec4 stroke_color = u_stroke_color; #endif + #ifndef HAS_UNIFORM_u_stroke_width stroke_width = unpack_mix_vec2(a_stroke_width, a_stroke_width_t); #else mediump float stroke_width = u_stroke_width; #endif + #ifndef HAS_UNIFORM_u_stroke_opacity stroke_opacity = unpack_mix_vec2(a_stroke_opacity, a_stroke_opacity_t); #else lowp float stroke_opacity = u_stroke_opacity; #endif + // unencode the extrusion vector that we snuck into the a_pos vector - vec2 extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0); + v_extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0); + vec2 extrude = v_extrude * (radius + stroke_width) * u_extrude_scale; // multiply a_pos by 0.5, since we had it * 2 in order to sneak // in extrusion data gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0, 1); if (u_scale_with_map) { - gl_Position.xy += extrude * (radius + stroke_width) * u_extrude_scale; + gl_Position.xy += extrude; } else { - gl_Position.xy += extrude * (radius + stroke_width) * u_extrude_scale * gl_Position.w; + gl_Position.xy += extrude * gl_Position.w; } // This is a minimum blur distance that serves as a faux-antialiasing for // the circle. since blur is a ratio of the circle's size and the intent is // to keep the blur at roughly 1px, the two are inversely related. - lowp float antialiasblur = 1.0 / DEVICE_PIXEL_RATIO / (radius + stroke_width); - - v_data = vec3(extrude.x, extrude.y, antialiasblur); + v_antialiasblur = 1.0 / DEVICE_PIXEL_RATIO / (radius + stroke_width); } )MBGL_SHADER"; @@ -146,79 +160,91 @@ varying highp vec4 color; uniform highp vec4 u_color; #endif + #ifndef HAS_UNIFORM_u_radius varying mediump float radius; #else uniform mediump float u_radius; #endif + #ifndef HAS_UNIFORM_u_blur varying lowp float blur; #else uniform lowp float u_blur; #endif + #ifndef HAS_UNIFORM_u_opacity varying lowp float opacity; #else uniform lowp float u_opacity; #endif + #ifndef HAS_UNIFORM_u_stroke_color varying highp vec4 stroke_color; #else uniform highp vec4 u_stroke_color; #endif + #ifndef HAS_UNIFORM_u_stroke_width varying mediump float stroke_width; #else uniform mediump float u_stroke_width; #endif + #ifndef HAS_UNIFORM_u_stroke_opacity varying lowp float stroke_opacity; #else uniform lowp float u_stroke_opacity; #endif -varying vec3 v_data; -void main() { +varying vec2 v_extrude; +varying lowp float v_antialiasblur; +void main() { + #ifdef HAS_UNIFORM_u_color highp vec4 color = u_color; #endif + #ifdef HAS_UNIFORM_u_radius mediump float radius = u_radius; #endif + #ifdef HAS_UNIFORM_u_blur lowp float blur = u_blur; #endif + #ifdef HAS_UNIFORM_u_opacity lowp float opacity = u_opacity; #endif + #ifdef HAS_UNIFORM_u_stroke_color highp vec4 stroke_color = u_stroke_color; #endif + #ifdef HAS_UNIFORM_u_stroke_width mediump float stroke_width = u_stroke_width; #endif + #ifdef HAS_UNIFORM_u_stroke_opacity lowp float stroke_opacity = u_stroke_opacity; #endif - vec2 extrude = v_data.xy; - float extrude_length = length(extrude); - lowp float antialiasblur = v_data.z; - float antialiased_blur = -max(blur, antialiasblur); + float extrude_length = length(v_extrude); + float antialiased_blur = -max(blur, v_antialiasblur); float opacity_t = smoothstep(0.0, antialiased_blur, extrude_length - 1.0); diff --git a/src/mbgl/shaders/collision_box.cpp b/src/mbgl/shaders/collision_box.cpp index 05f306ef65..07fa94e338 100644 --- a/src/mbgl/shaders/collision_box.cpp +++ b/src/mbgl/shaders/collision_box.cpp @@ -36,7 +36,7 @@ void main() { v_max_zoom = a_data.x; v_placement_zoom = a_data.y; - v_perspective_zoom_adjust = log2(collision_perspective_ratio * collision_adjustment) * 10.0; + v_perspective_zoom_adjust = floor(log2(collision_perspective_ratio * collision_adjustment) * 10.0); v_fade_tex = vec2((v_placement_zoom + v_perspective_zoom_adjust) / 255.0, 0.0); } diff --git a/src/mbgl/shaders/fill.cpp b/src/mbgl/shaders/fill.cpp index 8f5f304014..3ba00836a2 100644 --- a/src/mbgl/shaders/fill.cpp +++ b/src/mbgl/shaders/fill.cpp @@ -20,6 +20,7 @@ varying highp vec4 color; uniform highp vec4 u_color; #endif + #ifndef HAS_UNIFORM_u_opacity uniform lowp float a_opacity_t; attribute lowp vec2 a_opacity; @@ -28,20 +29,23 @@ varying lowp float opacity; uniform lowp float u_opacity; #endif -void main() { +void main() { + #ifndef HAS_UNIFORM_u_color color = unpack_mix_vec4(a_color, a_color_t); #else highp vec4 color = u_color; #endif + #ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, a_opacity_t); #else lowp float opacity = u_opacity; #endif + gl_Position = u_matrix * vec4(a_pos, 0, 1); } @@ -54,22 +58,26 @@ varying highp vec4 color; uniform highp vec4 u_color; #endif + #ifndef HAS_UNIFORM_u_opacity varying lowp float opacity; #else uniform lowp float u_opacity; #endif -void main() { +void main() { + #ifdef HAS_UNIFORM_u_color highp vec4 color = u_color; #endif + #ifdef HAS_UNIFORM_u_opacity lowp float opacity = u_opacity; #endif + gl_FragColor = color * opacity; #ifdef OVERDRAW_INSPECTOR diff --git a/src/mbgl/shaders/fill_extrusion.cpp b/src/mbgl/shaders/fill_extrusion.cpp index ad14e4f32e..817f73391c 100644 --- a/src/mbgl/shaders/fill_extrusion.cpp +++ b/src/mbgl/shaders/fill_extrusion.cpp @@ -27,6 +27,7 @@ varying lowp float base; uniform lowp float u_base; #endif + #ifndef HAS_UNIFORM_u_height uniform lowp float a_height_t; attribute lowp vec2 a_height; @@ -36,6 +37,7 @@ uniform lowp float u_height; #endif + #ifndef HAS_UNIFORM_u_color uniform lowp float a_color_t; attribute highp vec4 a_color; @@ -44,26 +46,30 @@ varying highp vec4 color; uniform highp vec4 u_color; #endif -void main() { +void main() { + #ifndef HAS_UNIFORM_u_base base = unpack_mix_vec2(a_base, a_base_t); #else lowp float base = u_base; #endif + #ifndef HAS_UNIFORM_u_height height = unpack_mix_vec2(a_height, a_height_t); #else lowp float height = u_height; #endif + #ifndef HAS_UNIFORM_u_color color = unpack_mix_vec4(a_color, a_color_t); #else highp vec4 color = u_color; #endif + base = max(0.0, base); height = max(0.0, height); @@ -113,32 +119,38 @@ varying lowp float base; uniform lowp float u_base; #endif + #ifndef HAS_UNIFORM_u_height varying lowp float height; #else uniform lowp float u_height; #endif + #ifndef HAS_UNIFORM_u_color varying highp vec4 color; #else uniform highp vec4 u_color; #endif -void main() { +void main() { + #ifdef HAS_UNIFORM_u_base lowp float base = u_base; #endif + #ifdef HAS_UNIFORM_u_height lowp float height = u_height; #endif + #ifdef HAS_UNIFORM_u_color highp vec4 color = u_color; #endif + gl_FragColor = v_color; #ifdef OVERDRAW_INSPECTOR diff --git a/src/mbgl/shaders/fill_extrusion_pattern.cpp b/src/mbgl/shaders/fill_extrusion_pattern.cpp index 2681973af6..d3e5eef1bf 100644 --- a/src/mbgl/shaders/fill_extrusion_pattern.cpp +++ b/src/mbgl/shaders/fill_extrusion_pattern.cpp @@ -39,6 +39,7 @@ varying lowp float base; uniform lowp float u_base; #endif + #ifndef HAS_UNIFORM_u_height uniform lowp float a_height_t; attribute lowp vec2 a_height; @@ -47,20 +48,23 @@ varying lowp float height; uniform lowp float u_height; #endif -void main() { +void main() { + #ifndef HAS_UNIFORM_u_base base = unpack_mix_vec2(a_base, a_base_t); #else lowp float base = u_base; #endif + #ifndef HAS_UNIFORM_u_height height = unpack_mix_vec2(a_height, a_height_t); #else lowp float height = u_height; #endif + base = max(0.0, base); height = max(0.0, height); @@ -109,22 +113,26 @@ varying lowp float base; uniform lowp float u_base; #endif + #ifndef HAS_UNIFORM_u_height varying lowp float height; #else uniform lowp float u_height; #endif -void main() { +void main() { + #ifdef HAS_UNIFORM_u_base lowp float base = u_base; #endif + #ifdef HAS_UNIFORM_u_height lowp float height = u_height; #endif + vec2 imagecoord = mod(v_pos_a, 1.0); vec2 pos = mix(u_pattern_tl_a / u_texsize, u_pattern_br_a / u_texsize, imagecoord); vec4 color1 = texture2D(u_image, pos); diff --git a/src/mbgl/shaders/fill_outline.cpp b/src/mbgl/shaders/fill_outline.cpp index 18a4d8c0a8..9ade598d10 100644 --- a/src/mbgl/shaders/fill_outline.cpp +++ b/src/mbgl/shaders/fill_outline.cpp @@ -23,6 +23,7 @@ varying highp vec4 outline_color; uniform highp vec4 u_outline_color; #endif + #ifndef HAS_UNIFORM_u_opacity uniform lowp float a_opacity_t; attribute lowp vec2 a_opacity; @@ -31,20 +32,23 @@ varying lowp float opacity; uniform lowp float u_opacity; #endif -void main() { +void main() { + #ifndef HAS_UNIFORM_u_outline_color outline_color = unpack_mix_vec4(a_outline_color, a_outline_color_t); #else highp vec4 outline_color = u_outline_color; #endif + #ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, a_opacity_t); #else lowp float opacity = u_opacity; #endif + gl_Position = u_matrix * vec4(a_pos, 0, 1); v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world; } @@ -58,24 +62,28 @@ varying highp vec4 outline_color; uniform highp vec4 u_outline_color; #endif + #ifndef HAS_UNIFORM_u_opacity varying lowp float opacity; #else uniform lowp float u_opacity; #endif + varying vec2 v_pos; void main() { - + #ifdef HAS_UNIFORM_u_outline_color highp vec4 outline_color = u_outline_color; #endif + #ifdef HAS_UNIFORM_u_opacity lowp float opacity = u_opacity; #endif + float dist = length(v_pos - gl_FragCoord.xy); float alpha = 1.0 - smoothstep(0.0, 1.0, dist); gl_FragColor = outline_color * (alpha * opacity); diff --git a/src/mbgl/shaders/fill_outline_pattern.cpp b/src/mbgl/shaders/fill_outline_pattern.cpp index 68e69c2135..11cddb7d07 100644 --- a/src/mbgl/shaders/fill_outline_pattern.cpp +++ b/src/mbgl/shaders/fill_outline_pattern.cpp @@ -32,14 +32,16 @@ varying lowp float opacity; uniform lowp float u_opacity; #endif -void main() { +void main() { + #ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, a_opacity_t); #else lowp float opacity = u_opacity; #endif + gl_Position = u_matrix * vec4(a_pos, 0, 1); v_pos_a = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, u_scale_a * u_pattern_size_a, u_tile_units_to_pixels, a_pos); @@ -70,12 +72,14 @@ varying lowp float opacity; uniform lowp float u_opacity; #endif -void main() { +void main() { + #ifdef HAS_UNIFORM_u_opacity lowp float opacity = u_opacity; #endif + vec2 imagecoord = mod(v_pos_a, 1.0); vec2 pos = mix(u_pattern_tl_a / u_texsize, u_pattern_br_a / u_texsize, imagecoord); vec4 color1 = texture2D(u_image, pos); diff --git a/src/mbgl/shaders/fill_pattern.cpp b/src/mbgl/shaders/fill_pattern.cpp index f6f9e2fbff..a3817c4426 100644 --- a/src/mbgl/shaders/fill_pattern.cpp +++ b/src/mbgl/shaders/fill_pattern.cpp @@ -30,14 +30,16 @@ varying lowp float opacity; uniform lowp float u_opacity; #endif -void main() { +void main() { + #ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, a_opacity_t); #else lowp float opacity = u_opacity; #endif + gl_Position = u_matrix * vec4(a_pos, 0, 1); v_pos_a = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, u_scale_a * u_pattern_size_a, u_tile_units_to_pixels, a_pos); @@ -65,12 +67,14 @@ varying lowp float opacity; uniform lowp float u_opacity; #endif -void main() { +void main() { + #ifdef HAS_UNIFORM_u_opacity lowp float opacity = u_opacity; #endif + vec2 imagecoord = mod(v_pos_a, 1.0); vec2 pos = mix(u_pattern_tl_a / u_texsize, u_pattern_br_a / u_texsize, imagecoord); vec4 color1 = texture2D(u_image, pos); diff --git a/src/mbgl/shaders/line.cpp b/src/mbgl/shaders/line.cpp index dce6046257..588664674b 100644 --- a/src/mbgl/shaders/line.cpp +++ b/src/mbgl/shaders/line.cpp @@ -42,6 +42,7 @@ varying highp vec4 color; uniform highp vec4 u_color; #endif + #ifndef HAS_UNIFORM_u_blur uniform lowp float a_blur_t; attribute lowp vec2 a_blur; @@ -50,6 +51,7 @@ varying lowp float blur; uniform lowp float u_blur; #endif + #ifndef HAS_UNIFORM_u_opacity uniform lowp float a_opacity_t; attribute lowp vec2 a_opacity; @@ -58,6 +60,7 @@ varying lowp float opacity; uniform lowp float u_opacity; #endif + #ifndef HAS_UNIFORM_u_gapwidth uniform lowp float a_gapwidth_t; attribute mediump vec2 a_gapwidth; @@ -65,6 +68,7 @@ attribute mediump vec2 a_gapwidth; uniform mediump float u_gapwidth; #endif + #ifndef HAS_UNIFORM_u_offset uniform lowp float a_offset_t; attribute lowp vec2 a_offset; @@ -72,38 +76,44 @@ attribute lowp vec2 a_offset; uniform lowp float u_offset; #endif -void main() { +void main() { + #ifndef HAS_UNIFORM_u_color color = unpack_mix_vec4(a_color, a_color_t); #else highp vec4 color = u_color; #endif + #ifndef HAS_UNIFORM_u_blur blur = unpack_mix_vec2(a_blur, a_blur_t); #else lowp float blur = u_blur; #endif + #ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, a_opacity_t); #else lowp float opacity = u_opacity; #endif + #ifndef HAS_UNIFORM_u_gapwidth mediump float gapwidth = unpack_mix_vec2(a_gapwidth, a_gapwidth_t); #else mediump float gapwidth = u_gapwidth; #endif + #ifndef HAS_UNIFORM_u_offset lowp float offset = unpack_mix_vec2(a_offset, a_offset_t); #else lowp float offset = u_offset; #endif + vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; @@ -160,36 +170,42 @@ varying highp vec4 color; uniform highp vec4 u_color; #endif + #ifndef HAS_UNIFORM_u_blur varying lowp float blur; #else uniform lowp float u_blur; #endif + #ifndef HAS_UNIFORM_u_opacity varying lowp float opacity; #else uniform lowp float u_opacity; #endif + varying vec2 v_width2; varying vec2 v_normal; varying float v_gamma_scale; void main() { - + #ifdef HAS_UNIFORM_u_color highp vec4 color = u_color; #endif + #ifdef HAS_UNIFORM_u_blur lowp float blur = u_blur; #endif + #ifdef HAS_UNIFORM_u_opacity lowp float opacity = u_opacity; #endif + // Calculate the distance of the pixel from the line in pixels. float dist = length(v_normal) * v_width2.s; diff --git a/src/mbgl/shaders/line_pattern.cpp b/src/mbgl/shaders/line_pattern.cpp index ded4c76825..8c41321b4f 100644 --- a/src/mbgl/shaders/line_pattern.cpp +++ b/src/mbgl/shaders/line_pattern.cpp @@ -45,6 +45,7 @@ varying lowp float blur; uniform lowp float u_blur; #endif + #ifndef HAS_UNIFORM_u_opacity uniform lowp float a_opacity_t; attribute lowp vec2 a_opacity; @@ -53,6 +54,7 @@ varying lowp float opacity; uniform lowp float u_opacity; #endif + #ifndef HAS_UNIFORM_u_offset uniform lowp float a_offset_t; attribute lowp vec2 a_offset; @@ -60,6 +62,7 @@ attribute lowp vec2 a_offset; uniform lowp float u_offset; #endif + #ifndef HAS_UNIFORM_u_gapwidth uniform lowp float a_gapwidth_t; attribute mediump vec2 a_gapwidth; @@ -67,32 +70,37 @@ attribute mediump vec2 a_gapwidth; uniform mediump float u_gapwidth; #endif -void main() { +void main() { + #ifndef HAS_UNIFORM_u_blur blur = unpack_mix_vec2(a_blur, a_blur_t); #else lowp float blur = u_blur; #endif + #ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, a_opacity_t); #else lowp float opacity = u_opacity; #endif + #ifndef HAS_UNIFORM_u_offset lowp float offset = unpack_mix_vec2(a_offset, a_offset_t); #else lowp float offset = u_offset; #endif + #ifndef HAS_UNIFORM_u_gapwidth mediump float gapwidth = unpack_mix_vec2(a_gapwidth, a_gapwidth_t); #else mediump float gapwidth = u_gapwidth; #endif + vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE; @@ -166,22 +174,26 @@ varying lowp float blur; uniform lowp float u_blur; #endif + #ifndef HAS_UNIFORM_u_opacity varying lowp float opacity; #else uniform lowp float u_opacity; #endif -void main() { +void main() { + #ifdef HAS_UNIFORM_u_blur lowp float blur = u_blur; #endif + #ifdef HAS_UNIFORM_u_opacity lowp float opacity = u_opacity; #endif + // Calculate the distance of the pixel from the line in pixels. float dist = length(v_normal) * v_width2.s; diff --git a/src/mbgl/shaders/line_sdf.cpp b/src/mbgl/shaders/line_sdf.cpp index b37bf688d4..12138fe563 100644 --- a/src/mbgl/shaders/line_sdf.cpp +++ b/src/mbgl/shaders/line_sdf.cpp @@ -50,6 +50,7 @@ varying highp vec4 color; uniform highp vec4 u_color; #endif + #ifndef HAS_UNIFORM_u_blur uniform lowp float a_blur_t; attribute lowp vec2 a_blur; @@ -58,6 +59,7 @@ varying lowp float blur; uniform lowp float u_blur; #endif + #ifndef HAS_UNIFORM_u_opacity uniform lowp float a_opacity_t; attribute lowp vec2 a_opacity; @@ -66,6 +68,7 @@ varying lowp float opacity; uniform lowp float u_opacity; #endif + #ifndef HAS_UNIFORM_u_gapwidth uniform lowp float a_gapwidth_t; attribute mediump vec2 a_gapwidth; @@ -73,6 +76,7 @@ attribute mediump vec2 a_gapwidth; uniform mediump float u_gapwidth; #endif + #ifndef HAS_UNIFORM_u_offset uniform lowp float a_offset_t; attribute lowp vec2 a_offset; @@ -80,38 +84,44 @@ attribute lowp vec2 a_offset; uniform lowp float u_offset; #endif -void main() { +void main() { + #ifndef HAS_UNIFORM_u_color color = unpack_mix_vec4(a_color, a_color_t); #else highp vec4 color = u_color; #endif + #ifndef HAS_UNIFORM_u_blur blur = unpack_mix_vec2(a_blur, a_blur_t); #else lowp float blur = u_blur; #endif + #ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, a_opacity_t); #else lowp float opacity = u_opacity; #endif + #ifndef HAS_UNIFORM_u_gapwidth mediump float gapwidth = unpack_mix_vec2(a_gapwidth, a_gapwidth_t); #else mediump float gapwidth = u_gapwidth; #endif + #ifndef HAS_UNIFORM_u_offset lowp float offset = unpack_mix_vec2(a_offset, a_offset_t); #else lowp float offset = u_offset; #endif + vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE; @@ -182,32 +192,38 @@ varying highp vec4 color; uniform highp vec4 u_color; #endif + #ifndef HAS_UNIFORM_u_blur varying lowp float blur; #else uniform lowp float u_blur; #endif + #ifndef HAS_UNIFORM_u_opacity varying lowp float opacity; #else uniform lowp float u_opacity; #endif -void main() { +void main() { + #ifdef HAS_UNIFORM_u_color highp vec4 color = u_color; #endif + #ifdef HAS_UNIFORM_u_blur lowp float blur = u_blur; #endif + #ifdef HAS_UNIFORM_u_opacity lowp float opacity = u_opacity; #endif + // Calculate the distance of the pixel from the line in pixels. float dist = length(v_normal) * v_width2.s; diff --git a/src/mbgl/shaders/symbol_icon.cpp b/src/mbgl/shaders/symbol_icon.cpp index 8960e02c28..720ba2eeeb 100644 --- a/src/mbgl/shaders/symbol_icon.cpp +++ b/src/mbgl/shaders/symbol_icon.cpp @@ -31,6 +31,7 @@ varying lowp float opacity; uniform lowp float u_opacity; #endif + // matrix is for the vertex position. uniform mat4 u_matrix; @@ -45,13 +46,14 @@ varying vec2 v_tex; varying vec2 v_fade_tex; void main() { - + #ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, a_opacity_t); #else lowp float opacity = u_opacity; #endif + vec2 a_pos = a_pos_offset.xy; vec2 a_offset = a_pos_offset.zw; @@ -110,7 +112,7 @@ void main() { highp float incidence_stretch = camera_to_anchor_distance / (u_camera_to_center_distance * cos(u_pitch)); highp float collision_adjustment = max(1.0, incidence_stretch / u_collision_y_stretch); - highp float perspective_zoom_adjust = log2(perspective_ratio * collision_adjustment) * 10.0; + highp float perspective_zoom_adjust = floor(log2(perspective_ratio * collision_adjustment) * 10.0); v_fade_tex = vec2((a_labelminzoom + perspective_zoom_adjust) / 255.0, 0.0); } @@ -126,15 +128,17 @@ varying lowp float opacity; uniform lowp float u_opacity; #endif + varying vec2 v_tex; varying vec2 v_fade_tex; void main() { - + #ifdef HAS_UNIFORM_u_opacity lowp float opacity = u_opacity; #endif + lowp float alpha = texture2D(u_fadetexture, v_fade_tex).a * opacity; gl_FragColor = texture2D(u_texture, v_tex) * alpha; diff --git a/src/mbgl/shaders/symbol_sdf.cpp b/src/mbgl/shaders/symbol_sdf.cpp index bae01a5b59..29194d9455 100644 --- a/src/mbgl/shaders/symbol_sdf.cpp +++ b/src/mbgl/shaders/symbol_sdf.cpp @@ -9,8 +9,6 @@ const char* symbol_sdf::name = "symbol_sdf"; const char* symbol_sdf::vertexSource = R"MBGL_SHADER( const float PI = 3.141592653589793; -// NOTE: the a_data attribute in this shader is manually bound (see https://github.com/mapbox/mapbox-gl-js/issues/4607). -// If removing or renaming a_data, revisit the manual binding in painter.js accordingly. attribute vec4 a_pos_offset; attribute vec2 a_label_pos; attribute vec4 a_data; @@ -31,7 +29,7 @@ uniform highp float u_size; // used when size is both zoom and feature constant uniform highp float u_layout_size; // used when size is feature constant -#ifdef HAS_UNIFORM_u_fill_color +#ifndef HAS_UNIFORM_u_fill_color uniform lowp float a_fill_color_t; attribute highp vec4 a_fill_color; varying highp vec4 fill_color; @@ -40,7 +38,7 @@ uniform highp vec4 u_fill_color; #endif -#ifdef HAS_UNIFORM_u_halo_color +#ifndef HAS_UNIFORM_u_halo_color uniform lowp float a_halo_color_t; attribute highp vec4 a_halo_color; varying highp vec4 halo_color; @@ -49,7 +47,7 @@ uniform highp vec4 u_halo_color; #endif -#ifdef HAS_UNIFORM_u_opacity +#ifndef HAS_UNIFORM_u_opacity uniform lowp float a_opacity_t; attribute lowp vec2 a_opacity; varying lowp float opacity; @@ -58,7 +56,7 @@ uniform lowp float u_opacity; #endif -#ifdef HAS_UNIFORM_u_halo_width +#ifndef HAS_UNIFORM_u_halo_width uniform lowp float a_halo_width_t; attribute lowp vec2 a_halo_width; varying lowp float halo_width; @@ -67,7 +65,7 @@ uniform lowp float u_halo_width; #endif -#ifdef HAS_UNIFORM_u_halo_blur +#ifndef HAS_UNIFORM_u_halo_blur uniform lowp float a_halo_blur_t; attribute lowp vec2 a_halo_blur; varying lowp float halo_blur; |