#import bevy_pbr::{ pbr_prepass_functions, pbr_bindings::material, pbr_types, pbr_functions, prepass_io, mesh_view_bindings::view, } #ifdef MESHLET_MESH_MATERIAL_PASS #import bevy_pbr::meshlet_visibility_buffer_resolve::resolve_vertex_output #endif #ifdef PREPASS_FRAGMENT @fragment fn fragment( #ifdef MESHLET_MESH_MATERIAL_PASS @builtin(position) frag_coord: vec4, #else in: prepass_io::VertexOutput, @builtin(front_facing) is_front: bool, #endif ) -> prepass_io::FragmentOutput { #ifdef MESHLET_MESH_MATERIAL_PASS let in = resolve_vertex_output(frag_coord); let is_front = true; #else pbr_prepass_functions::prepass_alpha_discard(in); #endif var out: prepass_io::FragmentOutput; #ifdef DEPTH_CLAMP_ORTHO out.frag_depth = in.clip_position_unclamped.z; #endif // DEPTH_CLAMP_ORTHO #ifdef NORMAL_PREPASS // NOTE: Unlit bit not set means == 0 is true, so the true case is if lit if (material.flags & pbr_types::STANDARD_MATERIAL_FLAGS_UNLIT_BIT) == 0u { let double_sided = (material.flags & pbr_types::STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT) != 0u; let world_normal = pbr_functions::prepare_world_normal( in.world_normal, double_sided, is_front, ); let normal = pbr_functions::apply_normal_mapping( material.flags, world_normal, double_sided, is_front, #ifdef VERTEX_TANGENTS #ifdef STANDARD_MATERIAL_NORMAL_MAP in.world_tangent, #endif // STANDARD_MATERIAL_NORMAL_MAP #endif // VERTEX_TANGENTS #ifdef VERTEX_UVS in.uv, #endif // VERTEX_UVS view.mip_bias, #ifdef MESHLET_MESH_MATERIAL_PASS in.ddx_uv, in.ddy_uv, #endif // MESHLET_MESH_MATERIAL_PASS ); out.normal = vec4(normal * 0.5 + vec3(0.5), 1.0); } else { out.normal = vec4(in.world_normal * 0.5 + vec3(0.5), 1.0); } #endif // NORMAL_PREPASS #ifdef MOTION_VECTOR_PREPASS #ifdef MESHLET_MESH_MATERIAL_PASS out.motion_vector = in.motion_vector; #else out.motion_vector = pbr_prepass_functions::calculate_motion_vector(in.world_position, in.previous_world_position); #endif #endif return out; } #else @fragment fn fragment(in: prepass_io::VertexOutput) { pbr_prepass_functions::prepass_alpha_discard(in); } #endif // PREPASS_FRAGMENT