1#import bevy_pbr::mesh_vertex_output as OutputTypes 2#import bevy_pbr::pbr_functions as PbrCore 3#import bevy_pbr::pbr_bindings as MaterialBindings 4#import bevy_pbr::pbr_types as PbrTypes 5#import bevy_pbr::mesh_view_bindings as ViewBindings 9 mesh: OutputTypes::MeshVertexOutput, 10 @builtin(front_facing) is_front: bool, 11 @builtin(position) frag_coord: vec4<f32>, 12) -> @location(0) vec4<f32> { 13 var output_color: vec4<f32> = MaterialBindings::material.base_color; 16 output_color = output_color * mesh.color; 19 if ((MaterialBindings::material.flags & PbrTypes::STANDARD_MATERIAL_FLAGS_BASE_COLOR_TEXTURE_BIT) != 0u) { 20 output_color = output_color * textureSample(MaterialBindings::base_color_texture, MaterialBindings::base_color_sampler, mesh.uv); 25 if ((MaterialBindings::material.flags & PbrTypes::STANDARD_MATERIAL_FLAGS_UNLIT_BIT) == 0u) { 28 var pbr_input: PbrCore::PbrInput; 30 pbr_input.material.base_color = output_color; 31 pbr_input.material.reflectance = MaterialBindings::material.reflectance; 32 pbr_input.material.flags = MaterialBindings::material.flags; 33 pbr_input.material.alpha_cutoff = MaterialBindings::material.alpha_cutoff; 36 var emissive: vec4<f32> = MaterialBindings::material.emissive; 38 if ((MaterialBindings::material.flags & PbrTypes::STANDARD_MATERIAL_FLAGS_EMISSIVE_TEXTURE_BIT) != 0u) { 39 emissive = vec4<f32>(emissive.rgb * textureSample(MaterialBindings::emissive_texture, MaterialBindings::emissive_sampler, mesh.uv).rgb, 1.0); 42 pbr_input.material.emissive = emissive; 44 var metallic: f32 = MaterialBindings::material.metallic; 45 var perceptual_roughness: f32 = MaterialBindings::material.perceptual_roughness; 47 if ((MaterialBindings::material.flags & PbrTypes::STANDARD_MATERIAL_FLAGS_METALLIC_ROUGHNESS_TEXTURE_BIT) != 0u) { 48 let metallic_roughness = textureSample(MaterialBindings::metallic_roughness_texture, MaterialBindings::metallic_roughness_sampler, mesh.uv); 50 metallic = metallic * metallic_roughness.b; 51 perceptual_roughness = perceptual_roughness * metallic_roughness.g; 54 pbr_input.material.metallic = metallic; 55 pbr_input.material.perceptual_roughness = perceptual_roughness; 57 var occlusion: f32 = 1.0; 59 if ((MaterialBindings::material.flags & PbrTypes::STANDARD_MATERIAL_FLAGS_OCCLUSION_TEXTURE_BIT) != 0u) { 60 occlusion = textureSample(MaterialBindings::occlusion_texture, MaterialBindings::occlusion_sampler, mesh.uv).r; 63 pbr_input.occlusion = occlusion; 65 pbr_input.frag_coord = frag_coord; 66 pbr_input.world_position = mesh.world_position; 67 pbr_input.world_normal = mesh.world_normal; 69 pbr_input.is_orthographic = ViewBindings::view.projection[3].w == 1.0; 71 pbr_input.N = PbrCore::prepare_normal( 72 MaterialBindings::material.flags, 75 #ifdef STANDARDMATERIAL_NORMAL_MAP 84 pbr_input.V = PbrCore::calculate_view(mesh.world_position, pbr_input.is_orthographic); 86 output_color = PbrCore::tone_mapping(PbrCore::pbr(pbr_input));