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

User-defined clipping planes #5765

Closed
pjcozzi opened this issue Aug 22, 2017 · 16 comments
Closed

User-defined clipping planes #5765

pjcozzi opened this issue Aug 22, 2017 · 16 comments

Comments

@pjcozzi
Copy link
Contributor

pjcozzi commented Aug 22, 2017

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.

@kring
Copy link
Member

kring commented Aug 22, 2017

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

@pjcozzi
Copy link
Contributor Author

pjcozzi commented Aug 23, 2017

Contributions to core Cesium welcome. 😄

@kring
Copy link
Member

kring commented Aug 23, 2017

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?

@pjcozzi
Copy link
Contributor Author

pjcozzi commented Aug 23, 2017

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

@likangning93
Copy link
Contributor

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

!!!!

@ggetz
Copy link
Contributor

ggetz commented Oct 11, 2017

Initial Effort Roadmap

  • Modify shaders to support an array of up to 6 clipping planes
  • Add API for assigning clipping planes to:
    • Models
    • Tilesets (i3dm, b3dm, pnts)
  • Sandcastle Example
  • Write tests
  • Additional clipping planes

Later

  • Use clipping planes to speed up tileset traversal
    • 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
  • Support for terrain
  • Add new plane primitive
  • 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.
  • 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

@pjcozzi
Copy link
Contributor Author

pjcozzi commented Oct 12, 2017

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.

@lilleyse
Copy link
Contributor

clip-planes-master branch is ready.

@pjcozzi
Copy link
Contributor Author

pjcozzi commented Oct 13, 2017

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.

@pjcozzi
Copy link
Contributor Author

pjcozzi commented Oct 13, 2017

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

@nmschulte
Copy link
Contributor

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.

@ggetz
Copy link
Contributor

ggetz commented Jan 17, 2018

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.

@nmschulte
Copy link
Contributor

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

@ggetz
Copy link
Contributor

ggetz commented Jan 24, 2018

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.

@pjcozzi
Copy link
Contributor Author

pjcozzi commented Jun 17, 2018

OK to close this or is there more in #5765 (comment)?

Perhaps clipping cube/volume should be a separate issue?

@ggetz
Copy link
Contributor

ggetz commented Jun 18, 2018

Opened #6696 for clipping volume and closing.

@lilleyse I didn't see anything else concrete in #5765 (comment) to also open an issue for, let me know if you see anything else that should.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants