-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Add multifrustum near/far planes to DebugCameraPrimitive #4932
Changes from 6 commits
afad284
58f2879
3b69d8d
9e575cc
270a0fd
672405a
06c8f7c
495631e
4b7843a
0b44434
82b88a9
58783cb
9d28ee1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ Change Log | |
* The attribute `perInstanceAttribute` of `DebugAppearance` has been made optional and defaults to `false`. | ||
* Fixed a bug that would cause a crash when `debugShowFrustums` is enabled with OIT. [#4864](https://github.com/AnalyticalGraphicsInc/cesium/pull/4864) | ||
* Added the ability to run the unit tests with a [WebGL Stub](https://github.com/AnalyticalGraphicsInc/cesium/tree/master/Documentation/Contributors/TestingGuide#run-with-webgl-stub), which makes all WebGL calls a noop and ignores test expectations that rely on reading back from WebGL. Use the web link from the main index.html or run with `npm run test-webgl-stub`. | ||
* Added support to `DebugCameraPrimitive` to draw multifrustum planes. `CesiumInspector` also displays this toggle. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The merge conflict in here needs to be resolved. |
||
### 1.29 - 2017-01-02 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,19 +92,15 @@ define([ | |
this._planesPrimitive = undefined; | ||
} | ||
|
||
var frustumCornersNDC = new Array(8); | ||
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); | ||
frustumCornersNDC[4] = new Cartesian4(-1.0, -1.0, 1.0, 1.0); | ||
frustumCornersNDC[5] = new Cartesian4(1.0, -1.0, 1.0, 1.0); | ||
frustumCornersNDC[6] = new Cartesian4(1.0, 1.0, 1.0, 1.0); | ||
frustumCornersNDC[7] = new Cartesian4(-1.0, 1.0, 1.0, 1.0); | ||
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(8); | ||
for (var i = 0; i < 8; ++i) { | ||
var scratchFrustumCorners = new Array(4); | ||
for (var i = 0; i < 4; ++i) { | ||
scratchFrustumCorners[i] = new Cartesian4(); | ||
} | ||
|
||
|
@@ -130,14 +126,28 @@ define([ | |
var viewProjection = Matrix4.multiply(projection, view, scratchMatrix); | ||
var inverseViewProjection = Matrix4.inverse(viewProjection, scratchMatrix); | ||
|
||
var positions = new Float64Array(8 * 3); | ||
for (var i = 0; i < 8; ++i) { | ||
var corner = Cartesian4.clone(frustumCornersNDC[i], scratchFrustumCorners[i]); | ||
Matrix4.multiplyByVector(inverseViewProjection, corner, corner); | ||
Cartesian3.divideByScalar(corner, corner.w, corner); // Handle the perspective divide | ||
positions[i * 3] = corner.x; | ||
positions[i * 3 + 1] = corner.y; | ||
positions[i * 3 + 2] = corner.z; | ||
var frustumSplits = frameState.frustumSplits; | ||
var numFrustums = frustumSplits.length - 1; | ||
|
||
var positions = new Float64Array(3 * 4 * (numFrustums + 1)); | ||
var f; | ||
for (f = 0; f < numFrustums + 1; ++f) { | ||
for (var i = 0; i < 4; ++i) { | ||
var corner = Cartesian4.clone(frustumCornersNDC[i], scratchFrustumCorners[i]); | ||
|
||
Matrix4.multiplyByVector(inverseViewProjection, corner, corner); | ||
Cartesian3.divideByScalar(corner, corner.w, corner); // Handle the perspective divide | ||
Cartesian3.subtract(corner, this._camera.positionWC, corner); | ||
Cartesian3.normalize(corner, corner); | ||
|
||
var fac = Cartesian3.dot(this._camera.directionWC, corner); | ||
Cartesian3.multiplyByScalar(corner, frustumSplits[f] / fac, corner); | ||
Cartesian3.add(corner, this._camera.positionWC, corner); | ||
|
||
positions[12 * f + i * 3] = corner.x; | ||
positions[12 * f + i * 3 + 1] = corner.y; | ||
positions[12 * f + i * 3 + 2] = corner.z; | ||
} | ||
} | ||
|
||
var boundingSphere = new BoundingSphere.fromVertices(positions); | ||
|
@@ -149,8 +159,33 @@ define([ | |
values : positions | ||
}); | ||
|
||
var offset; | ||
|
||
// Create the outline primitive | ||
var outlineIndices = new Uint16Array([0,1,1,2,2,3,3,0,0,4,4,7,7,3,7,6,6,2,2,1,1,5,5,4,5,6]); | ||
var outlineIndices = new Uint16Array(8 * (2 * numFrustums + 1)); | ||
// Build the far planes | ||
for (f = 0; f < numFrustums + 1; ++f) { | ||
outlineIndices[f * 8] = f * 4; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and in the loop below, assign There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment throughout. |
||
outlineIndices[f * 8 + 1] = f * 4 + 1; | ||
outlineIndices[f * 8 + 2] = f * 4 + 1; | ||
outlineIndices[f * 8 + 3] = f * 4 + 2; | ||
outlineIndices[f * 8 + 4] = f * 4 + 2; | ||
outlineIndices[f * 8 + 5] = f * 4 + 3; | ||
outlineIndices[f * 8 + 6] = f * 4 + 3; | ||
outlineIndices[f * 8 + 7] = f * 4; | ||
} | ||
// Build the sides of the frustums | ||
for (f = 0; f < numFrustums; ++f) { | ||
offset = (numFrustums + 1 + f) * 8; | ||
outlineIndices[offset] = f * 4; | ||
outlineIndices[offset + 1] = f * 4 + 4; | ||
outlineIndices[offset + 2] = f * 4 + 1; | ||
outlineIndices[offset + 3] = f * 4 + 5; | ||
outlineIndices[offset + 4] = f * 4 + 2; | ||
outlineIndices[offset + 5] = f * 4 + 6; | ||
outlineIndices[offset + 6] = f * 4 + 3; | ||
outlineIndices[offset + 7] = f * 4 + 7; | ||
} | ||
|
||
this._outlinePrimitive = new Primitive({ | ||
geometryInstances : new GeometryInstance({ | ||
|
@@ -174,7 +209,47 @@ define([ | |
}); | ||
|
||
// Create the planes primitive | ||
var planesIndices = new Uint16Array([4,5,6,4,6,7,5,1,2,5,2,6,7,6,2,7,2,3,0,1,5,0,5,4,0,4,7,0,7,3,1,0,3,1,3,2]); | ||
var planesIndices = new Uint16Array(6 * (5 * numFrustums + 1)); | ||
// Build the far planes | ||
for (f = 0; f < numFrustums + 1; ++f) { | ||
planesIndices[f * 6] = f * 4; | ||
planesIndices[f * 6 + 1] = f * 4 + 1; | ||
planesIndices[f * 6 + 2] = f * 4 + 2; | ||
planesIndices[f * 6 + 3] = f * 4; | ||
planesIndices[f * 6 + 4] = f * 4 + 2; | ||
planesIndices[f * 6 + 5] = f * 4 + 3; | ||
} | ||
// Build the sides of the frustums | ||
for (f = 0; f < numFrustums; ++f) { | ||
offset = (numFrustums + 1 + 4 * f) * 6; | ||
planesIndices[offset] = 4 * f + 4; | ||
planesIndices[offset + 1] = 4 * f; | ||
planesIndices[offset + 2] = 4 * f + 3; | ||
planesIndices[offset + 3] = 4 * f + 4; | ||
planesIndices[offset + 4] = 4 * f + 3; | ||
planesIndices[offset + 5] = 4 * f + 7; | ||
|
||
planesIndices[offset + 6] = 4 * f + 4; | ||
planesIndices[offset + 7] = 4 * f; | ||
planesIndices[offset + 8] = 4 * f + 1; | ||
planesIndices[offset + 9] = 4 * f + 4; | ||
planesIndices[offset + 10] = 4 * f + 1; | ||
planesIndices[offset + 11] = 4 * f + 5; | ||
|
||
planesIndices[offset + 12] = 4 * f + 7; | ||
planesIndices[offset + 13] = 4 * f + 3; | ||
planesIndices[offset + 14] = 4 * f + 2; | ||
planesIndices[offset + 15] = 4 * f + 7; | ||
planesIndices[offset + 16] = 4 * f + 2; | ||
planesIndices[offset + 17] = 4 * f + 6; | ||
|
||
planesIndices[offset + 18] = 4 * f + 6; | ||
planesIndices[offset + 19] = 4 * f + 2; | ||
planesIndices[offset + 20] = 4 * f + 1; | ||
planesIndices[offset + 21] = 4 * f + 6; | ||
planesIndices[offset + 22] = 4 * f + 1; | ||
planesIndices[offset + 23] = 4 * f + 5; | ||
} | ||
|
||
this._planesPrimitive = new Primitive({ | ||
geometryInstances : new GeometryInstance({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,6 +235,13 @@ define([ | |
* @default 0.0 | ||
*/ | ||
this.imagerySplitPosition = 0.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]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure about these defaults? Perhaps set this to |
||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ define([ | |
'./Camera', | ||
'./CreditDisplay', | ||
'./CullingVolume', | ||
'./DebugCameraPrimitive', | ||
'./DepthPlane', | ||
'./DeviceOrientationCameraController', | ||
'./Fog', | ||
|
@@ -109,6 +110,7 @@ define([ | |
Camera, | ||
CreditDisplay, | ||
CullingVolume, | ||
DebugCameraPrimitive, | ||
DepthPlane, | ||
DeviceOrientationCameraController, | ||
Fog, | ||
|
@@ -515,6 +517,9 @@ define([ | |
*/ | ||
this.debugShowDepthFrustum = 1; | ||
|
||
this._debugShowFrustumPlanes = false; | ||
this._debugFrustumPlanes = undefined; | ||
|
||
/** | ||
* When <code>true</code>, enables Fast Approximate Anti-aliasing even when order independent translucency | ||
* is unsupported. | ||
|
@@ -944,6 +949,36 @@ define([ | |
} | ||
}, | ||
|
||
/** | ||
* This property is for debugging only; it is not for production use. | ||
* <p> | ||
* When <code>true</code>, draws outlines to show the boundaries of the camera frustums | ||
* </p> | ||
* | ||
* @type Boolean | ||
* | ||
* @default false | ||
*/ | ||
debugShowFrustumPlanes : { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When this is merged into the |
||
get : function() { | ||
return this._debugShowFrustumPlanes; | ||
}, | ||
set : function(value) { | ||
if (!value) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and below, do not call Instead check if this flag changed in the render loop and then create or destroy. For example, see |
||
if (defined(this._debugFrustumPlanes)) { | ||
this._debugFrustumPlanes = this._debugFrustumPlanes && 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._debugShowFrustumPlanes = value; | ||
} | ||
}, | ||
|
||
/** | ||
* Gets whether or not the scene is optimized for 3D only viewing. | ||
* @memberof Scene.prototype | ||
|
@@ -1430,6 +1465,15 @@ define([ | |
updateFrustums(near, far, farToNearRatio, numFrustums, frustumCommandsList, is2D, scene.nearToFarDistance2D); | ||
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) { | ||
|
@@ -2240,6 +2284,9 @@ define([ | |
|
||
scene._groundPrimitives.update(frameState); | ||
scene._primitives.update(frameState); | ||
if (defined(scene._debugFrustumPlanes)) { | ||
scene._debugFrustumPlanes.update(frameState); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cleaner if all this is placed in its own function |
||
updateShadowMaps(scene); | ||
|
||
|
@@ -2896,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(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explicitly mention the new properties and arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also move this to a new section for 1.31 since this is unlikely to make the 1.30 release, which is going out tomorrow morning.