forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support array / cubemap / cubemap array textures in KTX2 (bevyengine#…
…5325) # Objective - Fix / support KTX2 array / cubemap / cubemap array textures - Fixes bevyengine#4495 . Supersedes bevyengine#4514 . ## Solution - Add `Option<TextureViewDescriptor>` to `Image` to enable configuration of the `TextureViewDimension` of a texture. - This allows users to set `D2Array`, `D3`, `Cube`, `CubeArray` or whatever they need - Automatically configure this when loading KTX2 - Transcode all layers and faces instead of just one - Use the UASTC block size of 128 bits, and the number of blocks in x/y for a given mip level in order to determine the offset of the layer and face within the KTX2 mip level data - `wgpu` wants data ordered as layer 0 mip 0..n, layer 1 mip 0..n, etc. See https://docs.rs/wgpu/latest/wgpu/util/trait.DeviceExt.html#tymethod.create_texture_with_data - Reorder the data KTX2 mip X layer Y face Z to `wgpu` layer Y face Z mip X order - Add a `skybox` example to demonstrate / test loading cubemaps from PNG and KTX2, including ASTC 4x4, BC7, and ETC2 compression for support everywhere. Note that you need to enable the `ktx2,zstd` features to be able to load the compressed textures. --- ## Changelog - Fixed: KTX2 array / cubemap / cubemap array textures - Fixes: Validation failure for compressed textures stored in KTX2 where the width/height are not a multiple of the block dimensions. - Added: `Image` now has an `Option<TextureViewDescriptor>` field to enable configuration of the texture view. This is useful for configuring the `TextureViewDimension` when it is not just a plain 2D texture and the loader could/did not identify what it should be. Co-authored-by: Carter Anderson <mcanders1@gmail.com>
- Loading branch information
Showing
11 changed files
with
615 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#import bevy_pbr::mesh_view_bindings | ||
|
||
#ifdef CUBEMAP_ARRAY | ||
@group(1) @binding(0) | ||
var base_color_texture: texture_cube_array<f32>; | ||
#else | ||
@group(1) @binding(0) | ||
var base_color_texture: texture_cube<f32>; | ||
#endif | ||
|
||
@group(1) @binding(1) | ||
var base_color_sampler: sampler; | ||
|
||
@fragment | ||
fn fragment( | ||
#import bevy_pbr::mesh_vertex_output | ||
) -> @location(0) vec4<f32> { | ||
let fragment_position_view_lh = world_position.xyz * vec3<f32>(1.0, 1.0, -1.0); | ||
return textureSample( | ||
base_color_texture, | ||
base_color_sampler, | ||
fragment_position_view_lh | ||
); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Modifications | ||
============= | ||
|
||
The original work, as attributed below, has been modified as follows using the ImageMagick tool: | ||
|
||
mogrify -resize 256x256 -format png *.jpg | ||
convert posx.png negx.png posy.png negy.png posz.png negz.png -gravity center -append cubemap.png | ||
|
||
Author | ||
====== | ||
|
||
This is the work of Emil Persson, aka Humus. | ||
http://www.humus.name | ||
|
||
|
||
|
||
License | ||
======= | ||
|
||
This work is licensed under a Creative Commons Attribution 3.0 Unported License. | ||
http://creativecommons.org/licenses/by/3.0/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.