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