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

Dithering in Fragment Shader #4493

Open
jwagner opened this issue May 13, 2024 · 1 comment · May be fixed by #4497
Open

Dithering in Fragment Shader #4493

jwagner opened this issue May 13, 2024 · 1 comment · May be fixed by #4497

Comments

@jwagner
Copy link

jwagner commented May 13, 2024

Is your feature request related to a problem? Please describe.
Egui currently doesn't apply any dithering to it's output. That's hardly an issue with the flat default look and feel. However, when drawing gradients or images (which have been resampled) banding becomes a problem.

Describe the solution you'd like
I think ideally egui would perform dithering in the fragment shader. Given the trivial nature of the shader performing a few more operations on the ALU for some simple dithering should not have a relevant impact on rendering performance. The one exception is potentially when software rasterization.

Describe alternatives you've considered
I'm currently just drawing a noisy texture on top of gradients to mask the problem but it requires a lot more noise to be added to the gradient to make it look smooth (ironically) than doing it in a fragment shader.

I think there is also an argument that this is out of scope for egui. Other than shadows most widgets seem to use solid colors. For the shadows the fall off is quick enough that dithering isn't necessary. Even when rendering images this is likely going to be an edge case and only an issue when rendering images with smooth gradients that either aren't dithered or have been resampled to the extent that the dithering in the image is ineffective.

Additional context
I'd be happy to create a PR if dithering is considered to be in scope for egui.

@emilk
Copy link
Owner

emilk commented May 14, 2024

I think this could be a nice improvement, and would reduce banding for e.g. the color picker.

We could use the same approach as in https://github.com/rerun-io/rerun/blob/55cf671d8c578648c9354a552d21f185a8eee688/crates/re_renderer/shader/generic_skybox.wgsl#L29-L65

We should make sure to mention in a comment that this is an optional improvement, and that someone writing their own egui renderer don't need to copy if they don't want to.

@jwagner jwagner linked a pull request May 14, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants