From 7eb8e2a9c9cd803d11b429288f6cee894e05f3c5 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 17 Jul 2019 12:39:07 -0400 Subject: [PATCH] set further near plane to fix precision for deckgl fix #7573 --- src/geo/transform.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/geo/transform.js b/src/geo/transform.js index 2707af82fda..289d05dc14f 100644 --- a/src/geo/transform.js +++ b/src/geo/transform.js @@ -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; + // 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, this.height / 50, farZ); mat4.scale(m, m, [1, -1, 1]); mat4.translate(m, m, [0, 0, -this.cameraToCenterDistance]);