You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously, loading an image resulted in a hard-coded TextureFormat.
When loading images that are meant to be used as the
`StandardMaterial::depth_map`, the data can be stored in ways that
result in an `R16Uint` TextureFormat. This results in an error because
the `depth_map` must be a Float sampler and not a Uint sampler.
2025-08-29T17:15:03.081069Z ERROR bevy_render::erased_render_asset:
bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial,
test_uv_transform::MyExtension>> Bind group construction failed: At
binding index 12, the provided image sampler `Uint` does not match the
required sampler type(s) `[Float { filterable: true }]`.
Setting the TextureFormat can adjust the way in which the same image
data shows up in the shader. For example, an image that would otherwise
be `TextureFormat::R16Uint` can be set to `TextureFormat::R16Unorm`,
with no other changes, which results in the 16-bit integer data being
converted to the 0-1 range for the shader.
```rust
asset_server.load_with_settings(
"grass_height.png",
|settings: &mut ImageLoaderSettings| {
settings.texture_format = Some(TextureFormat::R16Unorm);
}
),
```
This PR adds the ability to set the texture format with using
`load_with_settings`.
Software like Substance Designer outputs height data in what becomes
`R16Uint` format, but depth_map requires `R16Unorm`.
--
Additional notes:
- TextureFormat does not have a serde implementation, so is skipped in
this PR
- This PR tries to change as little as possible when it comes to Image
creation, so does not add a TextureFormat option to Image constructors
like `from_buffer` and `from_dynamic`, which is what is used by the
ImageLoader. It also ends up relying on a conversion from
[`DynamicImage`](https://docs.rs/image/0.25.6/image/enum.DynamicImage.html),
which doesn't have enough information to make this judgement afaict.
- Alternative strategies could include using a LoadTransformAndSave
sequence to correct the data, but this is not straightforward as the
tools to do this are not obvious (specifically the conversion from the
Vec<u8> image crate representation + filename guessing when loading the
processed image).
0 commit comments