Commit 25d4ced
enable easier modification of image samplers in image loaders (#22042)
# Objective
Previously, to modify a sampler when loading an image with settings it
was required to set all fields individually. Much of the time, these
settings are all the same so to enable repeating textures you have to
set the address_mode 3 times. To set filters you have to set them
another 3 times.
```rust
MeshMaterial3d(materials.add(
StandardMaterial {
base_color_texture:
Some(
asset_server.load_with_settings(
"floor_graph_base_color.png",
|settings: &mut ImageLoaderSettings| {
let descriptor = settings.sampler.get_or_init_descriptor();
descriptor.address_mode_u = bevy::image::ImageAddressMode::Repeat;
descriptor.address_mode_v = bevy::image::ImageAddressMode::Repeat;
descriptor.address_mode_w = bevy::image::ImageAddressMode::Repeat;
descriptor.mag_filter = ImageFilterMode::Linear;
descriptor.min_filter = ImageFilterMode::Linear;
descriptor.mipmap_filter = ImageFilterMode::Linear;
}
),
),
unlit: true,
cull_mode: None,
uv_transform: Affine2::from_scale(Vec2::new(30., 90.)),
..default()
},
)),
```
## Solution
Add two new helpers, loosely modeled after the `Transform::with_<field>`
functions. Further modifications can still be made to the descriptor for
use cases which want to set one of the three fields differently, or
additionally set anisotropy_clamp, etc.
```rust
let descriptor = settings
.sampler
.get_or_init_descriptor()
.set_address_mode(ImageAddressMode::Repeat)
.set_filter(ImageFilterMode::Linear);
```
## Testing
New test in bevy_image
## Showcase
```rust
MeshMaterial3d(materials.add(
StandardMaterial {
base_color_texture:
Some(
asset_server.load_with_settings(
"floor_graph_base_color.png",
|settings: &mut ImageLoaderSettings| {
let descriptor = settings
.sampler
.get_or_init_descriptor()
.set_address_mode(ImageAddressMode::Repeat)
.set_filter(ImageFilterMode::Linear);
}
),
),
unlit: true,
cull_mode: None,
uv_transform: Affine2::from_scale(Vec2::new(30., 90.)),
..default()
},
)),
```
This PR now includes:
- `set_filter`
- `set_address_mode`
- `set_anisotropic_filter`
---------
Co-authored-by: Greeble <166992735+greeble-dev@users.noreply.github.com>1 parent ad1c38a commit 25d4ced
1 file changed
+60
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
699 | 699 | | |
700 | 700 | | |
701 | 701 | | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
702 | 732 | | |
703 | 733 | | |
704 | 734 | | |
| |||
2212 | 2242 | | |
2213 | 2243 | | |
2214 | 2244 | | |
| 2245 | + | |
| 2246 | + | |
| 2247 | + | |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
| 2274 | + | |
2215 | 2275 | | |
0 commit comments