This example illustrates how to create a texture for use with a texture_2d_array<f32> shader uniform variable and then how to sample from that texture in the shader by using a MeshTag component on the mesh entity.
use ;
/// This example uses a shader source file from the assets subdirectory.
const SHADER_ASSET_PATH: &str = "shaders/array_texture.wgsl";
/// Corresponds to the number of layers in the array texture.
const TEXTURE_COUNT: u32 = 4;
#import bevy_pbr::{
forward_io::VertexOutput,
mesh_functions,
mesh_view_bindings::view,
pbr_types::{STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT, PbrInput, pbr_input_new},
pbr_functions as fns,
pbr_bindings,
}
#import bevy_core_pipeline::tonemapping::tone_mapping
@group(#{MATERIAL_BIND_GROUP}) @binding(0) var my_array_texture: texture_2d_array<f32>;
@group(#{MATERIAL_BIND_GROUP}) @binding(1) var my_array_texture_sampler: sampler;
@fragment
// Determine which layer of the array texture to sample from based on the
// mesh tag which originates from the MeshTag component on the entity.
let layer = mesh_functions::;
// Prepare a 'processed' StandardMaterial by sampling all textures to resolve
// the material members
var pbr_input: PbrInput = ;
pbr_input.material.base_color = ;
#ifdef VERTEX_COLORS
pbr_input.material.base_color = pbr_input.material.base_color * mesh.color;
#endif
let double_sided = (pbr_input.material.flags & STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT) != 0u;
pbr_input.frag_coord = mesh.position;
pbr_input.world_position = mesh.world_position;
pbr_input.world_normal = fns::;
pbr_input.is_orthographic = view.clip_from_view[3].w == 1.0;
pbr_input.N = ;
#ifdef VERTEX_TANGENTS
let Nt = .rgb;
let TBN = fns::;
pbr_input.N = fns::;
#endif
pbr_input.V = fns::;
return ;
}