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.
1import package::{
2 render::{
3 pbr_types,
4 pbr_functions::alpha_discard,
5 pbr_fragment::pbr_input_from_standard_material,
6 },
7 decal::clustered::apply_decals,
8};
10@if(PREPASS_PIPELINE)
11import package::{
12 prepass::io::{VertexOutput, FragmentOutput},
13 deferred::functions::deferred_output,
14};
15@else
16import package::render::{
17 forward_io::{VertexOutput, FragmentOutput},
18 pbr_functions::{apply_pbr_lighting, main_pass_post_lighting_processing},
19 pbr_types::STANDARD_MATERIAL_FLAGS_UNLIT_BIT,
20};
22@if(VISIBILITY_RANGE_DITHER)
23import package::render::pbr_functions::visibility_range_dither;
25@if(MESHLET_MESH_MATERIAL_PASS)
26import package::meshlet::visibility_buffer_resolve::resolve_vertex_output;
28@if(MATERIAL_OIT_ENABLED)
29import bevy_core_pipeline::oit::draw::oit_draw;
31@if(FORWARD_DECAL)
32import package::decal::forward::get_forward_decal_info;
34@fragment
35fn fragment(
36@if(MESHLET_MESH_MATERIAL_PASS)
37 @builtin(position) frag_coord: vec4<f32>,
38@if(!MESHLET_MESH_MATERIAL_PASS)
39 vertex_output: VertexOutput,
40@if(!MESHLET_MESH_MATERIAL_PASS)
41 @builtin(front_facing) is_front: bool,
42) -> FragmentOutput {
43@if(MESHLET_MESH_MATERIAL_PASS)
44 let vertex_output = resolve_vertex_output(frag_coord);
45@if(MESHLET_MESH_MATERIAL_PASS)
46 let is_front = true;
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@if(VISIBILITY_RANGE_DITHER)
53 visibility_range_dither(in.position, in.visibility_range_dither);
55@if(FORWARD_DECAL)
56 let forward_decal_info = get_forward_decal_info(in);
57@if(FORWARD_DECAL)
58 in.world_position = forward_decal_info.world_position;
59@if(FORWARD_DECAL)
60 in.uv = forward_decal_info.uv;
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(
67 pbr_input.material.flags,
68 pbr_input.material.alpha_cutoff,
69 pbr_input.material.base_color
70 );
72 // clustered decals
73 apply_decals(&pbr_input);
75 // write the gbuffer, lighting pass id, and optionally normal and motion_vector textures
76@if(PREPASS_PIPELINE)
77 let out = deferred_output(in, pbr_input);
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@if(!PREPASS_PIPELINE)
81 var out: FragmentOutput;
82@if(!PREPASS_PIPELINE)
83 if (pbr_input.material.flags & STANDARD_MATERIAL_FLAGS_UNLIT_BIT) == 0u {
84 out.color = apply_pbr_lighting(pbr_input);
85 } else {
86 out.color = pbr_input.material.base_color;
87 }
89 // apply in-shader post processing (fog, alpha-premultiply, and also tonemapping, debanding if the camera is non-hdr)
90 // note this does not include fullscreen postprocessing effects like bloom.
91@if(!PREPASS_PIPELINE)
92 out.color = main_pass_post_lighting_processing(pbr_input, out.color);
94@if(MATERIAL_OIT_ENABLED) {
95 let alpha_mode = pbr_input.material.flags & pbr_types::STANDARD_MATERIAL_FLAGS_ALPHA_MODE_RESERVED_BITS;
96 if alpha_mode == pbr_types::STANDARD_MATERIAL_FLAGS_ALPHA_MODE_BLEND {
97 // The fragments will only be drawn during the oit resolve pass.
98 oit_draw(in.position, vec4(out.color.rgb * out.color.a, out.color.a));
99 discard;
100 }
101 // Both `Premultiplied` and `Add` colors are premultiplied in `premultiply_alpha()`
102 if alpha_mode == pbr_types::STANDARD_MATERIAL_FLAGS_ALPHA_MODE_PREMULTIPLIED
103 || alpha_mode == pbr_types::STANDARD_MATERIAL_FLAGS_ALPHA_MODE_ADD {
104 // The fragments will only be drawn during the oit resolve pass.
105 oit_draw(in.position, out.color);
106 discard;
107 }
110@if(FORWARD_DECAL)
111 out.color.a = min(forward_decal_info.alpha, out.color.a);
113 return out;
Contents