Backport GL-JS fix 'Hide glyphs behind the camera'(https://github.com/mapbox/mapbox-gl-js/pull/9229)
189 lines
5.4 KiB
C++
189 lines
5.4 KiB
C++
// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.
|
|
// clang-format off
|
|
#include <mbgl/programs/symbol_icon_program.hpp>
|
|
#include <mbgl/programs/gl/preludes.hpp>
|
|
#include <mbgl/programs/gl/shader_source.hpp>
|
|
#include <mbgl/gl/program.hpp>
|
|
|
|
namespace mbgl {
|
|
namespace programs {
|
|
namespace gl {
|
|
|
|
template <typename>
|
|
struct ShaderSource;
|
|
|
|
template <>
|
|
struct ShaderSource<SymbolIconProgram> {
|
|
static constexpr const char* name = "symbol_icon";
|
|
static constexpr const uint8_t hash[8] = {0x17, 0x8a, 0xb9, 0xa4, 0x9d, 0xd2, 0xe1, 0x90};
|
|
static constexpr const auto vertexOffset = 50247;
|
|
static constexpr const auto fragmentOffset = 53077;
|
|
};
|
|
|
|
constexpr const char* ShaderSource<SymbolIconProgram>::name;
|
|
constexpr const uint8_t ShaderSource<SymbolIconProgram>::hash[8];
|
|
|
|
} // namespace gl
|
|
} // namespace programs
|
|
|
|
namespace gfx {
|
|
|
|
template <>
|
|
std::unique_ptr<gfx::Program<SymbolIconProgram>>
|
|
Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
|
|
return std::make_unique<gl::Program<SymbolIconProgram>>(programParameters);
|
|
}
|
|
|
|
} // namespace gfx
|
|
} // namespace mbgl
|
|
|
|
// Uncompressed source of symbol_icon.vertex.glsl:
|
|
/*
|
|
const float PI = 3.141592653589793;
|
|
|
|
attribute vec4 a_pos_offset;
|
|
attribute vec4 a_data;
|
|
attribute vec4 a_pixeloffset;
|
|
attribute vec3 a_projected_pos;
|
|
attribute float a_fade_opacity;
|
|
|
|
uniform bool u_is_size_zoom_constant;
|
|
uniform bool u_is_size_feature_constant;
|
|
uniform highp float u_size_t; // used to interpolate between zoom stops when size is a composite function
|
|
uniform highp float u_size; // used when size is both zoom and feature constant
|
|
uniform highp float u_camera_to_center_distance;
|
|
uniform highp float u_pitch;
|
|
uniform bool u_rotate_symbol;
|
|
uniform highp float u_aspect_ratio;
|
|
uniform float u_fade_change;
|
|
|
|
uniform mat4 u_matrix;
|
|
uniform mat4 u_label_plane_matrix;
|
|
uniform mat4 u_coord_matrix;
|
|
|
|
uniform bool u_is_text;
|
|
uniform bool u_pitch_with_map;
|
|
|
|
uniform vec2 u_texsize;
|
|
|
|
varying vec2 v_tex;
|
|
varying float v_fade_opacity;
|
|
|
|
|
|
#ifndef HAS_UNIFORM_u_opacity
|
|
uniform lowp float u_opacity_t;
|
|
attribute lowp vec2 a_opacity;
|
|
varying lowp float opacity;
|
|
#else
|
|
uniform lowp float u_opacity;
|
|
#endif
|
|
|
|
|
|
void main() {
|
|
|
|
#ifndef HAS_UNIFORM_u_opacity
|
|
opacity = unpack_mix_vec2(a_opacity, u_opacity_t);
|
|
#else
|
|
lowp float opacity = u_opacity;
|
|
#endif
|
|
|
|
|
|
vec2 a_pos = a_pos_offset.xy;
|
|
vec2 a_offset = a_pos_offset.zw;
|
|
|
|
vec2 a_tex = a_data.xy;
|
|
vec2 a_size = a_data.zw;
|
|
|
|
float a_size_min = floor(a_size[0] * 0.5);
|
|
vec2 a_pxoffset = a_pixeloffset.xy;
|
|
vec2 a_minFontScale = a_pixeloffset.zw / 256.0;
|
|
|
|
highp float segment_angle = -a_projected_pos[2];
|
|
float size;
|
|
|
|
if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {
|
|
size = mix(a_size_min, a_size[1], u_size_t) / 128.0;
|
|
} else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {
|
|
size = a_size_min / 128.0;
|
|
} else {
|
|
size = u_size;
|
|
}
|
|
|
|
vec4 projectedPoint = u_matrix * vec4(a_pos, 0, 1);
|
|
highp float camera_to_anchor_distance = projectedPoint.w;
|
|
// See comments in symbol_sdf.vertex
|
|
highp float distance_ratio = u_pitch_with_map ?
|
|
camera_to_anchor_distance / u_camera_to_center_distance :
|
|
u_camera_to_center_distance / camera_to_anchor_distance;
|
|
highp float perspective_ratio = clamp(
|
|
0.5 + 0.5 * distance_ratio,
|
|
0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles
|
|
4.0);
|
|
|
|
size *= perspective_ratio;
|
|
|
|
float fontScale = u_is_text ? size / 24.0 : size;
|
|
|
|
highp float symbol_rotation = 0.0;
|
|
if (u_rotate_symbol) {
|
|
// See comments in symbol_sdf.vertex
|
|
vec4 offsetProjectedPoint = u_matrix * vec4(a_pos + vec2(1, 0), 0, 1);
|
|
|
|
vec2 a = projectedPoint.xy / projectedPoint.w;
|
|
vec2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
|
|
|
|
symbol_rotation = atan((b.y - a.y) / u_aspect_ratio, b.x - a.x);
|
|
}
|
|
|
|
highp float angle_sin = sin(segment_angle + symbol_rotation);
|
|
highp float angle_cos = cos(segment_angle + symbol_rotation);
|
|
mat2 rotation_matrix = mat2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos);
|
|
|
|
vec4 projected_pos = u_label_plane_matrix * vec4(a_projected_pos.xy, 0.0, 1.0);
|
|
gl_Position = u_coord_matrix * vec4(projected_pos.xy / projected_pos.w + rotation_matrix * (a_offset / 32.0 * max(a_minFontScale, fontScale) + a_pxoffset / 16.0), 0.0, 1.0);
|
|
|
|
// Symbols might end up being behind the camera. Modify z-value to be out of visible bounds
|
|
// if this is the case, otherwise ignore depth. -1.1 is safely out of the visible depth range [-1, 1]
|
|
gl_Position.z = mix(-1.1 * gl_Position.w, gl_Position.z, float(projected_pos.w > 0.0));
|
|
|
|
v_tex = a_tex / u_texsize;
|
|
vec2 fade_opacity = unpack_opacity(a_fade_opacity);
|
|
float fade_change = fade_opacity[1] > 0.5 ? u_fade_change : -u_fade_change;
|
|
v_fade_opacity = max(0.0, min(1.0, fade_opacity[0] + fade_change));
|
|
}
|
|
|
|
*/
|
|
|
|
// Uncompressed source of symbol_icon.fragment.glsl:
|
|
/*
|
|
uniform sampler2D u_texture;
|
|
|
|
varying vec2 v_tex;
|
|
varying float v_fade_opacity;
|
|
|
|
|
|
#ifndef HAS_UNIFORM_u_opacity
|
|
varying lowp float opacity;
|
|
#else
|
|
uniform lowp float u_opacity;
|
|
#endif
|
|
|
|
|
|
void main() {
|
|
|
|
#ifdef HAS_UNIFORM_u_opacity
|
|
lowp float opacity = u_opacity;
|
|
#endif
|
|
|
|
|
|
lowp float alpha = opacity * v_fade_opacity;
|
|
gl_FragColor = texture2D(u_texture, v_tex) * alpha;
|
|
|
|
#ifdef OVERDRAW_INSPECTOR
|
|
gl_FragColor = vec4(1.0);
|
|
#endif
|
|
}
|
|
|
|
*/
|
|
// clang-format on
|