diff options
Diffstat (limited to 'src/mbgl/shaders/fill_extrusion_pattern.cpp')
-rw-r--r-- | src/mbgl/shaders/fill_extrusion_pattern.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/mbgl/shaders/fill_extrusion_pattern.cpp b/src/mbgl/shaders/fill_extrusion_pattern.cpp index 2681973af6..466d0e04fe 100644 --- a/src/mbgl/shaders/fill_extrusion_pattern.cpp +++ b/src/mbgl/shaders/fill_extrusion_pattern.cpp @@ -22,8 +22,7 @@ uniform lowp vec3 u_lightpos; uniform lowp float u_lightintensity; attribute vec2 a_pos; -attribute vec3 a_normal; -attribute float a_edgedistance; +attribute vec4 a_normal_ed; varying vec2 v_pos_a; varying vec2 v_pos_b; @@ -39,6 +38,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,40 +47,46 @@ 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 + + vec3 normal = a_normal_ed.xyz; + float edgedistance = a_normal_ed.w; + base = max(0.0, base); height = max(0.0, height); - float t = mod(a_normal.x, 2.0); + float t = mod(normal.x, 2.0); float z = t > 0.0 ? height : base; gl_Position = u_matrix * vec4(a_pos, z, 1); - vec2 pos = a_normal.x == 1.0 && a_normal.y == 0.0 && a_normal.z == 16384.0 + vec2 pos = normal.x == 1.0 && normal.y == 0.0 && normal.z == 16384.0 ? a_pos // extrusion top - : vec2(a_edgedistance, z * u_height_factor); // extrusion side + : vec2(edgedistance, z * u_height_factor); // extrusion side 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, pos); v_pos_b = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, u_scale_b * u_pattern_size_b, u_tile_units_to_pixels, pos); v_lighting = vec4(0.0, 0.0, 0.0, 1.0); - float directional = clamp(dot(a_normal / 16383.0, u_lightpos), 0.0, 1.0); + float directional = clamp(dot(normal / 16383.0, u_lightpos), 0.0, 1.0); directional = mix((1.0 - u_lightintensity), max((0.5 + u_lightintensity), 1.0), directional); - if (a_normal.y != 0.0) { + if (normal.y != 0.0) { directional *= clamp((t + base) * pow(height / 150.0, 0.5), mix(0.7, 0.98, 1.0 - u_lightintensity), 1.0); } @@ -109,22 +115,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); |