Cesium: User-defined clipping planes

Created on 23 Aug 2017  路  16Comments  路  Source: CesiumGS/cesium

For example, to reveal the interior of a CAD model in a 3D tileset.

Support up to 6 planes so a user can create a cube.

The classic implementation of this is a fragment shader with a 1D alpha texture (or maybe just discard).

Probably expose this for 3D tilesets and glTF models. We can add it to primitives, terrain, etc. if those cases come up.

category - graphics priority - high type - enhancement

Most helpful comment

I'm not sure what you mean by having the planes themselves be "shaded", if you could provide an image similar to what you mean that would be helpful.

After playing with this some more I can clarify now. I'm focusing on clipping the globe, for subterranean concepts, but the idea should generalize. What I had in mind is this: --
Where the clipping planes intersect the geometry/mesh, shade the intersection face(s). E.g. when clipping the globe to slice it in half, allow to shade (with a full blown material/shader, or a simpler interface like ARGB color) the resulting ellipse of the intersection.

Bigger picture: I want to provide a better back-drop for entities/primitives/meshes placed inside the clipped region of the globe. If this was done with actual geometry/mesh, this could improve the current default camera behavior too (as it is, it seems one can "pick" a point "inside" the globe as the camera manipulation ref. pt., see the attached animations).

I also want to show the original clipped surface with a different shading (material/shader), much like this "other idea":

Implement as a material? This would allow modifying the color of the clipped area or just do regular discard.

More than six planes may be handy for more complex geometry carving; the ability to specify an arbitrary geometry would be amazing, but that might be out of scope given the tech in focus here.

Last, if it matters, the ability to clip entities/primitives would be neat. I don't have a concrete grasp on the technical limitations though; I haven't yet dug into how this is implemented.


clip_cam

All 16 comments

I recently added cross-section support to a glTF model for a proof-of-concept for a customer. It can be done external to Cesium using some existing (but undocumented) hooks. Simple but effective:
https://github.com/TerriaJS/terriajs/blob/underground-poc/lib/Models/GltfCatalogItem.js#L259

Contributions to core Cesium welcome. 馃槃

Haha, well, I wasn't really sure we'd want it in core Cesium. At least, building stuff like this into the Model class seemed questionable. It's already huge! Maybe more like a plugin (or at least separate class) that bolts this feature on the way the code above does?

I suspect this will be a property (or array of clip planes) applied to a model or tileset that then modifies the shaders.

The implementation can probably be added pretty cleanly and be in mostly a separate file so we can add it elsewhere if/when needed.

Also, if there are other terria features that you are not sure if Cesium would want, please send me a list. 馃榾

Support up to 6 planes so a user can create a cube.

!!!!

Initial Effort Roadmap

  • [x] Modify shaders to support an array of up to 6 clipping planes
  • [x] Add API for assigning clipping planes to:

    • [x] Models

    • [x] Tilesets (i3dm, b3dm, pnts)

  • [x] Sandcastle Example
  • [x] Write tests
  • [x] Additional clipping planes

Later

  • [x] Use clipping planes to speed up tileset traversal

    • [x] Only apply clipping shader code to those tiles that intersect with a clipping plane

    • [ ] Bounding volume around convex clipping

  • [ ] Work in 2D and CV
  • [ ] Support vector tiles
  • [x] Support for terrain

    • [x] Sandcastle showing subsurface visualization (CC #5665)

  • [x] Add new plane primitive
  • [x] Ability to modify a clipping plane's reference frame
  • [ ] Modify model class to allow full shader recompiling
  • [ ] Add clipping to styling language
  • [ ] Still need to determine whether stencil clipping is doable.

    • [ ] May require a shadow-volume like approach in complicated cases.

  • [x] Blog post, with focus on the CPU culling optimization

Other ideas

  • [ ] Clipping cube concept? Easier to build than 6 clipping planes. Is there a fast path for this?
  • [ ] Implement as a material? This would allow modifying the color of the clipped area or just do regular discard.

CC @lilleyse

Thanks for putting this together!

@lilleyse could you create a branch clip-planes-master so that @ggetz can open incrementally pull requests into it?

Still need to determine whether stencil clipping is doable.

May also need to lay down z first, but that may not be worth it.

Use clipping planes to speed up tileset traversal

Also generate optimized shaders - only tiles/draw-commands with bounding volumes intersecting any clipping plane need to do the check.

Ability to modify a clipping plane's reference frame?

Move this from Other ideas to Later. We should certainty do this - just like a Primitive's model matrix can change.

clip-planes-master branch is ready.

Also, please add a blog post to the roadmap - the culling optimization is interesting and I don't think there is a ton of information in general on implementing clipping planes.

@lilleyse for the CPU culling optimization, please show @ggetz how to check/spy draw calls for the unit tests.

FYI: while CV and 2D support is coming, enabling clipping planes on the Globe while in CV has effect, and it's not what's desired.

2018_01_17-10_53_36-1143x663
2018_01_17-10_52_36-1145x662

When clipping the globe, it would be nice if the clipped area could be filled with a color (with alpha, or a whole material) to act as a backdrop. For example, in the sandcastle showcase this would mean the Cesium Man is rendered atop a solid color (e.g. black) hole rather than the stars/skybox/(fog/horizon). Otherwise, if the planes themselves could be "shaded" and clipped to the terrain/geometry, that would be ideal.

Thanks for the 2D/Columbus report @nmschulte.

For the backdrop, you can hide the skyBox and set the scene backgroundColor to achieve that effect.

I'm not sure what you mean by having the planes themselves be "shaded", if you could provide an image similar to what you mean that would be helpful.

I'm not sure what you mean by having the planes themselves be "shaded", if you could provide an image similar to what you mean that would be helpful.

After playing with this some more I can clarify now. I'm focusing on clipping the globe, for subterranean concepts, but the idea should generalize. What I had in mind is this: --
Where the clipping planes intersect the geometry/mesh, shade the intersection face(s). E.g. when clipping the globe to slice it in half, allow to shade (with a full blown material/shader, or a simpler interface like ARGB color) the resulting ellipse of the intersection.

Bigger picture: I want to provide a better back-drop for entities/primitives/meshes placed inside the clipped region of the globe. If this was done with actual geometry/mesh, this could improve the current default camera behavior too (as it is, it seems one can "pick" a point "inside" the globe as the camera manipulation ref. pt., see the attached animations).

I also want to show the original clipped surface with a different shading (material/shader), much like this "other idea":

Implement as a material? This would allow modifying the color of the clipped area or just do regular discard.

More than six planes may be handy for more complex geometry carving; the ability to specify an arbitrary geometry would be amazing, but that might be out of scope given the tech in focus here.

Last, if it matters, the ability to clip entities/primitives would be neat. I don't have a concrete grasp on the technical limitations though; I haven't yet dug into how this is implemented.


clip_cam

Thanks for the clarifications @nmschulte and the use cases!

Where the clipping planes intersect the geometry/mesh, shade the intersection face(s).
I also want to show the original clipped surface with a different shading (material/shader).

In the current implementation, we color the edge of the mesh that is being clipping with edgeColor and edgeWidth, but more in depth display and styling would go a long way indeed.

More than six planes may be handy for more complex geometry carving; the ability to specify an arbitrary geometry would be amazing, but that might be out of scope given the tech in focus here.

We've done a little with clipping volumes, specifically cubes, that we hope to bring to production soon.

Last, if it matters, the ability to clip entities/primitives would be neat.

Currently, you can clip model entities, and as far as I'm aware, it could be added it to other entities by adding the clipping shader modifications and hook for the other primitives.

OK to close this or is there more in https://github.com/AnalyticalGraphicsInc/cesium/issues/5765#issuecomment-335950848?

Perhaps clipping cube/volume should be a separate issue?

Opened #6696 for clipping volume and closing.

@lilleyse I didn't see anything else concrete in https://github.com/AnalyticalGraphicsInc/cesium/issues/5765#issuecomment-335950848 to also open an issue for, let me know if you see anything else that should.

Was this page helpful?
0 / 5 - 0 ratings