Skip to content

Improve texture filtering by doing it in gamma space#7311

Merged
emilk merged 8 commits intomainfrom
emilk/interpolate-textures-in-gamma-space
Jul 7, 2025
Merged

Improve texture filtering by doing it in gamma space#7311
emilk merged 8 commits intomainfrom
emilk/interpolate-textures-in-gamma-space

Conversation

@emilk
Copy link
Owner

@emilk emilk commented Jul 7, 2025

This makes some transparent images look a lot nicer when blended:

image

Cursive text will also look nicer.

This unfortunately changes the contract of what register_native_texture expects

@emilk emilk requested a review from Wumpf as a code owner July 7, 2025 12:42
@emilk emilk added egui_glow Relates to running egui_glow on native visuals Renderings / graphics releated egui-wgpu egui labels Jul 7, 2025
@github-actions
Copy link

github-actions bot commented Jul 7, 2025

Preview available at https://egui-pr-preview.github.io/pr/7311-emilkinterpolate-textures-in-gamma-space
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

@emilk emilk changed the title Interpolate textures in gamma space Improve texture filtering by doing it in gamma space Jul 7, 2025
@emilk emilk added this to the egui 0.32.0 milestone Jul 7, 2025
Copy link
Collaborator

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"academically" this still pains me that this is necessary but it's perfectly in line with what was discussed before and the improved results speak for themselves! 👍

When updating Rerun, we should check whether its map view is still looking as before - we are blending re_renderer rendered stuff on top of egui (the map itself) there and I'm not sure if this affects that or not.

/// This enables the application to reference the texture inside an image ui element.
/// This effectively enables off-screen rendering inside the egui UI. Texture must have
/// the texture format [`wgpu::TextureFormat::Rgba8UnormSrgb`].
/// the texture format [`wgpu::TextureFormat::Rgba8Unorm`].
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh I guess there's a future work item here that iff Rgba8UnormSrgb is passed in, we create an Rgba8Unorm view either way (telling the user that we do that)
If I remember correctly WebGPU standard now guarantees this working on the minspec.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you even know what format the given texture has?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that's exposed by now. Wasn't back when the code was written!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. right we should check that now that we can

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. this is a TextureView not a texture, but it's supposed to expose these things https://www.w3.org/TR/webgpu/#gputextureview
But alas wgpu doesn't do that yet. Tomorrow is a wgpu release and I want this badly, let's whip that up quickly..

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emilk emilk merged commit f46926a into main Jul 7, 2025
46 of 47 checks passed
@emilk emilk deleted the emilk/interpolate-textures-in-gamma-space branch July 7, 2025 15:46
@emilk emilk mentioned this pull request Jul 7, 2025
emilk added a commit to rerun-io/rerun that referenced this pull request Jul 7, 2025
### Related
* Includes emilk/egui#7311

### What
The image differences are rather minor, except _cursive_ text looks
slightly better now.

Also, the Rerun logo looks a bit nicer

Before/After:
![Screenshot 2025-07-07 at 18 21
51](https://github.com/user-attachments/assets/4e6fc643-0b3b-4759-9747-97779e236abe)
![Screenshot 2025-07-07 at 18 22
04](https://github.com/user-attachments/assets/86447453-260c-4182-8945-7fbd745b2d93)

### Map view
@Wumpf was worried about the map view looking different, but it looks
fine to me (eye-balling it)
MichaelGrupp added a commit to MichaelGrupp/maps that referenced this pull request Jul 25, 2025
Without any conversion, an old saved value appears as a completely
different color because it's assumed to be a gamma-premultiplied
value (which it wasn't when serialized with egui < 0.32).
This then lead e.g. the color picker to do wrong conversions and
mess up the tint color.

We now check if the session was written with the latest or an old
version and fix the misinterpreted color values if needed.

Note that while the values are correct after conversion, the image
can still appear darker due to the blending changes in egui.

Relates to: emilk/egui#5824
Relates to: emilk/egui#7311
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

egui_glow Relates to running egui_glow on native egui egui-wgpu visuals Renderings / graphics releated

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants