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

Increase max clipping planes using textures #6201

Merged
merged 38 commits into from
Mar 9, 2018

Conversation

likangning93
Copy link
Contributor

@likangning93 likangning93 commented Feb 9, 2018

Storing the clipping planes in textures leads to a few caveats:

  • precision problems with compression to RGBA means plane transformations happen in the shader now instead of on the CPU side
    • so it's a bit more shader math
    • but nice benefit is that the texture doesn't get updated as the view changes - yay!
  • attaching a Texture gl resource to ClippingPlaneCollection means it's no longer super practical to clone it onto each model in a 3D Tileset backed by gltf, so now they share the tileset's reference to a single ClippingPlaneCollection
  • Texture also means ClippingPlaneCollection now has to be destroyed, but since a Model may either have a reference to its own ClippingPlaneCollection or a Cesium3DTileset's ClippingPlaneCollection, the destroy 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

@cesium-concierge
Copy link

Signed CLA is on file.

@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.

🌍 🌎 🌏

@mramato
Copy link
Contributor

mramato commented Feb 9, 2018

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.

This doesn't sound like something we should ship to end users. We have a development directory in Sandcastle gallery for this kind of stuff, I would recommend moving it there.

@pjcozzi
Copy link
Contributor

pjcozzi commented Feb 9, 2018

Please bump to me for a final review when ready. In the meantime, one comment:

precision problems with compression to RGBA means plane transformations happen in the shader now instead of on the CPU side

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.

@likangning93
Copy link
Contributor Author

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.

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 gl call to update the texture due to view changes.

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.

@pjcozzi
Copy link
Contributor

pjcozzi commented Feb 9, 2018

@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.

@pjcozzi
Copy link
Contributor

pjcozzi commented Feb 10, 2018


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

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

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

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?

Copy link
Contributor Author

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();
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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 : {
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.

@@ -1272,26 +1287,13 @@ define([

var context = frameState.context;

this._defaultTexture = context.defaultTexture;
Copy link
Contributor

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)));
Copy link
Contributor

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.

Copy link
Contributor Author

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...

Copy link
Contributor

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.

new Plane(Cartesian3.UNIT_X, 0.0)
]
});
model.clippingPlanes = clippingPlanes;
Copy link
Contributor

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);
});
Copy link
Contributor

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?

Copy link
Contributor Author

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

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.

Copy link
Contributor Author

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!

Copy link
Contributor

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.

@mramato
Copy link
Contributor

mramato commented Feb 14, 2018

Sorry if this was already discussed, but ClippingPlaneCollection.isSupported should be deprecated instead of removed without warning. (Just have the deprecated version return true).

@likangning93
Copy link
Contributor Author

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

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

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);
});
Copy link
Contributor

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)));
Copy link
Contributor

@lilleyse lilleyse Feb 15, 2018

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)));
Copy link
Contributor

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() {
Copy link
Contributor

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
     */

Copy link
Contributor

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) {
Copy link
Contributor

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.

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

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.

*
* @type {ClippingPlaneCollection}
*/
this.clippingPlanes = options.clippingPlanes;
this._clippingPlanes = undefined;
Copy link
Contributor

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.

this._clippingPlanes = undefined;

var clippingPlanes = options.clippingPlanes;
ClippingPlaneCollection.setOwnership(clippingPlanes, this, '_clippingPlanes');
Copy link
Contributor

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

},

/**
* The {ClippingPlaneCollection} used to selectively disable rendering the model.
Copy link
Contributor

Choose a reason for hiding this comment

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

{@link ClippingPlaneCollection}

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

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.

@pjcozzi
Copy link
Contributor

pjcozzi commented Feb 28, 2018

@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 FLOAT is not supported.

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

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

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

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.

* Unpacks a float packed using Cartesian4.packFloat.
*
* @param {Cartesian4} packedFloat A Cartesian4 containing a float packed to 4 values representable using uint8.
*/
Copy link
Contributor

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.

* @param {Function} onChangeCallback Callback to take the Plane's index on update.
*/
function ClippingPlane(normal, distance, onChangeCallback) {

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove whitespace.


// If clipping planes/model color inactive:
// - destroy _rendererResources.*programs
// - relink _rendererResources.*programs to _cachedRendererResources
Copy link
Contributor

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?

Copy link
Contributor Author

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

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?

var program = programs[id];

var clippingPlaneCollection = model.clippingPlanes;
var addClippingPlaneCode = !firstBuild && needsClippingCode(model);
Copy link
Contributor

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.

Check.typeOf.object('clippingPlaneCollection', clippingPlaneCollection);
//>>includeEnd('debug');
var unionClippingRegions = clippingPlaneCollection.unionClippingRegions;
var clippingPlaneCount = clippingPlaneCollection.length;
Copy link
Contributor

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

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.

@likangning93
Copy link
Contributor Author

@lilleyse this is ready for another look

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.

Getting close...

defined,
defineProperties,
DeveloperError,
Plane
Copy link
Contributor

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.

* A Plane in Hessian Normal form to be used with ClippingPlaneCollection.
* Compatible with mathematics functions in Plane.js
*
* @constructor
Copy link
Contributor

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.

* @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) {
Copy link
Contributor

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) {
Copy link
Contributor

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).

if (currentClippingPlanesState !== this._clippingPlanesState) {
this._clippingPlanesState = currentClippingPlanesState;
this._content.clippingPlanesDirty = true;
}
Copy link
Contributor

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.

if (currentClippingPlanesState !== this._clippingPlanesState) {
this._clippingPlanesState = currentClippingPlanesState;
this._content.clippingPlanesDirty = true;
}
Copy link
Contributor

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.

Copy link
Contributor Author

@likangning93 likangning93 Mar 8, 2018

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

@@ -511,12 +514,20 @@ define([
*/
this.colorBlendAmount = defaultValue(options.colorBlendAmount, 0.5);

this.colorShadingEnabled = isColorShadingEnabled(this);
Copy link
Contributor

Choose a reason for hiding this comment

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

Change to this._colorShadingEnabled

*/
this.clippingPlanes = options.clippingPlanes;
this.changedShadersOnLastUpdate = false;
Copy link
Contributor

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?

@@ -1870,44 +1914,104 @@ define([
};

CreateProgramJob.prototype.execute = function() {
createProgram(this.id, this.model, this.context);
createProgram(this.id, this.model, this.context, true);
Copy link
Contributor

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.

@likangning93
Copy link
Contributor Author

@lilleyse updated!

' vec3 clipNormal = vec3(0.0);\n' +
' vec3 clipPosition = vec3(0.0);\n' +
' float clipAmount = 0.0;\n' +
' float pixelWidth = czm_metersPerPixel(position);\n' +
Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice fix!

@likangning93
Copy link
Contributor Author

@lilleyse ready!

@lilleyse
Copy link
Contributor

lilleyse commented Mar 9, 2018

This looks ready to go to me.

As a side note, the ability to regenerate model shaders now is pretty nice!

@lilleyse lilleyse merged commit 6d55f29 into CesiumGS:master Mar 9, 2018
@lilleyse lilleyse deleted the clippingPlanesByTexture branch March 9, 2018 20:29
@hpinkos
Copy link
Contributor

hpinkos commented Mar 9, 2018

@likangning93 open an issue to remove the deprecated things

@likangning93
Copy link
Contributor Author

Here: #6317

*/
ClippingPlaneCollection.isSupported = function() {
return !FeatureDetection.isInternetExplorer();
return true;
Copy link
Contributor

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

Copy link
Contributor

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

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

Copy link
Contributor Author

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...

Copy link
Contributor

@pjcozzi pjcozzi left a 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) {
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, 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>
Copy link
Contributor

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) {
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, add to CHANGES.md or mark these @private.

'use strict';

/**
* A Plane in Hessian Normal form to be used with ClippingPlaneCollection.
Copy link
Contributor

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) {
Copy link
Contributor

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);' +
Copy link
Contributor

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?

Copy link
Contributor Author

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

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';
Copy link
Contributor

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([
Copy link
Contributor

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) {
Copy link
Contributor

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.

@pjcozzi
Copy link
Contributor

pjcozzi commented Mar 11, 2018

Also a disclaimer that I did not look at the tests.

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.

Model pick shaders do not use clipping planes Clipping planes broken in IE
7 participants