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_fragment::pbr_input_from_standard_material,
3 pbr_functions::alpha_discard,
4}
6#ifdef PREPASS_PIPELINE
7#import bevy_pbr::{
8 prepass_io::{VertexOutput, FragmentOutput},
9 pbr_deferred_functions::deferred_output,
11#else
12#import bevy_pbr::{
13 forward_io::{VertexOutput, FragmentOutput},
14 pbr_functions::{apply_pbr_lighting, main_pass_post_lighting_processing},
16#endif
18struct MyExtendedMaterial {
19 quantize_steps: u32,
20#ifdef SIXTEEN_BYTE_ALIGNMENT
21 // Web examples WebGL2 support: structs must be 16 byte aligned.
22 _webgl2_padding_8b: u32,
23 _webgl2_padding_12b: u32,
24 _webgl2_padding_16b: u32,
25#endif
28@group(#{MATERIAL_BIND_GROUP}) @binding(100)
29var<uniform> my_extended_material: MyExtendedMaterial;
31@fragment
32fn fragment(
33 in: VertexOutput,
34 @builtin(front_facing) is_front: bool,
35) -> FragmentOutput {
36 // generate a PbrInput struct from the StandardMaterial bindings
37 var pbr_input = pbr_input_from_standard_material(in, is_front);
39 // we can optionally modify the input before lighting and alpha_discard is applied
40 pbr_input.material.base_color.b = pbr_input.material.base_color.r;
42 // alpha discard
43 pbr_input.material.base_color = alpha_discard(pbr_input.material, pbr_input.material.base_color);
45#ifdef PREPASS_PIPELINE
46 // in deferred mode we can't modify anything after that, as lighting is run in a separate fullscreen shader.
47 let out = deferred_output(in, pbr_input);
48#else
49 var out: FragmentOutput;
50 // apply lighting
51 out.color = apply_pbr_lighting(pbr_input);
53 // we can optionally modify the lit color before post-processing is applied
54 out.color = vec4<f32>(vec4<u32>(out.color * f32(my_extended_material.quantize_steps))) / f32(my_extended_material.quantize_steps);
56 // apply in-shader post processing (fog, alpha-premultiply, and also tonemapping, debanding if the camera is non-hdr)
57 // note this does not include fullscreen postprocessing effects like bloom.
58 out.color = main_pass_post_lighting_processing(pbr_input, out.color);
60 // we can optionally modify the final result here
61 out.color = out.color * 2.0;
62#endif
64 return out;
Contents