bevy/crates
axlitEels 775fae5b62
Add image sampler configuration in GLTF loader (#17875)
I can't underrate anisotropic filtering.

# Objective

- Allow easily enabling anisotropic filtering on glTF assets.
- Allow selecting `ImageFilterMode` for glTF assets at runtime.

## Solution

- Added a Resource `DefaultGltfImageSampler`: it stores
`Arc<Mutex<ImageSamplerDescriptor>>` and the same `Arc` is stored in
`GltfLoader`. The default is independent from provided to `ImagePlugin`
and is set in the same way but with `GltfPlugin`. It can then be
modified at runtime with `DefaultGltfImageSampler::set`.
- Added two fields to `GltfLoaderSettings`: `default_sampler:
Option<ImageSamplerDescriptor>` to override aforementioned global
default descriptor and `override_sampler: bool` to ignore glTF sampler
data.

## Showcase

Enabling anisotropic filtering as easy as:
```rust
app.add_plugins(DefaultPlugins.set(GltfPlugin{
    default_sampler: ImageSamplerDescriptor {
        min_filter: ImageFilterMode::Linear,
        mag_filter: ImageFilterMode::Linear,
        mipmap_filter: ImageFilterMode::Linear,
        anisotropy_clamp: 16,
        ..default()
    },
    ..default()
}))
```

Use code below to ignore both the global default sampler and glTF data,
having `your_shiny_sampler` used directly for all textures instead:
```rust
commands.spawn(SceneRoot(asset_server.load_with_settings(
    GltfAssetLabel::Scene(0).from_asset("models/test-scene.gltf"),
    |settings: &mut GltfLoaderSettings| {
        settings.default_sampler = Some(your_shiny_sampler);
        settings.override_sampler = true;
    }
)));
```
Remove either setting to get different result! They don't come in pair!

Scene rendered with trillinear texture filtering:

![Trillinear](https://github.com/user-attachments/assets/be4c417f-910c-4806-9e64-fd2c21b9fd8d)
Scene rendered with 16x anisotropic texture filtering:
![Anisotropic Filtering
x16](https://github.com/user-attachments/assets/68190be8-aabd-4bef-8e97-d1b5124cce60)

## Migration Guide

- The new fields in `GltfLoaderSettings` have their default values
replicate previous behavior.

---------

Co-authored-by: Greeble <166992735+greeble-dev@users.noreply.github.com>
2025-05-06 05:48:13 +00:00
..
bevy_a11y
bevy_animation Revert "Allow partial support for bevy_log in no_std (#18782)" (#18816) 2025-04-14 21:15:01 +00:00
bevy_anti_aliasing
bevy_app Rename bevy_platform_support to bevy_platform (#18813) 2025-04-11 23:13:28 +00:00
bevy_asset ignore files starting with . when loading folders (#11214) 2025-05-05 22:42:01 +00:00
bevy_audio Audio sink seek adopted (#18971) 2025-05-03 11:29:38 +00:00
bevy_color Implemented Alpha for f32. (#18653) 2025-05-06 00:00:17 +00:00
bevy_core_pipeline Rename bevy_platform_support to bevy_platform (#18813) 2025-04-11 23:13:28 +00:00
bevy_derive
bevy_dev_tools
bevy_diagnostic Update sysinfo version to 0.35.0 (#19028) 2025-05-05 05:49:23 +00:00
bevy_dylib don't disable std in bevy_dylib (#18807) 2025-04-11 18:44:53 +00:00
bevy_ecs Add IntoSystem::with_input and ::with_input_from system wrappers (#18067) 2025-05-06 05:46:30 +00:00
bevy_encase_derive
bevy_gilrs Rename bevy_platform_support to bevy_platform (#18813) 2025-04-11 23:13:28 +00:00
bevy_gizmos
bevy_gltf Add image sampler configuration in GLTF loader (#17875) 2025-05-06 05:48:13 +00:00
bevy_image Update ktx2 to 0.4.0 (#19073) 2025-05-05 16:42:36 +00:00
bevy_input Rename bevy_platform_support to bevy_platform (#18813) 2025-04-11 23:13:28 +00:00
bevy_input_focus Switch ChildOf back to tuple struct (#18672) 2025-04-02 00:10:10 +00:00
bevy_internal Revert "Allow partial support for bevy_log in no_std (#18782)" (#18816) 2025-04-14 21:15:01 +00:00
bevy_log feat(log): support customizing default log formatting (#17722) 2025-05-05 23:01:06 +00:00
bevy_macro_utils Fully qualify crate paths in BevyManifest (#18938) 2025-04-28 21:43:48 +00:00
bevy_math Fix rotate_by implementation for Aabb2d (#19015) 2025-05-04 13:05:27 +00:00
bevy_mesh Rename bevy_platform_support to bevy_platform (#18813) 2025-04-11 23:13:28 +00:00
bevy_mikktspace fix new nightly lint on mikktspace (#18988) 2025-04-30 05:19:01 +00:00
bevy_pbr Swap order of eviction/extraction when extracting for specialization (#18846) 2025-04-15 06:44:01 +00:00
bevy_picking Removed conversion from pointer physical coordinates to viewport local coordinates in bevy_picking make_ray function (#18870) 2025-04-27 13:54:28 +00:00
bevy_platform Create bevy_platform::cfg for viral feature management (#18822) 2025-05-06 00:52:15 +00:00
bevy_ptr
bevy_reflect Add NonNilUuid support to bevy_reflect (#18604) 2025-05-04 08:22:57 +00:00
bevy_remote Rename bevy_platform_support to bevy_platform (#18813) 2025-04-11 23:13:28 +00:00
bevy_render Derive clone_behavior for Components (#18811) 2025-05-06 00:32:59 +00:00
bevy_scene Rename bevy_platform_support to bevy_platform (#18813) 2025-04-11 23:13:28 +00:00
bevy_sprite Sprite picking docs fix (#19016) 2025-05-05 17:45:14 +00:00
bevy_state Rename StateScoped to DespawnOnExitState and add DespawnOnEnterState (#18818) 2025-05-06 00:37:04 +00:00
bevy_tasks Rename bevy_platform_support to bevy_platform (#18813) 2025-04-11 23:13:28 +00:00
bevy_text Text background colors (#18892) 2025-05-04 08:18:46 +00:00
bevy_time Rename bevy_platform_support to bevy_platform (#18813) 2025-04-11 23:13:28 +00:00
bevy_transform Revert "Allow partial support for bevy_log in no_std (#18782)" (#18816) 2025-04-14 21:15:01 +00:00
bevy_ui Add a viewport UI widget (#17253) 2025-05-05 22:57:37 +00:00
bevy_utils Rename bevy_platform_support to bevy_platform (#18813) 2025-04-11 23:13:28 +00:00
bevy_window Expose deferred screen edges setting for ios devices (#18729) 2025-04-30 21:24:53 +00:00
bevy_winit Expose CustomCursorUrl (#19006) 2025-05-06 05:23:48 +00:00