Better inset border SDF
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## What problem does this solve or what need does it fill?
Currently `sd_inset_rounded_box` in [ui.wesl](https://github.com/bevyengine/bevy/blob/7b2b90997ae2e73558ace09cc065d31a2c24b266/crates/bevy_ui_render/src/ui.wesl) positions center of inset box at an offset to center of outside box. This can cause incorrect behavior in some edge cases:
Note: this screenshot was made with bevy 0.19
## What solution would you like?
Using sdf of an outset box it is possible to have two different radii meet:
The solution is implemented in shadertoy:
[Border using an "outset" inset box](https://www.shadertoy.com/view/Ncy3Dy)
## What alternative(s) have you considered?
Cannot think of other solution as of now
## Additional context
Problem exists since sdf of a rounded box is calculated in the same quadrant because `sd_rounded_box` takes an absolute position of a point. This does not allow different radii to meet at the center. If we treat each side as different distance from center, this does not happen.
Contributor guide
Research direction
Start in crates/bevy_ui_render/src/ui.wesl at sd_inset_rounded_box, then compare its distance calculation with the linked Shadertoy implementation. Verify the change handles different radii meeting at the center and produces the expected upper-right corner behavior shown in the screenshots.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100