Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Bart Louwers <bart@emeel.net>
117 lines
4.0 KiB
GLSL
117 lines
4.0 KiB
GLSL
layout (location = 0) in vec2 a_pos;
|
|
layout (location = 1) in vec2 a_decimals_ed;
|
|
layout (location = 2) in vec2 a_normal2d;
|
|
|
|
out vec2 v_pos_a;
|
|
out vec2 v_pos_b;
|
|
out vec4 v_lighting;
|
|
|
|
layout (std140) uniform GlobalPaintParamsUBO {
|
|
highp vec2 u_pattern_atlas_texsize;
|
|
highp vec2 u_units_to_pixels;
|
|
highp vec2 u_world_size;
|
|
highp float u_camera_to_center_distance;
|
|
highp float u_symbol_fade_change;
|
|
highp float u_aspect_ratio;
|
|
highp float u_pixel_ratio;
|
|
highp float u_map_zoom;
|
|
lowp float global_pad1;
|
|
};
|
|
|
|
layout (std140) uniform FillExtrusionDrawableUBO {
|
|
highp mat4 u_matrix;
|
|
highp vec2 u_pixel_coord_upper;
|
|
highp vec2 u_pixel_coord_lower;
|
|
highp float u_height_factor;
|
|
highp float u_tile_ratio;
|
|
// Interpolations
|
|
highp float u_base_t;
|
|
highp float u_height_t;
|
|
highp float u_color_t;
|
|
highp float u_pattern_from_t;
|
|
highp float u_pattern_to_t;
|
|
lowp float drawable_pad1;
|
|
};
|
|
|
|
layout (std140) uniform FillExtrusionTilePropsUBO {
|
|
highp vec4 u_pattern_from;
|
|
highp vec4 u_pattern_to;
|
|
highp vec2 u_texsize;
|
|
lowp float tileprops_pad1;
|
|
lowp float tileprops_pad2;
|
|
};
|
|
|
|
layout (std140) uniform FillExtrusionPropsUBO {
|
|
highp vec4 u_color;
|
|
highp vec3 u_lightcolor;
|
|
lowp float props_pad1;
|
|
highp vec3 u_lightpos;
|
|
highp float u_base;
|
|
highp float u_height;
|
|
highp float u_lightintensity;
|
|
highp float u_vertical_gradient;
|
|
highp float u_opacity;
|
|
highp float u_fade;
|
|
highp float u_from_scale;
|
|
highp float u_to_scale;
|
|
lowp float props_pad2;
|
|
};
|
|
|
|
#pragma mapbox: define lowp float base
|
|
#pragma mapbox: define lowp float height
|
|
#pragma mapbox: define mediump vec4 pattern_from
|
|
#pragma mapbox: define mediump vec4 pattern_to
|
|
|
|
void main() {
|
|
#pragma mapbox: initialize lowp float base
|
|
#pragma mapbox: initialize lowp float height
|
|
#pragma mapbox: initialize mediump vec4 pattern_from
|
|
#pragma mapbox: initialize mediump vec4 pattern_to
|
|
|
|
vec2 pattern_tl_a = pattern_from.xy;
|
|
vec2 pattern_br_a = pattern_from.zw;
|
|
vec2 pattern_tl_b = pattern_to.xy;
|
|
vec2 pattern_br_b = pattern_to.zw;
|
|
|
|
float pixelRatio = u_pixel_ratio;
|
|
float tileRatio = u_tile_ratio;
|
|
float fromScale = u_from_scale;
|
|
float toScale = u_to_scale;
|
|
|
|
vec3 normal = vec3(a_normal2d / 16384.0, a_normal2d.x == 0.0 && a_normal2d.y == 0.0 ? 1.0 : 0.0);
|
|
float edgedistance = a_decimals_ed.y;
|
|
|
|
vec2 display_size_a = vec2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio);
|
|
vec2 display_size_b = vec2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio);
|
|
|
|
base = max(0.0, base);
|
|
height = max(0.0, height);
|
|
|
|
float t = mod(a_decimals_ed.x, 2.0);
|
|
float z = t > 0.0 ? height : base;
|
|
vec2 decimals = unpack_float(floor(a_decimals_ed.x / 2.0)) / 128.0;
|
|
|
|
gl_Position = u_matrix * vec4(a_pos + decimals, z, 1);
|
|
|
|
// extrusion top or side
|
|
vec2 pos = normal.z == 1.0 ? a_pos : vec2(edgedistance, z * u_height_factor);
|
|
|
|
v_pos_a = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, fromScale * display_size_a, tileRatio, pos);
|
|
v_pos_b = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, toScale * display_size_b, tileRatio, pos);
|
|
|
|
v_lighting = vec4(0.0, 0.0, 0.0, 1.0);
|
|
float directional = clamp(dot(normal, u_lightpos), 0.0, 1.0);
|
|
directional = mix((1.0 - u_lightintensity), max((0.5 + u_lightintensity), 1.0), directional);
|
|
|
|
if (normal.z == 0.0) {
|
|
// This avoids another branching statement, but multiplies by a constant of 0.84 if no vertical gradient,
|
|
// and otherwise calculates the gradient based on base + height
|
|
float fMin = mix(0.7, 0.98, 1.0 - u_lightintensity);
|
|
float factor = clamp((t + base) * pow(height / 150.0, 0.5), fMin, 1.0);
|
|
directional *= (1.0 - u_vertical_gradient) + (u_vertical_gradient * factor);
|
|
}
|
|
|
|
v_lighting.rgb += clamp(directional * u_lightcolor, mix(vec3(0.0), vec3(0.3), 1.0 - u_lightcolor), vec3(1.0));
|
|
v_lighting *= u_opacity;
|
|
}
|