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

Fix depth plane clipping #8203

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 11 additions & 1 deletion Source/Scene/DepthPlane.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
define([
'../Core/ApproximateTerrainHeights',
'../Core/BoundingSphere',
'../Core/Cartesian3',
'../Core/ComponentDatatype',
Expand All @@ -18,6 +19,7 @@ define([
'../Shaders/DepthPlaneVS',
'./SceneMode'
], function(
ApproximateTerrainHeights,
BoundingSphere,
Cartesian3,
ComponentDatatype,
Expand Down Expand Up @@ -51,15 +53,23 @@ define([
}

var depthQuadScratch = FeatureDetection.supportsTypedArrays() ? new Float32Array(12) : [];
var scratchRadii = new Cartesian3();
var scratchCartesian1 = new Cartesian3();
var scratchCartesian2 = new Cartesian3();
var scratchCartesian3 = new Cartesian3();
var scratchCartesian4 = new Cartesian3();

function computeDepthQuad(ellipsoid, frameState) {
var radii = ellipsoid.radii;
var radii = Cartesian3.clone(ellipsoid.radii, scratchRadii);
var p = frameState.camera.positionWC;

// This effectively pushes the depth plane farther from the camera so that the depth plane does not render
// above primitives in the scene.
var radiusOffset = -ApproximateTerrainHeights._defaultMinTerrainHeight;
radii.x -= radiusOffset;
radii.y -= radiusOffset;
radii.z -= radiusOffset;

// Find the corresponding position in the scaled space of the ellipsoid.
var q = Cartesian3.multiplyComponents(ellipsoid.oneOverRadii, p, scratchCartesian1);

Expand Down