From 9e575ccb6cf1ea7fb41174de9980813ecbcfcfff Mon Sep 17 00:00:00 2001 From: Austin Eng <213reeses@gmail.com> Date: Tue, 31 Jan 2017 08:41:12 -0500 Subject: [PATCH] don't explicitly add draw commands; various fixes --- Source/Scene/DebugCameraPrimitive.js | 18 +++++++-------- Source/Scene/FrameState.js | 9 +++++--- Source/Scene/Scene.js | 34 ++++++++++++++++------------ 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/Source/Scene/DebugCameraPrimitive.js b/Source/Scene/DebugCameraPrimitive.js index 7875b4930b3a..d162e7ca40f0 100644 --- a/Source/Scene/DebugCameraPrimitive.js +++ b/Source/Scene/DebugCameraPrimitive.js @@ -92,7 +92,7 @@ define([ this._planesPrimitive = undefined; } - var frustumCornersNDC = new Array(8); + var frustumCornersNDC = new Array(4); frustumCornersNDC[0] = new Cartesian4(-1.0, -1.0, 1.0, 1.0); frustumCornersNDC[1] = new Cartesian4(1.0, -1.0, 1.0, 1.0); frustumCornersNDC[2] = new Cartesian4(1.0, 1.0, 1.0, 1.0); @@ -100,7 +100,7 @@ define([ var scratchMatrix = new Matrix4(); var scratchFrustumCorners = new Array(4); - for (var i = 0; i < 8; ++i) { + for (var i = 0; i < 4; ++i) { scratchFrustumCorners[i] = new Cartesian4(); } @@ -126,7 +126,8 @@ define([ var viewProjection = Matrix4.multiply(projection, view, scratchMatrix); var inverseViewProjection = Matrix4.inverse(viewProjection, scratchMatrix); - var numFrustums = Math.max(1, Math.ceil(Math.log(frameState.far / frameState.near) / Math.log(frameState.farToNearRatio))); + var frustumSplits = frameState.frustumSplits; + var numFrustums = frustumSplits.length - 1; var positions = new Float64Array(3 * 4 * (numFrustums + 1)); var f; @@ -139,9 +140,8 @@ define([ Cartesian3.subtract(corner, this._camera.positionWC, corner); Cartesian3.normalize(corner, corner); - var d = frameState.near * Math.pow(frameState.farToNearRatio, f); var fac = Cartesian3.dot(this._camera.directionWC, corner); - Cartesian3.multiplyByScalar(corner, d / fac, corner); + Cartesian3.multiplyByScalar(corner, frustumSplits[f] / fac, corner); Cartesian3.add(corner, this._camera.positionWC, corner); positions[12 * f + i * 3] = corner.x; @@ -163,7 +163,7 @@ define([ // Create the outline primitive var outlineIndices = new Uint16Array(8 * (2 * numFrustums + 1)); - // build the far planes + // Build the far planes for (f = 0; f < numFrustums + 1; ++f) { outlineIndices[f * 8] = f * 4; outlineIndices[f * 8 + 1] = f * 4 + 1; @@ -174,7 +174,7 @@ define([ outlineIndices[f * 8 + 6] = f * 4 + 3; outlineIndices[f * 8 + 7] = f * 4; } - // build the sides of the frustums + // Build the sides of the frustums for (f = 0; f < numFrustums; ++f) { offset = (numFrustums + 1 + f) * 8; outlineIndices[offset] = f * 4; @@ -210,7 +210,7 @@ define([ // Create the planes primitive var planesIndices = new Uint16Array(6 * (5 * numFrustums + 1)); - // build the far planes + // Build the far planes for (f = 0; f < numFrustums + 1; ++f) { planesIndices[f * 6] = f * 4; planesIndices[f * 6 + 1] = f * 4 + 1; @@ -219,7 +219,7 @@ define([ planesIndices[f * 6 + 4] = f * 4 + 2; planesIndices[f * 6 + 5] = f * 4 + 3; } - // build the sides of the frustums + // Build the sides of the frustums for (f = 0; f < numFrustums; ++f) { offset = (numFrustums + 1 + 4 * f) * 6; planesIndices[offset] = 4 * f + 4; diff --git a/Source/Scene/FrameState.js b/Source/Scene/FrameState.js index 674a4a7ea2d7..8025afce5fa6 100644 --- a/Source/Scene/FrameState.js +++ b/Source/Scene/FrameState.js @@ -236,9 +236,12 @@ define([ */ this.imagerySplitPosition = 0.0; - this.near = 1.0; - this.far = 1000.0; - this.farToNearRatio = 1000.0; + /** + * Distances to the near and far planes of the camera frustums + * @type {Number[]} + * @default [1.0, 1000.0] + */ + this.frustumSplits = [1.0, 1000.0]; } /** diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 04f31486707a..728ec214cc77 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -952,7 +952,7 @@ define([ /** * This property is for debugging only; it is not for production use. *

- * When true, draws primitives to show the boundaries of the camera frustum + * When true, draws outlines to show the boundaries of the camera frustums *

* * @type Boolean @@ -963,23 +963,19 @@ define([ get : function() { return this._debugShowFrustumPlanes; }, - - set : function(val) { - if (!val) { + set : function(value) { + if (!value) { if (defined(this._debugFrustumPlanes)) { - this.primitives.remove(this._debugFrustumPlanes); - this._debugFrustumPlanes = this._debugFrustumPlanes && !this._debugFrustumPlanes.isDestroyed() && this._debugFrustumPlanes.destroy(); + this._debugFrustumPlanes = this._debugFrustumPlanes && this._debugFrustumPlanes.destroy(); } - } else if (val !== this._debugShowFrustumPlanes) { - this._debugFrustumPlanes = this._debugFrustumPlanes && !this._debugFrustumPlanes.isDestroyed() && this._debugFrustumPlanes.destroy(); + } else if (value !== this._debugShowFrustumPlanes) { + this._debugFrustumPlanes = this._debugFrustumPlanes && this._debugFrustumPlanes.destroy(); this._debugFrustumPlanes = new DebugCameraPrimitive({ camera: this.camera, updateOnChange: false }); - this._debugFrustumPlanes.update(this.frameState); - this.primitives.add(this._debugFrustumPlanes); } - this._debugShowFrustumPlanes = val; + this._debugShowFrustumPlanes = value; } }, @@ -1467,11 +1463,17 @@ define([ if (near !== Number.MAX_VALUE && (numFrustums !== numberOfFrustums || (frustumCommandsList.length !== 0 && (near < frustumCommandsList[0].near || far > frustumCommandsList[numberOfFrustums - 1].far)))) { updateFrustums(near, far, farToNearRatio, numFrustums, frustumCommandsList, is2D, scene.nearToFarDistance2D); - frameState.near = near; - frameState.far = far; - frameState.farToNearRatio = farToNearRatio; createPotentiallyVisibleSet(scene); } + + var frustumSplits = frameState.frustumSplits; + frustumSplits.length = numFrustums + 1; + for (var j = 0; j < numFrustums; ++j) { + frustumSplits[j] = frustumCommandsList[j].near; + if (j === numFrustums - 1) { + frustumSplits[j + 1] = frustumCommandsList[j].far; + } + } } function getAttributeLocations(shaderProgram) { @@ -2282,6 +2284,9 @@ define([ scene._groundPrimitives.update(frameState); scene._primitives.update(frameState); + if (defined(scene._debugFrustumPlanes)) { + scene._debugFrustumPlanes.update(frameState) + } updateShadowMaps(scene); @@ -2938,6 +2943,7 @@ define([ this._sunPostProcess = this._sunPostProcess && this._sunPostProcess.destroy(); this._depthPlane = this._depthPlane && this._depthPlane.destroy(); this._transitioner.destroy(); + this._debugFrustumPlanes = this._debugFrustumPlanes && this._debugFrustumPlanes.destroy(); if (defined(this._globeDepth)) { this._globeDepth.destroy();