#import bevy_pbr::{ pbr_functions::alpha_discard, pbr_fragment::pbr_input_from_standard_material, } #ifdef PREPASS_PIPELINE #import bevy_pbr::{ prepass_io::{VertexOutput, FragmentOutput}, pbr_deferred_functions::deferred_output, } #else #import bevy_pbr::{ forward_io::{VertexOutput, FragmentOutput}, pbr_functions, pbr_functions::{apply_pbr_lighting, main_pass_post_lighting_processing}, pbr_types::STANDARD_MATERIAL_FLAGS_UNLIT_BIT, } #endif #ifdef MESHLET_MESH_MATERIAL_PASS #import bevy_pbr::meshlet_visibility_buffer_resolve::resolve_vertex_output #endif @fragment fn fragment( #ifdef MESHLET_MESH_MATERIAL_PASS @builtin(position) frag_coord: vec4, #else in: VertexOutput, @builtin(front_facing) is_front: bool, #endif ) -> FragmentOutput { #ifdef MESHLET_MESH_MATERIAL_PASS let in = resolve_vertex_output(frag_coord); let is_front = true; #endif // If we're in the crossfade section of a visibility range, conditionally // discard the fragment according to the visibility pattern. #ifdef VISIBILITY_RANGE_DITHER pbr_functions::visibility_range_dither(in.position, in.visibility_range_dither); #endif // generate a PbrInput struct from the StandardMaterial bindings var pbr_input = pbr_input_from_standard_material(in, is_front); // alpha discard pbr_input.material.base_color = alpha_discard(pbr_input.material, pbr_input.material.base_color); #ifdef PREPASS_PIPELINE // write the gbuffer, lighting pass id, and optionally normal and motion_vector textures let out = deferred_output(in, pbr_input); #else // in forward mode, we calculate the lit color immediately, and then apply some post-lighting effects here. // in deferred mode the lit color and these effects will be calculated in the deferred lighting shader var out: FragmentOutput; if (pbr_input.material.flags & STANDARD_MATERIAL_FLAGS_UNLIT_BIT) == 0u { out.color = apply_pbr_lighting(pbr_input); } else { out.color = pbr_input.material.base_color; } // apply in-shader post processing (fog, alpha-premultiply, and also tonemapping, debanding if the camera is non-hdr) // note this does not include fullscreen postprocessing effects like bloom. out.color = main_pass_post_lighting_processing(pbr_input, out.color); #endif return out; }