new UI clipping implementation#24148
Open
ickshonpe wants to merge 24 commits intobevyengine:mainfrom
Open
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. | |||
Member
There was a problem hiding this comment.
I think this probably belongs in testbed. It's a great test, but not very educational.
Contributor
Author
There was a problem hiding this comment.
Yeah maybe, I might expand it further though.
Member
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
Contributor
|
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. |
mnmaita
reviewed
May 6, 2026
…into overflow-transform
…into overflow-transform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Get clipping working with transformed nodes.
Fixes #17630
Fixes #21775
(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.
Testing
Showcase