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 22, 2019
1 parent 9a40a5e commit 761660f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
10 changes: 10 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,15 @@ class GlobeLayer extends TiledGeometryLayer {
cameraPosition.copy(context.camera.camera3D.position).applyMatrix4(worldToScaledEllipsoid);
magnitudeSquared = cameraPosition.lengthSq() - 1.0;

// pre-horizon subdivision
scaledHorizonCullingPoint.copy(context.camera.camera3D.position).multiply(scaledToSphere);

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

return super.preUpdate(context, changeSources);
}

Expand Down
9 changes: 9 additions & 0 deletions src/Core/Prefab/Planar/PlanarLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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 ratioHorizon = 0.1;
const distanceToGround = context.camera.camera3D.position.z;
context.horizon = distanceToGround / Math.sin(Math.atan(ratioHorizon * Math.tan(fov)));

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

export default PlanarLayer;
4 changes: 4 additions & 0 deletions src/Layer/TiledGeometryLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,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 761660f

Please sign in to comment.