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

No mipmap interpolation, mipmap level 0 fetched by default. #6348

Closed
jkb0o opened this issue Oct 23, 2022 · 0 comments
Closed

No mipmap interpolation, mipmap level 0 fetched by default. #6348

jkb0o opened this issue Oct 23, 2022 · 0 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior

Comments

@jkb0o
Copy link
Contributor

jkb0o commented Oct 23, 2022

Bevy version

8.1

Relevant system information

AdapterInfo { name: "Apple M1", vendor: 0, device: 0, device_type: IntegratedGpu, backend: Metal }

What you did

I render single image with mipmaps (circle.basis) multiple times with different sizes using bevy ui:
pixelated_big

bevy_issue_mipmaps.zip

What went wrong

Looks like mipmaps doesn't respected. There is a screenshot. Top row is basis image with mipmaps. The bottom row is png image without mipmaps. It looks the same, pixelated:
pixelated_small

I'm expecting the correct interpolation between mipmap levels based on image size. Something like this:
non_pixelated_small

Additional information

I found this happens because bevy::render::texture::ImageSettings::linear_descriptior() do not set mipmap_filter option:

pub fn linear_descriptor() -> wgpu::SamplerDescriptor<'static> {
wgpu::SamplerDescriptor {
mag_filter: wgpu::FilterMode::Linear,
min_filter: wgpu::FilterMode::Linear,
..Default::default()
}
}

It is FilterMode::Nearest by default. With this setting I was even unable to fetch color with textureSampleLevel in wgsl shader, it always return data from mip level 0.

Changing ImageSettings didn't help, possibly because of #5744.
The only workaround i found is to set mipmap_filter manually, as suggested in #5744:

fn patch_default_mipmap_filter(
    mut texture_events: EventReader<AssetEvent<Image>>,
    mut textures: ResMut<Assets<Image>>,
) {
    let filter = FilterMode::Linear;
    for event in texture_events.iter() {
        if let AssetEvent::Created { handle } = event {
            if let Some(mut texture) = textures.get_mut(handle) {
                texture.sampler_descriptor = ImageSampler::Descriptor(SamplerDescriptor {
                    mag_filter: filter,
                    min_filter: filter,
                    mipmap_filter: filter,
                    ..default()
                });
            };
        }
    }
}

While researching I found the same behaviour in 3d as well: by default mipmap level 0 fetched.

@jkb0o jkb0o added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Oct 23, 2022
@jkb0o jkb0o changed the title No mipmap interpolation, mipmap level 0 fetches by default. No mipmap interpolation, mipmap level 0 fetched by default. Oct 23, 2022
jkb0o added a commit to jkb0o/bevy that referenced this issue Oct 23, 2022
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels Oct 23, 2022
bors bot pushed a commit that referenced this issue Nov 3, 2022
…st() (#6349)

Respect mipmap_filter when create ImageDescriptor with linear()/nearest()

# Objective

Fixes #6348

## Migration Guide

This PR changes default `ImageSettings` and may lead to unexpected behaviour for existing projects with mipmapped textures. Users should provide custom `ImageSettings` resource with `mipmap_filter=FilterMode::Nearest` if they want to  keep old behaviour.

Co-authored-by: Yakov Borevich <j.borevich@gmail.com>
@bors bors bot closed this as completed in 157f2c1 Nov 3, 2022
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
…st() (bevyengine#6349)

Respect mipmap_filter when create ImageDescriptor with linear()/nearest()

# Objective

Fixes bevyengine#6348

## Migration Guide

This PR changes default `ImageSettings` and may lead to unexpected behaviour for existing projects with mipmapped textures. Users should provide custom `ImageSettings` resource with `mipmap_filter=FilterMode::Nearest` if they want to  keep old behaviour.

Co-authored-by: Yakov Borevich <j.borevich@gmail.com>
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 C-Bug An unexpected or incorrect behavior
Projects
None yet
2 participants