Skip to content

Commit

Permalink
feat(core): optimization subdivision with horizon
Browse files Browse the repository at this point in the history
  • Loading branch information
gchoqueux committed Jan 18, 2019
1 parent 149208c commit efde2d9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/Core/Prefab/Globe/GlobeLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let magnitudeSquared = 0.0;

// vectors for operation purpose
const scaledHorizonCullingPoint = new THREE.Vector3();
const scaledToSphere = new THREE.Vector3(1.0, 1.0, ellipsoidSizes.x / ellipsoidSizes.z);

/**
* @property {boolean} isGlobeLayer - Used to checkout whether this layer is a
Expand Down Expand Up @@ -89,6 +90,14 @@ class GlobeLayer extends TiledGeometryLayer {
cameraPosition.copy(context.camera.camera3D.position).applyMatrix4(worldToScaledEllipsoid);
magnitudeSquared = cameraPosition.lengthSq() - 1.0;

scaledHorizonCullingPoint.copy(context.camera.camera3D.position).multiply(scaledToSphere);

const length = scaledHorizonCullingPoint.length();
context.horizon = (length ** 2 - ellipsoidSizes.x ** 2) ** 0.5;
const distanceToGround = Math.max(length - ellipsoidSizes.x, 0);
const factor = Math.min(distanceToGround / ellipsoidSizes.x, 1.0) ** 0.25;
context.horizon -= (context.horizon - distanceToGround) * 0.75 * (1 - factor);

return super.preUpdate(context, changeSources);
}

Expand Down
10 changes: 9 additions & 1 deletion src/Core/Prefab/Planar/PlanarLayer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as THREE from 'three';

import TiledGeometryLayer from 'Layer/TiledGeometryLayer';
import PlanarTileBuilder from './PlanarTileBuilder';

Expand Down Expand Up @@ -45,6 +44,15 @@ class PlanarLayer extends TiledGeometryLayer {
this.maxSubdivisionLevel = this.maxSubdivisionLevel || 5.0;
this.maxDeltaElevation = this.maxDeltaElevation || 4.0;
}

preUpdate(context, changeSources) {
const fov = THREE.Math.degToRad(context.camera.camera3D.fov * 0.5);
const distanceToGround = context.camera.camera3D.position.z;
const ratioHorizon = 0.1;
context.horizon = distanceToGround / Math.sin(Math.atan(ratioHorizon * Math.tan(fov)));

return super.preUpdate(context, changeSources);
}
}

export default PlanarLayer;
5 changes: 5 additions & 0 deletions src/Layer/TiledGeometryLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class TiledGeometryLayer extends GeometryLayer {
this.schemeTile = schemeTile;
this.builder = builder;
this.info = new InfoTiledGeometryLayer(this);
this.enableSubdivisionHorizon = true;

if (!this.schemeTile) {
throw new Error(`Cannot init tiled layer without schemeTile for layer ${this.id}`);
Expand Down Expand Up @@ -396,6 +397,10 @@ class TiledGeometryLayer extends GeometryLayer {
0.0,
context.camera.camera3D.position.distanceTo(boundingSphereCenter) - node.boundingSphere.radius * subdivisionVector.x);

if (context.horizon && distance > context.horizon) {
return false;
}

// Size projection on pixel of bounding
node.screenSize = context.camera._preSSE * (2 * node.boundingSphere.radius * subdivisionVector.x) / distance;

Expand Down

0 comments on commit efde2d9

Please sign in to comment.