1#define_import_path bevy_pbr::ambient3#import bevy_pbr::{4 lighting::{EnvBRDFApprox, F_AB},5 mesh_view_bindings::lights,6}8// A precomputed `NdotV` is provided because it is computed regardless,9// but `world_normal` and the view vector `V` are provided separately for more advanced uses.10fn ambient_light(11 world_position: vec4<f32>,12 world_normal: vec3<f32>,13 V: vec3<f32>,14 NdotV: f32,15 diffuse_color: vec3<f32>,16 specular_color: vec3<f32>,17 perceptual_roughness: f32,18 occlusion: vec3<f32>,19) -> vec3<f32> {20 let diffuse_ambient = EnvBRDFApprox(diffuse_color, F_AB(1.0, NdotV));21 let specular_ambient = EnvBRDFApprox(specular_color, F_AB(perceptual_roughness, NdotV));23 // No real world material has specular values under 0.02, so we use this range as a24 // "pre-baked specular occlusion" that extinguishes the fresnel term, for artistic control.25 // See: https://google.github.io/filament/Filament.html#specularocclusion26 let specular_occlusion = saturate(dot(specular_color, vec3(50.0 * 0.33)));28 return (diffuse_ambient + specular_ambient * specular_occlusion) * lights.ambient_color.rgb * occlusion;29}