Skip to content

Conversation

@ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Oct 30, 2024

Objective

UI Anti-aliasing is incorrectly implemented. It always uses an edge radius of 0.25 logical pixels, and ignores the physical resolution. For low dpi screens 0.25 is is too low and on higher dpi screens the physical edge radius is much too large, resulting in visual artifacts.

Solution

Multiply the distance by the scale factor in the antialias function so that the edge radius stays constant in physical pixels.

Testing

To see the problem really clearly run the button example with UiScale set really high. With UiScale(25.) on main if you examine the button's border you can see a thick gradient fading away from the edges:

edgg

With this PR the edges are sharp and smooth at all scale factors:

edge

@ickshonpe ickshonpe closed this Oct 30, 2024
@ickshonpe ickshonpe reopened this Oct 30, 2024
@ickshonpe ickshonpe marked this pull request as draft October 30, 2024 23:52
@ickshonpe ickshonpe added A-UI Graphical user interfaces, styles, layouts, and widgets A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior labels Oct 30, 2024
@alice-i-cecile alice-i-cecile added this to the 0.15 milestone Oct 31, 2024
@alice-i-cecile alice-i-cecile added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Nov 12, 2024
@mockersf
Copy link
Member

@ickshonpe is this ready or is it still a draft?

@ickshonpe ickshonpe marked this pull request as ready for review November 13, 2024 04:10
@BenjaminBrienen BenjaminBrienen added the D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes label Nov 13, 2024
@ickshonpe
Copy link
Contributor Author

ickshonpe commented Nov 13, 2024

@ickshonpe is this ready or is it still a draft?

Ready for review now, though the implementation sucks so much as it passes in the inverse scale factor with every vertex 😓. That could be removed later by switching to physical coordinates internally in a follow up.

I've got some before and after test examples but I need to go to sleep, I'll put them up when I wake up.

@mockersf mockersf added this pull request to the merge queue Nov 13, 2024
Merged via the queue into bevyengine:main with commit aab36f3 Nov 13, 2024
29 checks passed
mockersf pushed a commit that referenced this pull request Nov 16, 2024
UI Anti-aliasing is incorrectly implemented. It always uses an edge
radius of 0.25 logical pixels, and ignores the physical resolution. For
low dpi screens 0.25 is is too low and on higher dpi screens the
physical edge radius is much too large, resulting in visual artifacts.

Multiply the distance by the scale factor in the `antialias` function so
that the edge radius stays constant in physical pixels.

To see the problem really clearly run the button example with `UiScale`
set really high. With `UiScale(25.)` on main if you examine the button's
border you can see a thick gradient fading away from the edges:

<img width="127" alt="edgg"
src="https://github.com/user-attachments/assets/7c852030-c0e8-4aef-8d3e-768cb2464cab">

With this PR the edges are sharp and smooth at all scale factors:

<img width="127" alt="edge"
src="https://github.com/user-attachments/assets/b3231140-1bbc-4a4f-a1d3-dde21f287988">
ecoskey pushed a commit to ecoskey/bevy that referenced this pull request Dec 2, 2024
# Objective

UI Anti-aliasing is incorrectly implemented. It always uses an edge
radius of 0.25 logical pixels, and ignores the physical resolution. For
low dpi screens 0.25 is is too low and on higher dpi screens the
physical edge radius is much too large, resulting in visual artifacts.

## Solution

Multiply the distance by the scale factor in the `antialias` function so
that the edge radius stays constant in physical pixels.

## Testing

To see the problem really clearly run the button example with `UiScale`
set really high. With `UiScale(25.)` on main if you examine the button's
border you can see a thick gradient fading away from the edges:

<img width="127" alt="edgg"
src="https://github.com/user-attachments/assets/7c852030-c0e8-4aef-8d3e-768cb2464cab">

With this PR the edges are sharp and smooth at all scale factors: 

<img width="127" alt="edge"
src="https://github.com/user-attachments/assets/b3231140-1bbc-4a4f-a1d3-dde21f287988">
ecoskey pushed a commit to ecoskey/bevy that referenced this pull request Jan 6, 2025
# Objective

UI Anti-aliasing is incorrectly implemented. It always uses an edge
radius of 0.25 logical pixels, and ignores the physical resolution. For
low dpi screens 0.25 is is too low and on higher dpi screens the
physical edge radius is much too large, resulting in visual artifacts.

## Solution

Multiply the distance by the scale factor in the `antialias` function so
that the edge radius stays constant in physical pixels.

## Testing

To see the problem really clearly run the button example with `UiScale`
set really high. With `UiScale(25.)` on main if you examine the button's
border you can see a thick gradient fading away from the edges:

<img width="127" alt="edgg"
src="https://github.com/user-attachments/assets/7c852030-c0e8-4aef-8d3e-768cb2464cab">

With this PR the edges are sharp and smooth at all scale factors: 

<img width="127" alt="edge"
src="https://github.com/user-attachments/assets/b3231140-1bbc-4a4f-a1d3-dde21f287988">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants