@@ -851,20 +851,14 @@ fn apply_pbr_lighting(
851851#ifdef STANDARD_MATERIAL_SPECULAR_TRANSMISSION
852852 transmitted_light += transmission :: specular_transmissive_light (in . world_position , in . frag_coord . xyz , view_z , in . N , in . V , F0 , ior , thickness , perceptual_roughness , specular_transmissive_color , specular_transmitted_environment_light ). rgb ;
853853
854- if (in . material . flags & pbr_types :: STANDARD_MATERIAL_FLAGS_ATTENUATION_ENABLED_BIT ) != 0u {
855- // We reuse the `atmospheric_fog()` function here, as it's fundamentally
856- // equivalent to the attenuation that takes place inside the material volume,
857- // and will allow us to eventually hook up subsurface scattering more easily
858- var attenuation_fog : mesh_view_types :: Fog ;
859- attenuation_fog . base_color . a = 1 .0 ;
860- let attenuation_color = max (in . material . attenuation_color . rgb , vec3 <f32 >(1e-6 ));
861- attenuation_fog . be = - log (attenuation_color ) / in . material . attenuation_distance ;
862- // TODO: Add the subsurface scattering factor below
863- // attenuation_fog.bi = /* ... */
864- transmitted_light = bevy_pbr :: fog :: atmospheric_fog (
865- attenuation_fog , vec4 <f32 >(transmitted_light , 1 .0 ), thickness ,
866- vec3 <f32 >(0 .0 ) // TODO: Pass in (pre-attenuated) scattered light contribution here
867- ). rgb ;
854+ if (in . material . flags & pbr_types :: STANDARD_MATERIAL_FLAGS_ATTENUATION_ENABLED_BIT ) != 0u
855+ && in . material . attenuation_distance != 0 .0 {
856+ // Compute light attenuation using Beer's law.
857+ let transmittance = pow (
858+ in . material . attenuation_color . rgb ,
859+ vec3 <f32 >(thickness / in . material . attenuation_distance ),
860+ );
861+ transmitted_light *= transmittance ;
868862 }
869863#endif
870864
0 commit comments