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

Add multifrustum near/far planes to DebugCameraPrimitive #4932

Merged
merged 13 commits into from
Feb 2, 2017

Conversation

austinEng
Copy link
Contributor

This adds multifrustum near/far planes to DebugCameraPrimitive and adds a toggle in CesiumInspector to draw these planes. This is useful for debugging what primitives are contained in each frustum.

Copy link
Contributor

@lilleyse lilleyse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new functionality!

CHANGES.md Outdated
* 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`.
>>>>>>> agi/master

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The merge conflict in here needs to be resolved.

@@ -93,17 +93,13 @@ define([
}

var frustumCornersNDC = new Array(8);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only 4 now.


var scratchMatrix = new Matrix4();
var scratchFrustumCorners = new Array(8);
var scratchFrustumCorners = new Array(4);
for (var i = 0; i < 8; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be 4

positions[i * 3] = corner.x;
positions[i * 3 + 1] = corner.y;
positions[i * 3 + 2] = corner.z;
var numFrustums = Math.max(1, Math.ceil(Math.log(frameState.far / frameState.near) / Math.log(frameState.farToNearRatio)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think FrameState should store the exact splits rather than recalculating here.

// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalize the first word in comments.

@@ -945,6 +950,40 @@ 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tweak wording a bit - draws outlines to show the boundaries of the camera frustums

get : function() {
return this._debugShowFrustumPlanes;
},

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove empty line.

updateOnChange: false
});
this._debugFrustumPlanes.update(this.frameState);
this.primitives.add(this._debugFrustumPlanes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not add directly to primitives. Instead Scene should be responsible for pushing this._debugFrustumPlanes's commands.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While doing that make sure to destroy it when scene is destroyed.

return this._debugShowFrustumPlanes;
},

set : function(val) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val -> value

@austinEng
Copy link
Contributor Author

@lilleyse Updated.

@lilleyse
Copy link
Contributor

Looks good to me, does anyone else want to review quickly?

@pjcozzi
Copy link
Contributor

pjcozzi commented Feb 1, 2017

Are we sure it is correct? It seems like it doesn't draw the farthest frustum.

var outlineIndices = new Uint16Array(8 * (2 * numFrustums + 1));
// Build the far planes
for (f = 0; f < numFrustums + 1; ++f) {
outlineIndices[f * 8] = f * 4;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in the loop below, assign f * 8 and f * 4 to locals. I do not know if the JS engine would optimize. This primitive is just for debugging, but in general primitive.update functions are carefully coded for performance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment throughout.

* @type {Number[]}
* @default [1.0, 1000.0]
*/
this.frustumSplits = [1.0, 1000.0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about these defaults? Perhaps set this to []. At the start of the frame, set the length to zero (which does not free the memory), then push each distance.

CHANGES.md Outdated
@@ -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.
Copy link
Contributor

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.

Copy link
Contributor

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.

return this._debugShowFrustumPlanes;
},
set : function(value) {
if (!value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below, do not call destroy and new DebugCameraPrimitive in the set function; it could result in WebGL calls being made outside of request animation frame.

Instead check if this flag changed in the render loop and then create or destroy.

For example, see modelMatrix in DebugModelMatrixPrimitive.

*
* @default false
*/
debugShowFrustumPlanes : {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this is merged into the 3d-tiles branch, please remove the code that explicitly creates the debug frustum in the Cesium3DTileset and just have the inspector set this property.

@pjcozzi
Copy link
Contributor

pjcozzi commented Feb 1, 2017

This will be very cool for performance and visual artifact debugging.

@austinEng
Copy link
Contributor Author

Are we sure it is correct? It seems like it doesn't draw the farthest frustum.

As in it's the wrong size or it doesn't appear at all? I thought that planes were located wrongly at first, but I realized that since I'm computing the splits based on the distances computed in Scene, and we clamp the planes distances down to the size of the contained bounding spheres, I think it makes sense that the last far plane doesn't extend as far as expected.

@pjcozzi
Copy link
Contributor

pjcozzi commented Feb 1, 2017

Looks good, but try a case when the viewer is near terrain and looking slightly up and there are 3 frustums.

@austinEng
Copy link
Contributor Author

austinEng commented Feb 1, 2017

Here's three frustums

1
2
3

1
2
3

@pjcozzi
Copy link
Contributor

pjcozzi commented Feb 1, 2017

OK, not sure what we where running to offline.

I am good with this!

@lilleyse did you want to look at the latest changes?

Copy link
Contributor

@lilleyse lilleyse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaner if all this is placed in its own function updateDebugFrustumPlanes

@@ -149,8 +165,38 @@ define([
values : positions
});

var offset, idx;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid abbreviations, index is fine.

@austinEng
Copy link
Contributor Author

@lilleyse is this ready to be merged then?

@lilleyse
Copy link
Contributor

lilleyse commented Feb 2, 2017

Yes, thanks @austinEng .

@lilleyse lilleyse merged commit b6afe7e into CesiumGS:master Feb 2, 2017
@lilleyse lilleyse mentioned this pull request Feb 3, 2017
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants