-
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
Increase max clipping planes using textures #6201
Increase max clipping planes using textures #6201
Conversation
…ets and update-as-needed
@likangning93, thanks for the pull request! Maintainers, we have a signed CLA from @likangning93, so you can review this at any time. I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome. 🌍 🌎 🌏 |
This doesn't sound like something we should ship to end users. We have a |
Please bump to me for a final review when ready. In the meantime, one comment:
We can likely use float textures when available and emulate the 64-bit floating subtraction - which is generally the main cause of jitter - just like we do for vertex positions with RTE rendering. @bagnell or @lilleyse can point you to example code. |
It's kind of nice putting pre-transform planes into the texture though, since we don't have to run CPU-side packing math every frame or do a Post-transform planes are also tricky with 3D Tilesets because tiles can have their own matrices - we'd be doing a lot more texture updates in that case, so performance could be really bad. |
@likangning93 I don't have the bandwidth to work on this right now, but if there is a precision issue please discuss with @bagnell or @lilleyse as I'm confident there is an approach where we could get higher precision and still keep all the work in the shader. |
|
|
||
var modelUrl = '../../SampleData/models/CesiumAir/Cesium_Air.glb'; | ||
var agiHqUrl = Cesium.CesiumIon.createResource(1458, { accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIxYmJiNTAxOC1lOTg5LTQzN2EtODg1OC0zMWJjM2IxNGNlYmMiLCJpZCI6NDQsImFzc2V0cyI6WzE0NThdLCJpYXQiOjE0OTkyNjM4MjB9.1WKijRa-ILkmG6utrhDWX6rDgasjD7dZv-G5ZyCmkKg' }); | ||
var instancedUrl = '../../../Specs/Data/Cesium3DTiles/Instanced/InstancedOrientation/'; |
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.
Make the same changes here as Apps/Sandcastle/gallery/3D Tiles Clipping Planes.html
in https://github.com/AnalyticalGraphicsInc/cesium/pull/6218/files
@@ -0,0 +1,255 @@ | |||
<!DOCTYPE html> |
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.
For consistency Many Clipping Planes.jpg
should be 225x150.
|
||
// Avoid wastefully re-uploading textures when the clipping planes don't change between frames | ||
var previousTextureBytes = new ArrayBuffer(ClippingPlaneCollection.TEXTURE_WIDTH * ClippingPlaneCollection.TEXTURE_WIDTH * 4); | ||
previousTextureBytes[0] = 1; |
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.
Is this to trigger that it has changed on the first frame?
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 the idea was to make sure the texture gets updated with a buffer full of zeros if that's the clipping plane texture produced, but on second thought that's probably impossible so this isn't necessary.
this._lengthRangeUnion = new Cartesian4(); | ||
|
||
// Packed uniform for plane count and denormalization parameters | ||
this._lengthRange = new Cartesian3(); |
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.
Why is there both _lengthRange
and _lengthRangeUnion
?
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.
globe and point cloud shaders get regenerated if the ClippingPlaneCollection
is flipped from union to intersection, while Model.js
just puts a branch in the shader. I think @pjcozzi mentioned changing Model.js
to also regenerate shaders on the fly, though. Should that be in a separate PR?
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.
It don't think it hurts if all systems use the vec4 version for now.
Yeah, Model changes will be in another PR.
* | ||
* @type {Cartesian3} | ||
*/ | ||
lengthRange : { |
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.
@@ -1272,26 +1287,13 @@ define([ | |||
|
|||
var context = frameState.context; | |||
|
|||
this._defaultTexture = context.defaultTexture; |
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.
Does the content need to hold onto this? It seems like u_clippingPlanes
can just get it from the frame state.
* @type {number} | ||
* @constant | ||
*/ | ||
ClippingPlaneCollection.TEXTURE_WIDTH = CesiumMath.nextPowerOfTwo(Math.ceil(Math.sqrt(ClippingPlaneCollection.MAX_CLIPPING_PLANES * 2))); |
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 wonder if it would make more sense to make this a 1D texture, at least it would simplify some shader code. I can't seem to load https://webglstats.com/webgl right now but we can check what % of devices support 2048 pixel textures.
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.
It might still be better to keep it as a POT though. I think I remember something about those being more efficient for GPU memory or something, although I also vaguely remember someone saying something about how that's not necessarily true anymore...
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.
We try to use 1D textures for the 3D Tiles batch table, so there is some precedent there. But it doesn't matter much in the end.
Specs/Scene/ModelSpec.js
Outdated
new Plane(Cartesian3.UNIT_X, 0.0) | ||
] | ||
}); | ||
model.clippingPlanes = clippingPlanes; |
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.
Fix indentation
expect(scene).notToRender(color); | ||
|
||
tileset.clippingPlanes.unionClippingRegions = false; | ||
|
||
expect(scene).toRenderAndCall(function(rgba) { | ||
console.log(rgba); | ||
}); |
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.
What's with all the console.logs
in here?
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.
this might be a "whoops" sort of thing...
@@ -0,0 +1,255 @@ | |||
<!DOCTYPE html> |
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 really like this demo and feel like it could be incorporated into the main clipping planes demo. If that's annoying to do it could be a standalone demo in the main folder.
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.
@mramato recommended moving it to Development since it's more for debugging and performance testing than demonstrating the feature. @pjcozzi also mentioned at one point that we might do actual clipping cylinders, at which point this demo kind of becomes a "wrong" way to achieve the effect.
I really like this demo
Much appreciated though!
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'm not sure about this being in development
; I just spent awhile looking for it. At the least, there should be a simple example showing using a lot of clipping planes.
Sorry if this was already discussed, but |
@lilleyse updated, but as a quick heads-up (as discussed offline) I'm going to take a look at how much work it'll be to include a float texture version as primary and move the RGBA version to fallback. |
CHANGES.md
Outdated
@@ -5,6 +5,7 @@ Change Log | |||
|
|||
##### Deprecated :hourglass_flowing_sand: | |||
* In the `Resource` class, `addQueryParameters` and `addTemplateValues` have been deprecated and will be removed in Cesium 1.45. Please use `setQueryParameters` and `setTemplateValues` instead. | |||
* `ClippingPlaneCollection` is now supported in Internet Explorer, so `ClippingPlaneCollection.isSupported` has been deprectaed and will be removed in Cesium 1.45. |
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.
Please submit an issue to remind us to do this.
CHANGES.md
Outdated
@@ -5,6 +5,7 @@ Change Log | |||
|
|||
##### Deprecated :hourglass_flowing_sand: | |||
* In the `Resource` class, `addQueryParameters` and `addTemplateValues` have been deprecated and will be removed in Cesium 1.45. Please use `setQueryParameters` and `setTemplateValues` instead. | |||
* `ClippingPlaneCollection` is now supported in Internet Explorer, so `ClippingPlaneCollection.isSupported` has been deprectaed and will be removed in Cesium 1.45. |
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 mention in CHANGES.md that #6184 is fixed.
}) | ||
.then(function() { | ||
tileset.clippingPlanes.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere.center); | ||
}); |
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.
Usually in Cesium code we condense this to:
instancedUrl.then(function(resource) {
return loadTileset(resource);
}).then(function() {
tileset.clippingPlanes.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere.center);
});
* @type {number} | ||
* @constant | ||
*/ | ||
ClippingPlaneCollection.TEXTURE_WIDTH = CesiumMath.nextPowerOfTwo(Math.ceil(Math.sqrt(ClippingPlaneCollection.MAX_CLIPPING_PLANES * 2))); |
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.
Bump.
Edit: add @private
.
* @type {number} | ||
* @constant | ||
*/ | ||
ClippingPlaneCollection.TEXTURE_WIDTH = CesiumMath.nextPowerOfTwo(Math.ceil(Math.sqrt(ClippingPlaneCollection.MAX_CLIPPING_PLANES * 2))); |
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.
We try to use 1D textures for the 3D Tiles batch table, so there is some precedent there. But it doesn't matter much in the end.
* @private | ||
*/ | ||
ClippingPlaneCollection.prototype.destroy = function() { |
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.
Round out the doc for this. For example:
/**
* Destroys the WebGL resources held by this object. Destroying an object allows for deterministic
* release of WebGL resources, instead of relying on the garbage collector to destroy this object.
* <br /><br />
* Once an object is destroyed, it should not be used; calling any function other than
* <code>isDestroyed</code> will result in a {@link DeveloperError} exception. Therefore,
* assign the return value (<code>undefined</code>) to the object as done in the example.
*
* @returns {undefined}
*
* @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
*
*
* @example
* clippingPlanes = clippingPlanes && clippingPlanes .destroy();
*
* @see ClippingPlaneCollection#isDestroyed
*/
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 remove @private
. See #5615 (comment)
ClippingPlaneCollection.prototype.checkDestroy = function(owner) { | ||
if (defined(this.owner) && owner !== this.owner) { | ||
return this; | ||
ClippingPlaneCollection.setOwnership = function(clippingPlaneCollection, newOwner, key) { |
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.
Place setOwnership
and isSupported
above the destroy functions, which are usually last.
Source/Scene/Model.js
Outdated
@@ -512,11 +512,15 @@ define([ | |||
this.colorBlendAmount = defaultValue(options.colorBlendAmount, 0.5); | |||
|
|||
/** | |||
* The {@link ClippingPlaneCollection} used to selectively disable rendering the model. Clipping planes are not currently supported in Internet Explorer. | |||
* The {ClippingPlaneCollection} used to selectively disable rendering the model. Clipping planes are not currently supported in Internet Explorer. |
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 any occurrences of Clipping planes are not currently supported in Internet Explorer.
Source/Scene/Model.js
Outdated
* | ||
* @type {ClippingPlaneCollection} | ||
*/ | ||
this.clippingPlanes = options.clippingPlanes; | ||
this._clippingPlanes = undefined; |
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.
Documentation is not needed for underscored variables.
Source/Scene/Model.js
Outdated
this._clippingPlanes = undefined; | ||
|
||
var clippingPlanes = options.clippingPlanes; | ||
ClippingPlaneCollection.setOwnership(clippingPlanes, this, '_clippingPlanes'); |
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.
Instead of these two lines, you could just call the setter directly.
this.clippingPlanes = options.clippingPlanes
Source/Scene/Model.js
Outdated
}, | ||
|
||
/** | ||
* The {ClippingPlaneCollection} used to selectively disable rendering the model. |
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.
{@link ClippingPlaneCollection}
Source/Scene/Model.js
Outdated
// Only destroy the ClippingPlaneCollection if this is the owner - if this model is part of a Cesium3DTileset, | ||
// _clippingPlanes references a ClippingPlaneCollection that this model does not own. | ||
var clippingPlaneCollection = this._clippingPlanes; | ||
if (defined(clippingPlaneCollection) && !clippingPlaneCollection.isDestroyed() && clippingPlaneCollection._owner === this) { |
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.
Perhaps add a getter for ClippingPlaneCollection.owner
so it doesn't have to access a private var.
@likangning93 I don't recall specifics but there is probably some precision loose, which may not matter in general, and certainty not for a fallback case when |
@@ -40,7 +40,7 @@ | |||
'use strict'; | |||
//Sandcastle_Begin | |||
// Use clipping planes to selectively hide parts of the globe surface. | |||
// Clipping planes are not currently supported in Internet Explorer. | |||
// |
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 trailing \\
.
CHANGES.md
Outdated
@@ -10,6 +10,8 @@ Change Log | |||
|
|||
##### Deprecated :hourglass_flowing_sand: | |||
* In the `Resource` class, `addQueryParameters` and `addTemplateValues` have been deprecated and will be removed in Cesium 1.45. Please use `setQueryParameters` and `setTemplateValues` instead. | |||
* `ClippingPlaneCollection` is now supported in Internet Explorer, so `ClippingPlaneCollection.isSupported` has been deprecated and will be removed in Cesium 1.43. |
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.
1.43
should now be 1.45
.
CHANGES.md
Outdated
@@ -19,6 +21,11 @@ Change Log | |||
* Added `put`, `patch`, `delete`, `options` and `head` methods, so it can be used for all XHR requests. | |||
* Added `preserveQueryParameters` parameter to `getDerivedResource`, to allow us to append query parameters instead of always replacing them. | |||
* Added `setQueryParameters` and `appendQueryParameters` to allow for better handling of query strings. | |||
* Enable terrain in the `CesiumViewer` demo application [#6198](https://github.com/AnalyticalGraphicsInc/cesium/pull/6198) |
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.
It looks like this was added accidentally.
Source/Core/Cartesian4.js
Outdated
* Unpacks a float packed using Cartesian4.packFloat. | ||
* | ||
* @param {Cartesian4} packedFloat A Cartesian4 containing a float packed to 4 values representable using uint8. | ||
*/ |
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.
Add the return variable to the doc.
Source/Core/ClippingPlane.js
Outdated
* @param {Function} onChangeCallback Callback to take the Plane's index on update. | ||
*/ | ||
function ClippingPlane(normal, distance, onChangeCallback) { | ||
|
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 whitespace.
Source/Scene/Model.js
Outdated
|
||
// If clipping planes/model color inactive: | ||
// - destroy _rendererResources.*programs | ||
// - relink _rendererResources.*programs to _cachedRendererResources |
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.
If a model has clipping planes and then a minute later has its color set, what happens to the clipping planes-only shader?
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.
Ah... I guess this should always be running destroyIfNotCached
@@ -4380,9 +4517,23 @@ define([ | |||
} | |||
|
|||
releaseCachedGltf(this); | |||
this._sourcePrograms = undefined; | |||
this._sourceShaders = undefined; |
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 set quantizedVertexShaders
to undefined
?
Source/Scene/Model.js
Outdated
var program = programs[id]; | ||
|
||
var clippingPlaneCollection = model.clippingPlanes; | ||
var addClippingPlaneCode = !firstBuild && needsClippingCode(model); |
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.
This needs a similar check for color.
Maybe irrelevant based on the comment above.
Source/Scene/getClippingFunction.js
Outdated
Check.typeOf.object('clippingPlaneCollection', clippingPlaneCollection); | ||
//>>includeEnd('debug'); | ||
var unionClippingRegions = clippingPlaneCollection.unionClippingRegions; | ||
var clippingPlaneCount = clippingPlaneCollection.length; |
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.
clippingPlaneCount
-> clippingPlanesLenth
|
||
if (!ClippingPlaneCollection.useFloatTexture(scene._context)) { | ||
// Don't fail just because float textures aren't supported | ||
return; |
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.
Make sure to delete the scene before returning. Fix throughout the file.
@lilleyse this is ready for another look |
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.
Getting close...
Source/Core/ClippingPlane.js
Outdated
defined, | ||
defineProperties, | ||
DeveloperError, | ||
Plane |
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.
DeveloperError
and Plane
aren't used.
Source/Core/ClippingPlane.js
Outdated
* A Plane in Hessian Normal form to be used with ClippingPlaneCollection. | ||
* Compatible with mathematics functions in Plane.js | ||
* | ||
* @constructor |
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.
Add @alias ClippingPlane
so this class shows up in the documentation.
Source/Core/ClippingPlane.js
Outdated
* @param {ClippingPlane} clippingPlane The ClippingPlane to be cloned | ||
* @param {ClippingPlane} [result] The object on which to store the cloned parameters. | ||
*/ | ||
ClippingPlane.clone = function(clippingPlane, result) { |
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.
Add @returns
.
return this._unionClippingRegions ? this._planes.length : -this._planes.length; | ||
}; | ||
|
||
function computeTextureResolution(pixelsNeeded, result) { |
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.
Move this function closer to the are that calls (above update
).
Source/Scene/Cesium3DTile.js
Outdated
if (currentClippingPlanesState !== this._clippingPlanesState) { | ||
this._clippingPlanesState = currentClippingPlanesState; | ||
this._content.clippingPlanesDirty = true; | ||
} |
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.
Maybe add the clipping planes code to a separate function updateClippingPlanes
? Just to help keep update
super simple. Though this._content.clippingPlanesDirty = false; // reset after content update
will have to stay here.
Source/Scene/Cesium3DTile.js
Outdated
if (currentClippingPlanesState !== this._clippingPlanesState) { | ||
this._clippingPlanesState = currentClippingPlanesState; | ||
this._content.clippingPlanesDirty = true; | ||
} |
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.
Maybe clippingPlanesDirty
should be a property of Cesium3DTile
instead. I think that will be cleaner overall.
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.
so very much cleaner
esp. looking at Composite3DTileContent
Source/Scene/Model.js
Outdated
@@ -511,12 +514,20 @@ define([ | |||
*/ | |||
this.colorBlendAmount = defaultValue(options.colorBlendAmount, 0.5); | |||
|
|||
this.colorShadingEnabled = isColorShadingEnabled(this); |
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.
Change to this._colorShadingEnabled
Source/Scene/Model.js
Outdated
*/ | ||
this.clippingPlanes = options.clippingPlanes; | ||
this.changedShadersOnLastUpdate = false; |
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.
This flag feels wrong to have. Could ModelInstanceCollection
instead look to see if model commands are dirty?
Source/Scene/Model.js
Outdated
@@ -1870,44 +1914,104 @@ define([ | |||
}; | |||
|
|||
CreateProgramJob.prototype.execute = function() { | |||
createProgram(this.id, this.model, this.context); | |||
createProgram(this.id, this.model, this.context, true); |
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.
createProgram
no longer takes the last argument.
28e5141
to
a05c225
Compare
@lilleyse updated! |
dab78e3
to
4e705de
Compare
' vec3 clipNormal = vec3(0.0);\n' + | ||
' vec3 clipPosition = vec3(0.0);\n' + | ||
' float clipAmount = 0.0;\n' + | ||
' float pixelWidth = czm_metersPerPixel(position);\n' + |
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.
@lilleyse dependence on this function causes edge styling to break in orthographic view.
Just setting it to a constant when we switch to orthographic seems fine, but that will need shader recompilation.
Separate PR later?
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.
Discussed offline, should be a quick fix.
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.
Nice fix!
@lilleyse ready! |
This looks ready to go to me. As a side note, the ability to regenerate model shaders now is pretty nice! |
@likangning93 open an issue to remove the deprecated things |
Here: #6317 |
*/ | ||
ClippingPlaneCollection.isSupported = function() { | ||
return !FeatureDetection.isInternetExplorer(); | ||
return true; |
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.
This should have a deprecationWarning
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.
@likangning93 did you add the deprecation warning here?
}; | ||
plane.index = newPlaneIndex; | ||
} else { | ||
this._containsUntrackablePlanes = true; |
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.
This should print a deprecationWarning
too
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.
more use cases for a "whoops" reaction for github...
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.
@likangning93 this looks pretty good and that you surely learned a lot about the rendering engine. I only have the bandwidth for this one review so please iterate with @lilleyse for any tweaks, and ping me if there is something that you two think you really need me for. Thanks!
var dir = new Cesium.Cartesian3(); | ||
dir.x = 1.0; | ||
dir.y = Math.tan(angle); | ||
if (angle > 1.57079632679) { |
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, avoid hardcoding values. There are PI
constants here: https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Core/Math.js#L321
@@ -0,0 +1,255 @@ | |||
<!DOCTYPE html> |
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'm not sure about this being in development
; I just spent awhile looking for it. At the least, there should be a simple example showing using a lot of clipping planes.
* @param {Cartesian4} [result] The Cartesian4 that will contain the packed float. | ||
* @returns {Cartesian4} A Cartesian4 representing the float packed to values in x, y, z, and w. | ||
*/ | ||
Cartesian4.packFloat = function(value, result) { |
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, add to CHANGES.md or mark these @private
.
'use strict'; | ||
|
||
/** | ||
* A Plane in Hessian Normal form to be used with ClippingPlaneCollection. |
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.
Use {@link ClippingPlaneCollection}
.
Check out the Documentation Guide if you need a refresher on best practices.
* in the direction of the normal; if negative, the origin is in the half-space | ||
* opposite to the normal; if zero, the plane passes through the origin. | ||
*/ | ||
function ClippingPlane(normal, distance) { |
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.
normal
and distance
are required, right? Shouldn't this throw an exception if they are not defined?
Potentially acceptable but borderline shady if this relies on UpdateChangedCartesian3
's constructor function to validation normal
.
'void main() \n' + | ||
'{ \n' + | ||
' gltf_clip_main(); \n' + | ||
' if (gltf_clippingPlanesLength > 0) \n' + | ||
' float clipDistance = clip(gl_FragCoord, gltf_clippingPlanes, gltf_clippingPlanesMatrix);' + |
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.
Is this specific to glTF or is there a reasonable way to encapsulate this so the same GLSL code/function is used for the globe shadre as well?
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.
We could re-use this in PointCloud3DTileContent
, but the logic is baked into GlobeFS.glsl
and enabled/disabled using injected defines.
I'll go ahead and move it out, it'll be handy in case at some point we want to make all things clippable.
'use strict'; | ||
|
||
/** | ||
* Gets the glsl functions needed to retrieve clipping planes from a ClippingPlaneCollection's texture. |
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.
"GLSL"
Here, below, and throughout.
*/ | ||
function getUnpackFloatFunction(functionName) { | ||
if (!defined(functionName)) { | ||
functionName = 'unpackFloat'; |
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.
Why does this ever need another name and why can't it just be a built-in czm_
GLSL function?
@@ -0,0 +1,168 @@ | |||
define([ |
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.
Does this belong in Renderer
or Scene
? Probably wherever the plane collection lives.
@@ -0,0 +1,8 @@ | |||
vec4 czm_transformPlane(mat4 transform, vec4 clippingPlane) { |
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 the parameter order be (plane, transform)? Whatever is consistent.
Also a disclaimer that I did not look at the tests. |
Storing the clipping planes in textures leads to a few caveats:
Texture
gl resource toClippingPlaneCollection
means it's no longer super practical toclone
it onto each model in a 3D Tileset backed by gltf, so now they share the tileset's reference to a singleClippingPlaneCollection
Texture
also meansClippingPlaneCollection
now has to be destroyed, but since aModel
may either have a reference to its ownClippingPlaneCollection
or aCesium3DTileset
'sClippingPlaneCollection
, thedestroy
function is a little weird and might need discussion.There's also a new Sandcastle that I used for debugging. Performance predictably isn't great with all 2048 planes and gets worse as you get closer to the model or use a 3D Tileset. But it works! Even my laptop with Atom Z3700 Series Intel Graphics will gamely throw up a frame or two every couple seconds.
Fixes #6184
Fixes #6048