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

Disable bilinear filtering for Image #557

Closed
ThisIsRex opened this issue Oct 8, 2020 · 8 comments · Fixed by #1894
Closed

Disable bilinear filtering for Image #557

ThisIsRex opened this issue Oct 8, 2020 · 8 comments · Fixed by #1894
Labels
feature New feature or request image question Further information is requested rendering

Comments

@ThisIsRex
Copy link
Contributor

I want to display a small image or a pixel art so I don't need an antialiasing. How to disable it for specific widget?
Image::new(image::Handle::from_pixels(3, 3, img_data)) .width(Length::Units(100)) .height(Length::Units(100))

@twitchyliquid64
Copy link

Images (on desktop) aren't processed in any way - they are rastered to a texture, uploaded to the GPU, and drawn.

If your input image is 3 pixels in size, but you are rendering it in a 100x100 pixel area, you are probably running into texture sampling. Our image pipline has these settings:

let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
            address_mode_u: wgpu::AddressMode::ClampToEdge,
            address_mode_v: wgpu::AddressMode::ClampToEdge,
            address_mode_w: wgpu::AddressMode::ClampToEdge,
            mag_filter: wgpu::FilterMode::Linear,
            min_filter: wgpu::FilterMode::Linear,
            mipmap_filter: wgpu::FilterMode::Linear,
            ..Default::default()
        });

LINEAR indicates that adjacent pixels are linearly interpolated, resulting in a smooth fade. I think thats probably the cause of your issues, if you want abrupt/blocky changes for pixel art. Unfortunately KhronosGroup/Vulkan-Docs#1361 suggests that NEAREST has inconsistent behavior across GPUs, so I'm not sure if exposing a different mode here is a good option.

Not ideal, but would it be possible to scale up the image to 100x100 instead of using a small image?

@ThisIsRex
Copy link
Contributor Author

ThisIsRex commented Oct 8, 2020

Not ideal, but would it be possible to scale up the image to 100x100 instead of using a small image?

I want to make a program which should representante binary data as image, like a hex editor, but with pixels instead of numbers and the canvas might be small

@twitchyliquid64
Copy link

Unfortunately sampler behavior is a core part of the image pipeline and cannot be easily switched over for some primitives. It might be possible to have a second sampler that we switch to for such images, but as I'm no expert with the wgpu stuff and this would be a pretty core change, I'll leave that to @hecrj to opine on.

In the absence of any new features or code changes to iced, I think scaling up your pixel art to the size of the image widget is the best path forward.

@hecrj
Copy link
Member

hecrj commented Oct 13, 2020

@ThisIsRex Have you considered using a Canvas widget to draw your pixel art using rectangles instead of generating a bitmap? Would that be overkill? How many pixels are we talking about?

@hecrj hecrj added feature New feature or request question Further information is requested labels Oct 13, 2020
@ThisIsRex
Copy link
Contributor Author

@ThisIsRex Have you considered using a Canvas widget to draw your pixel art using rectangles instead of generating a bitmap? Would that be overkill? How many pixels are we talking about?

I want to make a program, which should visualize any binary file as pixels. The image size can be various, from 3x3 to 2048x2048 with zooming. I think, Canvas is not the best widget for doing this.

@ronvoluted
Copy link

@ThisIsRex Would SVG rects work for your case? It would preserve 'pixel'/square separation but this remark in the docs suggests it should be benchmarked:

"Svg images can have a considerable rendering cost when resized, specially when they are complex."
https://docs.rs/iced/0.1.1/iced/widget/svg/struct.Svg.html

@hecrj hecrj changed the title How to disable antialiasing in Image widget Disable bilinear filtering for Image Jan 19, 2022
@hecrj hecrj added image and removed widget labels Jan 20, 2022
@bluecheetah001
Copy link

the KhronosGroup/Vulkan-Docs#1361 link is just saying that nearest isn't guaranteed when anisotrophy is enabled. but anisotrophy shouldn't be needed for UI graphics that always render head-on.

@Mingun
Copy link

Mingun commented Nov 11, 2023

but anisotrophy shouldn't be needed for UI graphics that always render head-on.

Note: that could not be true if you want UI like in Dead Space (spoiler: all UI in game is "in-game" literally)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request image question Further information is requested rendering
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants