-
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
Conversation
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.
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 | ||
|
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.
The merge conflict in here needs to be resolved.
Source/Scene/DebugCameraPrimitive.js
Outdated
@@ -93,17 +93,13 @@ define([ | |||
} | |||
|
|||
var frustumCornersNDC = new Array(8); |
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.
Only 4 now.
Source/Scene/DebugCameraPrimitive.js
Outdated
|
||
var scratchMatrix = new Matrix4(); | ||
var scratchFrustumCorners = new Array(8); | ||
var scratchFrustumCorners = new Array(4); | ||
for (var i = 0; i < 8; ++i) { |
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.
Should be 4
Source/Scene/DebugCameraPrimitive.js
Outdated
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))); |
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.
I think FrameState
should store the exact splits rather than recalculating here.
Source/Scene/DebugCameraPrimitive.js
Outdated
// 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 |
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.
Capitalize the first word in comments.
Source/Scene/Scene.js
Outdated
@@ -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 |
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.
Tweak wording a bit - draws outlines to show the boundaries of the camera frustums
Source/Scene/Scene.js
Outdated
get : function() { | ||
return this._debugShowFrustumPlanes; | ||
}, | ||
|
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.
Remove empty line.
Source/Scene/Scene.js
Outdated
updateOnChange: false | ||
}); | ||
this._debugFrustumPlanes.update(this.frameState); | ||
this.primitives.add(this._debugFrustumPlanes); |
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.
Do not add directly to primitives
. Instead Scene
should be responsible for pushing this._debugFrustumPlanes
's commands.
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.
While doing that make sure to destroy it when scene is destroyed.
Source/Scene/Scene.js
Outdated
return this._debugShowFrustumPlanes; | ||
}, | ||
|
||
set : function(val) { |
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.
val
-> value
9372246
to
270a0fd
Compare
@lilleyse Updated. |
Looks good to me, does anyone else want to review quickly? |
Are we sure it is correct? It seems like it doesn't draw the farthest frustum. |
Source/Scene/DebugCameraPrimitive.js
Outdated
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 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.
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.
Same comment throughout.
Source/Scene/FrameState.js
Outdated
* @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 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. |
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.
Source/Scene/Scene.js
Outdated
return this._debugShowFrustumPlanes; | ||
}, | ||
set : function(value) { | ||
if (!value) { |
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.
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.
Source/Scene/Scene.js
Outdated
* | ||
* @default false | ||
*/ | ||
debugShowFrustumPlanes : { |
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.
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.
This will be very cool for performance and visual artifact debugging. |
aee3c96
to
82b88a9
Compare
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 |
Looks good, but try a case when the viewer is near terrain and looking slightly up and there are 3 frustums. |
OK, not sure what we where running to offline. I am good with this! @lilleyse did you want to look at the latest changes? |
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.
Changes look good.
Source/Scene/Scene.js
Outdated
if (defined(scene._debugFrustumPlanes)) { | ||
scene._debugFrustumPlanes.update(frameState); | ||
} | ||
|
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.
Cleaner if all this is placed in its own function updateDebugFrustumPlanes
Source/Scene/DebugCameraPrimitive.js
Outdated
@@ -149,8 +165,38 @@ define([ | |||
values : positions | |||
}); | |||
|
|||
var offset, idx; |
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.
Avoid abbreviations, index
is fine.
32d84fa
to
98622d8
Compare
98622d8
to
58783cb
Compare
a0bcd74
to
9d28ee1
Compare
@lilleyse is this ready to be merged then? |
Yes, thanks @austinEng . |
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.