Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set further near plane to fix depth precision for deckgl #8502

Merged
merged 5 commits into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/geo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,18 @@ class Transform {
// Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance`
const farZ = furthestDistance * 1.01;

// The larger the value of nearZ is
// - the more depth precision is available for features (good)
// - clipping starts appearing sooner when the camera is close to 3d features (bad)
//
// Smaller values worked well for mapbox-gl-js but deckgl was encountering precision issues
// when rendering it's layers using custom layers. This value was experimentally chosen and
// seems to solve z-fighting issues in deckgl while not clipping buildings too close to the camera.
const nearZ = this.height / 50;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
On native side, near set to 0.1 * state.getCameraToCenterDistance() evaluates to height / 90.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an existing render test that exercises this with extrusion layers?


// matrix for conversion from location to GL coordinates (-1 .. 1)
let m = new Float64Array(16);
mat4.perspective(m, this._fov, this.width / this.height, 1, farZ);
mat4.perspective(m, this._fov, this.width / this.height, nearZ, farZ);

mat4.scale(m, m, [1, -1, 1]);
mat4.translate(m, m, [0, 0, -this.cameraToCenterDistance]);
Expand Down
12 changes: 12 additions & 0 deletions src/ui/map.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow

import { version } from '../../package.json';
import { extend, bindAll, warnOnce, uniqueId } from '../util/util';
import browser from '../util/browser';
import window from '../util/window';
Expand Down Expand Up @@ -1942,6 +1943,17 @@ class Map extends Camera {
_setCacheLimits(limit: number, checkThreshold: number) {
setCacheLimits(limit, checkThreshold);
}

/**
* The version of Mapbox GL JS in use as specified in package.json, CHANGELOG.md, and the GitHub release.
*
* @name version
* @instance
* @memberof Map
* @var {string} version
*/

get version(): string { return version; }
}

export default Map;
Expand Down
4 changes: 2 additions & 2 deletions test/unit/ui/marker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ test('Marker with draggable:true moves to new position in response to a mouse-tr
simulate.mouseup(el);

const endPos = map.project(marker.getLngLat());
t.equal(Math.floor(endPos.x), startPos.x + 10);
t.equal(Math.floor(endPos.y), startPos.y + 10);
t.equal(Math.round(endPos.x), startPos.x + 10);
t.equal(Math.round(endPos.y), startPos.y + 10);

map.remove();
t.end();
Expand Down