Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file removed assets/textures/spiaggia_di_mondello_1k.hdr
Binary file not shown.
15 changes: 13 additions & 2 deletions crates/bevy_image/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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,
}
Expand Down
56 changes: 56 additions & 0 deletions crates/bevy_image/src/ktx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}"
Expand Down
24 changes: 23 additions & 1 deletion examples/3d/depth_of_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -186,6 +187,7 @@ fn tweak_scene(
(Entity, &GltfMeshName, &MeshMaterial3d<StandardMaterial>),
(With<Mesh3d>, Without<Lightmap>),
>,
compressed_format_support: Res<CompressedImageFormatSupport>,
) {
// Turn on shadows.
for mut light in lights.iter_mut() {
Expand All @@ -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()
});
}
Expand Down