Skip to content

Commit

Permalink
Make debug collision boxes take account of text-pitch-scale
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLoer committed Apr 25, 2017
1 parent 0df789c commit 76e9b50
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/render/draw_collision_debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ function drawCollisionDebug(painter, sourceCache, layer, coords) {
gl.uniform1f(program.u_zoom, painter.transform.zoom * 10);
gl.uniform1f(program.u_maxzoom, (tile.coord.z + 1) * 10);

gl.uniform1f(program.u_collision_y_stretch, tile.collisionTile.yStretch);
gl.uniform1f(program.u_pitch, painter.transform.pitch / 360 * 2 * Math.PI);
gl.uniform1f(program.u_camera_to_center_distance, painter.transform.cameraToCenterDistance);
// TODO: Hook up to `text-pitch-scale` and `icon-pitch-scale` properties
gl.uniform1f(program.u_pitch_scale, 0.0);

for (const segment of buffers.segments) {
segment.vaos[layer.id].bind(gl, program, buffers.layoutVertexBuffer, buffers.elementBuffer, null, segment.vertexOffset);
gl.drawElements(gl.LINES, segment.primitiveLength * 2, gl.UNSIGNED_SHORT, segment.primitiveOffset * 2 * 2);
Expand Down
3 changes: 2 additions & 1 deletion src/shaders/collision_box.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ uniform float u_maxzoom;

varying float v_max_zoom;
varying float v_placement_zoom;
varying float v_perspective_zoom_adjust;

void main() {

Expand All @@ -21,9 +22,9 @@ void main() {
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0) * alpha;
}

if (v_placement_zoom >= u_maxzoom) {
// Blue = this collision box will not be placed at tile zoom + 1
// e.g. The only way to show this is overzooming
if (v_placement_zoom >= u_maxzoom + v_perspective_zoom_adjust) {
gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0) * alpha;
}
}
20 changes: 17 additions & 3 deletions src/shaders/collision_box.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,27 @@ attribute vec2 a_data;

uniform mat4 u_matrix;
uniform float u_scale;
uniform float u_pitch;
uniform float u_collision_y_stretch;
uniform float u_pitch_scale;
uniform float u_camera_to_center_distance;

varying float v_max_zoom;
varying float v_placement_zoom;
varying float v_perspective_zoom_adjust;

void main() {
gl_Position = u_matrix * vec4(a_pos + a_extrude / u_scale, 0.0, 1.0);
vec4 projectedPoint = u_matrix * vec4(a_pos, 0, 1);
highp float camera_to_anchor_distance = projectedPoint.w;
highp float perspective_ratio = 1.0 + (1.0 - u_pitch_scale)*((camera_to_anchor_distance / u_camera_to_center_distance) - 1.0);;

v_max_zoom = a_data.x;
v_placement_zoom = a_data.y;
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);

gl_Position = u_matrix * vec4(a_pos + a_extrude * perspective_ratio * collision_adjustment / u_scale, 0.0, 1.0);

v_perspective_zoom_adjust = log2(perspective_ratio * collision_adjustment)*10.0;

v_max_zoom = a_data.x + v_perspective_zoom_adjust;
v_placement_zoom = a_data.y + v_perspective_zoom_adjust;
}

0 comments on commit 76e9b50

Please sign in to comment.