|
1 | | -#import bevy_pbr::mesh_view_bindings |
2 | | -#import bevy_pbr::mesh_bindings |
3 | | - |
4 | | -#import bevy_pbr::pbr_types |
5 | | -#import bevy_pbr::utils |
6 | | -#import bevy_pbr::clustered_forward |
7 | | -#import bevy_pbr::lighting |
8 | | -#import bevy_pbr::shadows |
9 | | -#import bevy_pbr::fog |
10 | | -#import bevy_pbr::pbr_functions |
11 | | -#import bevy_pbr::pbr_ambient |
| 1 | +#import bevy_pbr::mesh_vertex_output MeshVertexOutput |
| 2 | +#import bevy_pbr::mesh_view_bindings view |
| 3 | +#import bevy_pbr::pbr_types STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT |
| 4 | +#import bevy_core_pipeline::tonemapping tone_mapping |
| 5 | +#import bevy_pbr::pbr_functions as fns |
12 | 6 |
|
13 | 7 | @group(1) @binding(0) |
14 | 8 | var my_array_texture: texture_2d_array<f32>; |
15 | 9 | @group(1) @binding(1) |
16 | 10 | var my_array_texture_sampler: sampler; |
17 | 11 |
|
18 | | -struct FragmentInput { |
19 | | - @builtin(front_facing) is_front: bool, |
20 | | - @builtin(position) frag_coord: vec4<f32>, |
21 | | - #import bevy_pbr::mesh_vertex_output |
22 | | -}; |
23 | | - |
24 | 12 | @fragment |
25 | | -fn fragment(in: FragmentInput) -> @location(0) vec4<f32> { |
26 | | - let layer = i32(in.world_position.x) & 0x3; |
| 13 | +fn fragment( |
| 14 | + @builtin(front_facing) is_front: bool, |
| 15 | + mesh: MeshVertexOutput, |
| 16 | +) -> @location(0) vec4<f32> { |
| 17 | + let layer = i32(mesh.world_position.x) & 0x3; |
27 | 18 |
|
28 | 19 | // Prepare a 'processed' StandardMaterial by sampling all textures to resolve |
29 | 20 | // the material members |
30 | | - var pbr_input: PbrInput = pbr_input_new(); |
| 21 | + var pbr_input: fns::PbrInput = fns::pbr_input_new(); |
31 | 22 |
|
32 | | - pbr_input.material.base_color = textureSample(my_array_texture, my_array_texture_sampler, in.uv, layer); |
| 23 | + pbr_input.material.base_color = textureSample(my_array_texture, my_array_texture_sampler, mesh.uv, layer); |
33 | 24 | #ifdef VERTEX_COLORS |
34 | | - pbr_input.material.base_color = pbr_input.material.base_color * in.color; |
| 25 | + pbr_input.material.base_color = pbr_input.material.base_color * mesh.color; |
35 | 26 | #endif |
36 | 27 |
|
37 | | - pbr_input.frag_coord = in.frag_coord; |
38 | | - pbr_input.world_position = in.world_position; |
39 | | - pbr_input.world_normal = prepare_world_normal( |
40 | | - in.world_normal, |
| 28 | + pbr_input.frag_coord = mesh.position; |
| 29 | + pbr_input.world_position = mesh.world_position; |
| 30 | + pbr_input.world_normal = fns::prepare_world_normal( |
| 31 | + mesh.world_normal, |
41 | 32 | (pbr_input.material.flags & STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT) != 0u, |
42 | | - in.is_front, |
| 33 | + is_front, |
43 | 34 | ); |
44 | 35 |
|
45 | 36 | pbr_input.is_orthographic = view.projection[3].w == 1.0; |
46 | 37 |
|
47 | | - pbr_input.N = apply_normal_mapping( |
| 38 | + pbr_input.N = fns::apply_normal_mapping( |
48 | 39 | pbr_input.material.flags, |
49 | | - pbr_input.world_normal, |
| 40 | + mesh.world_normal, |
50 | 41 | #ifdef VERTEX_TANGENTS |
51 | 42 | #ifdef STANDARDMATERIAL_NORMAL_MAP |
52 | | - in.world_tangent, |
| 43 | + mesh.world_tangent, |
53 | 44 | #endif |
54 | 45 | #endif |
55 | | - in.uv, |
| 46 | + mesh.uv, |
56 | 47 | ); |
57 | | - pbr_input.V = calculate_view(in.world_position, pbr_input.is_orthographic); |
| 48 | + pbr_input.V = fns::calculate_view(mesh.world_position, pbr_input.is_orthographic); |
58 | 49 |
|
59 | | - return tone_mapping(pbr(pbr_input)); |
| 50 | + return tone_mapping(fns::pbr(pbr_input), view.color_grading); |
60 | 51 | } |
0 commit comments