Search across packages, versions, files, declarations, and comments. Use multiple terms to narrow results (AND), and add @vertex, @fragment, or @compute to filter by shader stage.
1#import bevy_pbr::{
2 forward_io::VertexOutput,
3 mesh_view_bindings::view,
4 pbr_types::{STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT, PbrInput, pbr_input_new},
5 pbr_functions as fns,
6 pbr_bindings,
7}
8#import bevy_core_pipeline::tonemapping::tone_mapping
10@group(#{MATERIAL_BIND_GROUP}) @binding(0) var my_array_texture: texture_2d_array<f32>;
11@group(#{MATERIAL_BIND_GROUP}) @binding(1) var my_array_texture_sampler: sampler;
13@fragment
14fn fragment(
15 @builtin(front_facing) is_front: bool,
16 mesh: VertexOutput,
17) -> @location(0) vec4<f32> {
18 let layer = i32(mesh.world_position.x) & 0x3;
20 // Prepare a 'processed' StandardMaterial by sampling all textures to resolve
21 // the material members
22 var pbr_input: PbrInput = pbr_input_new();
24 pbr_input.material.base_color = textureSample(my_array_texture, my_array_texture_sampler, mesh.uv, layer);
25#ifdef VERTEX_COLORS
26 pbr_input.material.base_color = pbr_input.material.base_color * mesh.color;
27#endif
29 let double_sided = (pbr_input.material.flags & STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT) != 0u;
31 pbr_input.frag_coord = mesh.position;
32 pbr_input.world_position = mesh.world_position;
33 pbr_input.world_normal = fns::prepare_world_normal(
34 mesh.world_normal,
35 double_sided,
36 is_front,
37 );
39 pbr_input.is_orthographic = view.clip_from_view[3].w == 1.0;
41 pbr_input.N = normalize(pbr_input.world_normal);
43#ifdef VERTEX_TANGENTS
44 let Nt = textureSampleBias(pbr_bindings::normal_map_texture, pbr_bindings::normal_map_sampler, mesh.uv, view.mip_bias).rgb;
45 let TBN = fns::calculate_tbn_mikktspace(mesh.world_normal, mesh.world_tangent);
46 pbr_input.N = fns::apply_normal_mapping(
47 pbr_input.material.flags,
48 TBN,
49 double_sided,
50 is_front,
51 Nt,
52 );
53#endif
55 pbr_input.V = fns::calculate_view(mesh.world_position, pbr_input.is_orthographic);
57 return tone_mapping(fns::apply_pbr_lighting(pbr_input), view.color_grading);
Contents