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