UI CPU clipping implementation supporting rotation and scaling - #24148
UI CPU clipping implementation supporting rotation and scaling#24148ickshonpe wants to merge 47 commits into
Conversation
`CalculatedClip` is now an enum with `Rects` and `FullyClipped` variants. `Rects` holds a list of `Rect` in node local coords and `Affine2` world-to-local transform. `bevy_ui_render` has a new `clipping` module with a `clip_polygon` function that intersects UI elements with the clipping rects and chops off the non-visible regions and returns a list of vertices that forms a triangle fan. New example `overflow_transform`.
| @@ -0,0 +1,132 @@ | |||
| //! Demonstrates nested transformed UI clipping. | |||
There was a problem hiding this comment.
I think this probably belongs in testbed. It's a great test, but not very educational.
There was a problem hiding this comment.
Yeah maybe, I might expand it further though.
There was a problem hiding this comment.
kk! It's also fancy enough that I don't mind it being in the main examples.
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
…into overflow-transform
|
It looks like your PR has been selected for a highlight in the next release blog post, but you didn't provide a release note. Please review the instructions for writing release notes, then expand or revise the content in the release notes directory to showcase your changes. |
|
There are some changes for retained UI updates I'm working on atm, but I'll try and get back to this start of next week so it can get merged. |
|
@alice-i-cecile should be ready now. |
Objective
Support
Overflowclipping for transformed nodes.Fixes #17630, #21775, #25126
(and probably quite a few others)
Solution
CalculatedClipis now an enum withRectsandFullyClippedvariants.Rectsholds a list ofRectin node local coords andAffine2world-to-local transform.bevy_ui_renderhas a newclippingmodule with aclip_polygonfunction that intersects UI elements with the clipping rects and chops off the non-visible regions and returns a list of vertices that forms a triangle fan. Uses a simplified version of the Sutherland–Hodgman algorithm.Performance isn't too bad, but text suffers a bit when clipped as there's no broad phase atm, instead it tests and breaks up each glyph individually. The clipping geometry also needs to be cached somewhere and updated incrementally.
I didn't try to optimise this branch too much yet as I suspect the required changes would probably end up being much larger and more complicated than the clipping implementation itself, and it might better to leave them for follow up PRs.
Currently this only supports rectangular clipping regions but it can easily be expanded to support any covex shapes.
--
Ideally we'd do clipping on the GPU which would allow for arbitrary clipping geometry and better performance. That would need a complete rewrite of the UI renderer and might have compatibility issues. I think this is good enough as an improving step, it works reliably and the code is also simpler and easier to understand, in particular UV interpolation is much simpler now.
Testing
Showcase