Skip to content

Commit

Permalink
Address review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
karimnaaji committed Apr 20, 2022
1 parent 6a7c1ea commit 435492a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
15 changes: 13 additions & 2 deletions src/geo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ class Transform {
// globe coordinate transformation matrix
globeMatrix: Float64Array;

globeCenterInViewSpace: [number, number, number];
globeRadius: number;

inverseAdjustmentMatrix: Array<number>;

minLng: number;
Expand Down Expand Up @@ -1767,8 +1770,16 @@ class Transform {
if (!m) throw new Error("failed to invert matrix");
this.pixelMatrixInverse = m;

// globe matrix
this.globeMatrix = this.projection.name === 'globe' ? calculateGlobeMatrix(this) : m;
if (this.projection.name === 'globe') {
this.globeMatrix = calculateGlobeMatrix(this);

const globeCenter = [this.globeMatrix[12], this.globeMatrix[13], this.globeMatrix[14]];

this.globeCenterInViewSpace = vec3.transformMat4(globeCenter, globeCenter, worldToCamera);
this.globeRadius = this.worldSize / 2.0 / Math.PI - 1.0;
} else {
this.globeMatrix = m;
}

this._projMatrixCache = {};
this._alignedProjMatrixCache = {};
Expand Down
4 changes: 2 additions & 2 deletions src/render/draw_atmosphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ function drawAtmosphere(painter: Painter, fog: Fog) {
const horizonBlend = mapValue(fog.properties.get('horizon-blend'), 0.0, 1.0, 0.0, 0.25);

const temporalOffset = (painter.frameCounter / 1000.0) % 1;
const globeCenterInViewSpace = (((painter.globeCenterInViewSpace): any): Array<number>);
const globeCenterInViewSpace = (((tr.globeCenterInViewSpace): any): Array<number>);
const globeCenterDistance = vec3.length(globeCenterInViewSpace);
const distanceToHorizon = Math.sqrt(Math.pow(globeCenterDistance, 2.0) - Math.pow(painter.globeRadius, 2.0));
const distanceToHorizon = Math.sqrt(Math.pow(globeCenterDistance, 2.0) - Math.pow(tr.globeRadius, 2.0));
const horizonAngle = Math.acos(distanceToHorizon / globeCenterDistance);

const uniforms = atmosphereUniformValues(
Expand Down
29 changes: 6 additions & 23 deletions src/render/painter.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ class Painter {
debugOverlayCanvas: HTMLCanvasElement;
_terrain: ?Terrain;
globeSharedBuffers: ?GlobeSharedBuffers;
globeCenterInViewSpace: [number, number, number];
globeRadius: number;
viewport: [number, number];
atmosphereBuffer: AtmosphereBuffer;
tileLoaded: boolean;
frameCopies: Array<WebGLTexture>;
Expand Down Expand Up @@ -562,23 +559,6 @@ class Painter {
this.globeSharedBuffers = new GlobeSharedBuffers(this.context);
}

if (isGlobe) {
const tr = this.transform;
const viewMatrix = tr._camera.getWorldToCamera(tr.worldSize, 1.0);
const globeCenter = [tr.globeMatrix[12], tr.globeMatrix[13], tr.globeMatrix[14]];

this.globeCenterInViewSpace = vec3.transformMat4(globeCenter, globeCenter, viewMatrix);
this.globeRadius = tr.worldSize / 2.0 / Math.PI - 1.0;
this.viewport = [
tr.width * browser.devicePixelRatio,
tr.height * browser.devicePixelRatio
];
} else {
this.globeCenterInViewSpace = [0, 0, 0];
this.globeRadius = 0;
this.viewport = [0, 0];
}

// Following line is billing related code. Do not change. See LICENSE.txt
if (!isMapAuthenticated(this.context.gl)) return;

Expand Down Expand Up @@ -1013,9 +993,12 @@ class Painter {
this.transform.frustumCorners.TR,
this.transform.frustumCorners.BR,
this.transform.frustumCorners.BL,
this.globeCenterInViewSpace,
this.globeRadius,
this.viewport);
this.transform.globeCenterInViewSpace,
this.transform.globeRadius,
[
this.transform.width * browser.devicePixelRatio,
this.transform.height * browser.devicePixelRatio
]);

program.setFogUniformValues(context, fogUniforms);
}
Expand Down

0 comments on commit 435492a

Please sign in to comment.