-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add texture filtering options #1894
Conversation
a12a656
to
c6d514b
Compare
I discovered this after inadvertently implementing a similar thing (though as global options for the renderer, not per- I think there may be a bug in this PR, though. In my app I animate images by creating a new handle every tick like this (and AFAIK this how it must be done, let me know if there's a better way):
and initialize like:
and update the image on a tick like:
and draw the view and image like so:
This has two issues on this branch currently when using the
I suspect the new HashMap is getting confused because (say) the GPU-driver-provided handle for the new image is reused and confusing the identity used by the map...? Though it doesn't explain why the image content changes. Neither issue occurs in the |
Thanks for checking this. The cause for the image not updating is probably because I did not include the filter settings in the hash of the image thus the change detection misses that. I'll fix that. For the memory leak I need to look into it. I might need to update some things here anyway to include new changes from main. |
Ok after looking into it I found that there are some problems in the wgpu part that I need to fix. (Should have tested this better, again thanks for doing so). The issue is not with the change detection but with the layers.
I will attempt to do this properly and then we'll see. |
I tried to fix the mentioned issues. The size of a layer growths to four times its size (roughly on my machine: 350B ->1400B). This is unfortunate but the only alternative I can think of is to use an |
This works fine for me in practice, thanks! |
- Support only `Linear` or `Nearest` - Simplify `Layer` groups - Move `FilterMethod` to `Image` and `image::Viewer`
710fd48
to
a5125d6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks 🥳
I have refactored and simplified the code a bit in a5125d6. Specifically:
- I have removed support for different minification and magnification filter methods. Normally, the strategy used for both is the same.
- I simplified the layer groups. Instead of creating a new
Layer
per sampler, we can just add an additional sampler and its instances to theLayer
. Theuniforms
can be reused. - I moved the
FilterMethod
from theHandle
to theImage
andimage::Viewer
widgets. This way, the method can be changed easily without recreating theHandle
.
I have also added a simple checkbox to the "Image" step in the tour
example to enable nearest interpolation.
A nice side-effect of these changes is that now we can use nearest interpolation for SVG, which should fix blurriness when using the Svg
widget in some cases! 🎉
Let me know what you think and I believe we can merge this.
Thanks for the refactoring/overhaul. Looks and works great. Good that you could clean up the layer stuff a bit. I was not very happy with the previous state but lacked an idea to make it better. |
Eep, this was exactly the use case I came to this PR for, though. I'm working on a project (related to pixel art) where I want minification to be "smooth" and magnification to be chunky. Is it possible to restore this? |
It would be possible of course. Its just not that nice with the 4 samplers. Is linear min-sampling even desirable for pixel-art? When I hardcode min-filter to linear it again started to look all blurry when scaled down. (Which I though one tries to avoid here) |
Well, I'm speaking mainly of use cases like shrinking down to the range of e.g. 1/2 or 1/4 the size -- I want to see "all" the pixels accounted for. A nearest filter (as used for magnification) would cause most of the pixels to disappear. I suppose, without making such a change, I could change the (single) filter dynamically based on the apparent scaling. |
That sounds like a valid strategy, and you will have more control that way. Let's merge then! |
Adds the possibility to add Texture filtering options to an image handle (should work with tiny_skia and wgpu) (Original Issue: #557 )
This is necessary when rendering smaller Pixelart or when trying to implement pixelbased image manipulation (As I am currently trying).
I asked on Discord and since nobody seemed to work at it I gave it a try.
I know it adds a little complexity to the rendering of images and imposes a rendering order of images with different filter options (Even though only inside a layer?) so if you think the feature is not interesting enough to justify these drawbacks its fine.
Just wanted to provide it. If its not completely unfitting I'd be happy to take feedback, since I am not very experienced with the graphics part.
Fixes #557.