Skip to content

Commit

Permalink
don't explicitly add draw commands; various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
austinEng committed Jan 31, 2017
1 parent 3b69d8d commit 9e575cc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
18 changes: 9 additions & 9 deletions Source/Scene/DebugCameraPrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ 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);
frustumCornersNDC[3] = new Cartesian4(-1.0, 1.0, 1.0, 1.0);

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();
}

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions Source/Scene/FrameState.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

/**
Expand Down
34 changes: 20 additions & 14 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ define([
/**
* This property is for debugging only; it is not for production use.
* <p>
* When <code>true</code>, draws primitives to show the boundaries of the camera frustum
* When <code>true</code>, draws outlines to show the boundaries of the camera frustums
* </p>
*
* @type Boolean
Expand All @@ -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;
}
},

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -2282,6 +2284,9 @@ define([

scene._groundPrimitives.update(frameState);
scene._primitives.update(frameState);
if (defined(scene._debugFrustumPlanes)) {
scene._debugFrustumPlanes.update(frameState)
}

updateShadowMaps(scene);

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 9e575cc

Please sign in to comment.