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 bevy_pbr::render::{
2 pbr_fragment::pbr_input_from_standard_material,
3 pbr_functions::alpha_discard,
4};
6@if(PREPASS_PIPELINE)
7import bevy_pbr::{
8 prepass::io::{VertexOutput, FragmentOutput},
9 deferred::functions::deferred_output,
10};
11@else
12import bevy_pbr::render::{
13 forward_io::{VertexOutput, FragmentOutput},
14 pbr_functions::{apply_pbr_lighting, main_pass_post_lighting_processing},
15};
17struct MyExtendedMaterial {
18 quantize_steps: u32,
19 // Web examples WebGL2 support: structs must be 16 byte aligned.
20 @if(SIXTEEN_BYTE_ALIGNMENT)
21 _webgl2_padding_8b: u32,
22 @if(SIXTEEN_BYTE_ALIGNMENT)
23 _webgl2_padding_12b: u32,
24 @if(SIXTEEN_BYTE_ALIGNMENT)
25 _webgl2_padding_16b: u32,
28@group(constants::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(
44 pbr_input.material.flags,
45 pbr_input.material.alpha_cutoff,
46 pbr_input.material.base_color
47 );
49 var out: FragmentOutput;
50@if(PREPASS_PIPELINE) {
51 // in deferred mode we can't modify anything after that, as lighting is run in a separate fullscreen shader.
52 out = deferred_output(in, pbr_input);
53} @else {
54 // apply lighting
55 out.color = apply_pbr_lighting(pbr_input);
57 // we can optionally modify the lit color before post-processing is applied
58 out.color = vec4<f32>(vec4<u32>(out.color * f32(my_extended_material.quantize_steps))) / f32(my_extended_material.quantize_steps);
60 // apply in-shader post processing (fog, alpha-premultiply, and also tonemapping, debanding if the camera is non-hdr)
61 // note this does not include fullscreen postprocessing effects like bloom.
62 out.color = main_pass_post_lighting_processing(pbr_input, out.color);
64 // we can optionally modify the final result here
65 out.color = out.color * 2.0;
68 return out;
Contents