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