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 pbr_types,
3 pbr_functions::alpha_discard,
4 pbr_fragment::pbr_input_from_standard_material,
5 decal::clustered::apply_decals,
6}
8#ifdef PREPASS_PIPELINE
9#import bevy_pbr::{
10 prepass_io::{VertexOutput, FragmentOutput},
11 pbr_deferred_functions::deferred_output,
13#else
14#import bevy_pbr::{
15 forward_io::{VertexOutput, FragmentOutput},
16 pbr_functions::{apply_pbr_lighting, main_pass_post_lighting_processing},
17 pbr_types::STANDARD_MATERIAL_FLAGS_UNLIT_BIT,
19#endif
21#ifdef VISIBILITY_RANGE_DITHER
22#import bevy_pbr::pbr_functions::visibility_range_dither;
23#endif
25#ifdef MESHLET_MESH_MATERIAL_PASS
26#import bevy_pbr::meshlet_visibility_buffer_resolve::resolve_vertex_output
27#endif
29#ifdef OIT_ENABLED
30#import bevy_core_pipeline::oit::oit_draw
31#endif // OIT_ENABLED
33#ifdef FORWARD_DECAL
34#import bevy_pbr::decal::forward::get_forward_decal_info
35#endif
37@fragment
38fn fragment(
39#ifdef MESHLET_MESH_MATERIAL_PASS
40 @builtin(position) frag_coord: vec4<f32>,
41#else
42 vertex_output: VertexOutput,
43 @builtin(front_facing) is_front: bool,
44#endif
45) -> FragmentOutput {
46#ifdef MESHLET_MESH_MATERIAL_PASS
47 let vertex_output = resolve_vertex_output(frag_coord);
48 let is_front = true;
49#endif
51 var in = vertex_output;
53 // If we're in the crossfade section of a visibility range, conditionally
54 // discard the fragment according to the visibility pattern.
55#ifdef VISIBILITY_RANGE_DITHER
56 visibility_range_dither(in.position, in.visibility_range_dither);
57#endif
59#ifdef FORWARD_DECAL
60 let forward_decal_info = get_forward_decal_info(in);
61 in.world_position = forward_decal_info.world_position;
62 in.uv = forward_decal_info.uv;
63#endif
65 // generate a PbrInput struct from the StandardMaterial bindings
66 var pbr_input = pbr_input_from_standard_material(in, is_front);
68 // alpha discard
69 pbr_input.material.base_color = alpha_discard(pbr_input.material, pbr_input.material.base_color);
71 // clustered decals
72 apply_decals(&pbr_input);
74#ifdef PREPASS_PIPELINE
75 // write the gbuffer, lighting pass id, and optionally normal and motion_vector textures
76 let out = deferred_output(in, pbr_input);
77#else
78 // in forward mode, we calculate the lit color immediately, and then apply some post-lighting effects here.
79 // in deferred mode the lit color and these effects will be calculated in the deferred lighting shader
80 var out: FragmentOutput;
81 if (pbr_input.material.flags & STANDARD_MATERIAL_FLAGS_UNLIT_BIT) == 0u {
82 out.color = apply_pbr_lighting(pbr_input);
83 } else {
84 out.color = pbr_input.material.base_color;
85 }
87 // apply in-shader post processing (fog, alpha-premultiply, and also tonemapping, debanding if the camera is non-hdr)
88 // note this does not include fullscreen postprocessing effects like bloom.
89 out.color = main_pass_post_lighting_processing(pbr_input, out.color);
90#endif
92#ifdef OIT_ENABLED
93 let alpha_mode = pbr_input.material.flags & pbr_types::STANDARD_MATERIAL_FLAGS_ALPHA_MODE_RESERVED_BITS;
94 if alpha_mode != pbr_types::STANDARD_MATERIAL_FLAGS_ALPHA_MODE_OPAQUE {
95 // The fragments will only be drawn during the oit resolve pass.
96 oit_draw(in.position, out.color);
97 discard;
98 }
99#endif // OIT_ENABLED
101#ifdef FORWARD_DECAL
102 out.color.a = min(forward_decal_info.alpha, out.color.a);
103#endif
105 return out;
Contents