Skip to content

Commit

Permalink
Fix rendering of symbols behind the camera
Browse files Browse the repository at this point in the history
  • Loading branch information
mpulkki-mapbox committed Nov 22, 2019
1 parent 1579741 commit 31b6aa4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/shaders/symbol_icon.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ void main() {
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 * fontScale), 0.0, 1.0);
vec4 clip_pos = u_coord_matrix * vec4(projected_pos.xy / projected_pos.w + rotation_matrix * (a_offset / 32.0 * fontScale), 0.0, 1.0);

// Don't render symbols that are behind the camera (-w * 1.01 transforms into a depth value of -1.01 in NDC)
clip_pos.z = mix(-clip_pos.w * 1.01, clip_pos.z, float(projected_pos.w > 0.0));
gl_Position = clip_pos;

v_tex = a_tex / u_texsize;
vec2 fade_opacity = unpack_opacity(a_fade_opacity);
Expand Down
6 changes: 5 additions & 1 deletion src/shaders/symbol_sdf.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ void main() {
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 * fontScale), 0.0, 1.0);
vec4 clip_pos = u_coord_matrix * vec4(projected_pos.xy / projected_pos.w + rotation_matrix * (a_offset / 32.0 * fontScale), 0.0, 1.0);

// Don't render symbols that are behind the camera (-w * 1.01 transforms into a depth value of -1.01 in NDC)
clip_pos.z = mix(-clip_pos.w * 1.01, clip_pos.z, float(projected_pos.w > 0.0));
gl_Position = clip_pos;
float gamma_scale = gl_Position.w;

vec2 tex = a_tex / u_texsize;
Expand Down

0 comments on commit 31b6aa4

Please sign in to comment.