diff --git a/assets/models/DepthOfFieldExample/CircuitBoardLightmap_astc_4x4_hdr.ktx2 b/assets/models/DepthOfFieldExample/CircuitBoardLightmap_astc_4x4_hdr.ktx2 new file mode 100644 index 0000000000000..066cd6f91dbf3 Binary files /dev/null and b/assets/models/DepthOfFieldExample/CircuitBoardLightmap_astc_4x4_hdr.ktx2 differ diff --git a/assets/models/DepthOfFieldExample/CircuitBoardLightmap_bc6h_ufloat.ktx2 b/assets/models/DepthOfFieldExample/CircuitBoardLightmap_bc6h_ufloat.ktx2 new file mode 100644 index 0000000000000..5a107ea9afbed Binary files /dev/null and b/assets/models/DepthOfFieldExample/CircuitBoardLightmap_bc6h_ufloat.ktx2 differ diff --git a/assets/textures/spiaggia_di_mondello_1k.hdr b/assets/textures/spiaggia_di_mondello_1k.hdr deleted file mode 100644 index 694306a88f040..0000000000000 Binary files a/assets/textures/spiaggia_di_mondello_1k.hdr and /dev/null differ diff --git a/crates/bevy_image/src/image.rs b/crates/bevy_image/src/image.rs index b296ecdf9388c..ac2c3a97cdd06 100644 --- a/crates/bevy_image/src/image.rs +++ b/crates/bevy_image/src/image.rs @@ -1249,6 +1249,9 @@ impl Image { format_description .required_features() .contains(Features::TEXTURE_COMPRESSION_ASTC) + || format_description + .required_features() + .contains(Features::TEXTURE_COMPRESSION_ASTC_HDR) || format_description .required_features() .contains(Features::TEXTURE_COMPRESSION_BC) @@ -1899,8 +1902,9 @@ bitflags::bitflags! { pub struct CompressedImageFormats: u32 { const NONE = 0; const ASTC_LDR = 1 << 0; - const BC = 1 << 1; - const ETC2 = 1 << 2; + const ASTC_HDR = 1 << 1; + const BC = 1 << 2; + const ETC2 = 1 << 3; } } @@ -1910,6 +1914,9 @@ impl CompressedImageFormats { if features.contains(Features::TEXTURE_COMPRESSION_ASTC) { supported_compressed_formats |= Self::ASTC_LDR; } + if features.contains(Features::TEXTURE_COMPRESSION_ASTC_HDR) { + supported_compressed_formats |= Self::ASTC_HDR; + } if features.contains(Features::TEXTURE_COMPRESSION_BC) { supported_compressed_formats |= Self::BC; } @@ -1945,6 +1952,10 @@ impl CompressedImageFormats { | TextureFormat::EacR11Snorm | TextureFormat::EacRg11Unorm | TextureFormat::EacRg11Snorm => self.contains(CompressedImageFormats::ETC2), + TextureFormat::Astc { + channel: wgpu_types::AstcChannel::Hdr, + .. + } => self.contains(CompressedImageFormats::ASTC_HDR), TextureFormat::Astc { .. } => self.contains(CompressedImageFormats::ASTC_LDR), _ => true, } diff --git a/crates/bevy_image/src/ktx2.rs b/crates/bevy_image/src/ktx2.rs index 74e8c0caadbda..4ca3ce273bcf4 100644 --- a/crates/bevy_image/src/ktx2.rs +++ b/crates/bevy_image/src/ktx2.rs @@ -1476,6 +1476,62 @@ pub fn ktx2_format_to_texture_format( }, } } + ktx2::Format::ASTC_4x4_SFLOAT_BLOCK => TextureFormat::Astc { + block: AstcBlock::B4x4, + channel: AstcChannel::Hdr, + }, + ktx2::Format::ASTC_5x4_SFLOAT_BLOCK => TextureFormat::Astc { + block: AstcBlock::B5x4, + channel: AstcChannel::Hdr, + }, + ktx2::Format::ASTC_5x5_SFLOAT_BLOCK => TextureFormat::Astc { + block: AstcBlock::B5x5, + channel: AstcChannel::Hdr, + }, + ktx2::Format::ASTC_6x5_SFLOAT_BLOCK => TextureFormat::Astc { + block: AstcBlock::B6x5, + channel: AstcChannel::Hdr, + }, + ktx2::Format::ASTC_6x6_SFLOAT_BLOCK => TextureFormat::Astc { + block: AstcBlock::B6x6, + channel: AstcChannel::Hdr, + }, + ktx2::Format::ASTC_8x5_SFLOAT_BLOCK => TextureFormat::Astc { + block: AstcBlock::B8x5, + channel: AstcChannel::Hdr, + }, + ktx2::Format::ASTC_8x6_SFLOAT_BLOCK => TextureFormat::Astc { + block: AstcBlock::B8x6, + channel: AstcChannel::Hdr, + }, + ktx2::Format::ASTC_8x8_SFLOAT_BLOCK => TextureFormat::Astc { + block: AstcBlock::B8x8, + channel: AstcChannel::Hdr, + }, + ktx2::Format::ASTC_10x5_SFLOAT_BLOCK => TextureFormat::Astc { + block: AstcBlock::B10x5, + channel: AstcChannel::Hdr, + }, + ktx2::Format::ASTC_10x6_SFLOAT_BLOCK => TextureFormat::Astc { + block: AstcBlock::B10x6, + channel: AstcChannel::Hdr, + }, + ktx2::Format::ASTC_10x8_SFLOAT_BLOCK => TextureFormat::Astc { + block: AstcBlock::B10x8, + channel: AstcChannel::Hdr, + }, + ktx2::Format::ASTC_10x10_SFLOAT_BLOCK => TextureFormat::Astc { + block: AstcBlock::B10x10, + channel: AstcChannel::Hdr, + }, + ktx2::Format::ASTC_12x10_SFLOAT_BLOCK => TextureFormat::Astc { + block: AstcBlock::B12x10, + channel: AstcChannel::Hdr, + }, + ktx2::Format::ASTC_12x12_SFLOAT_BLOCK => TextureFormat::Astc { + block: AstcBlock::B12x12, + channel: AstcChannel::Hdr, + }, _ => { return Err(TextureError::UnsupportedTextureFormat(format!( "{ktx2_format:?}" diff --git a/examples/3d/depth_of_field.rs b/examples/3d/depth_of_field.rs index 1ffbc31c34ed2..52d6b85948463 100644 --- a/examples/3d/depth_of_field.rs +++ b/examples/3d/depth_of_field.rs @@ -9,6 +9,7 @@ //! //! [a blog post on depth of field in Unity]: https://catlikecoding.com/unity/tutorials/advanced-rendering/depth-of-field/ +use bevy::image::{CompressedImageFormatSupport, CompressedImageFormats}; use bevy::{ camera::PhysicalCameraParameters, core_pipeline::tonemapping::Tonemapping, @@ -186,6 +187,7 @@ fn tweak_scene( (Entity, &GltfMeshName, &MeshMaterial3d), (With, Without), >, + compressed_format_support: Res, ) { // Turn on shadows. for mut light in lights.iter_mut() { @@ -197,7 +199,27 @@ fn tweak_scene( if &**name == "CircuitBoard" { materials.get_mut(material).unwrap().lightmap_exposure = 10000.0; commands.entity(entity).insert(Lightmap { - image: asset_server.load("models/DepthOfFieldExample/CircuitBoardLightmap.hdr"), + image: asset_server.load( + if compressed_format_support + .0 + .contains(CompressedImageFormats::ASTC_HDR) + { + info!( + "Use compressed lightmap: {:?}", + CompressedImageFormats::ASTC_HDR + ); + "models/DepthOfFieldExample/CircuitBoardLightmap_astc_4x4_hdr.ktx2" + } else if compressed_format_support + .0 + .contains(CompressedImageFormats::BC) + { + info!("Use compressed lightmap: {:?}", CompressedImageFormats::BC); + "models/DepthOfFieldExample/CircuitBoardLightmap_bc6h_ufloat.ktx2" + } else { + info!("Use uncompressed lightmap"); + "models/DepthOfFieldExample/CircuitBoardLightmap.hdr" + }, + ), ..default() }); }