mirror of
https://github.com/bevyengine/bevy
synced 2025-02-18 15:08:36 +00:00
Reuse fog implementation to implement transmission attenuation
This commit is contained in:
parent
50b32da4c8
commit
580f4af803
2 changed files with 16 additions and 0 deletions
|
@ -366,6 +366,21 @@ fn pbr(
|
|||
transmitted_light += transmissive_light(in.world_position, in.frag_coord.xyz, in.N, in.V, ior, thickness, perceptual_roughness, transmissive_color, transmitted_environment_light_specular).rgb;
|
||||
}
|
||||
|
||||
if in.material.attenuation_distance < (1.0 / 0.0) /* f32::INFINITY */ {
|
||||
// We reuse the `atmospheric_fog()` function here, as it's fundamentally
|
||||
// equivalent to the attenuation that takes place inside the material volume,
|
||||
// and will allow us to eventually hook up subsurface scattering more easily
|
||||
var attenuation_fog: Fog;
|
||||
attenuation_fog.base_color.a = 1.0;
|
||||
attenuation_fog.be = pow(1.0 - in.material.attenuation_color.rgb, vec3<f32>(E)) / in.material.attenuation_distance;
|
||||
// TODO: Add the subsurface scattering factor below
|
||||
// attenuation_fog.bi = /* ... */
|
||||
transmitted_light = atmospheric_fog(
|
||||
attenuation_fog, vec4<f32>(transmitted_light, 1.0), thickness,
|
||||
vec3<f32>(0.0) // TODO: Pass in (pre-attenuated) scatterd light contribution here
|
||||
).rgb;
|
||||
}
|
||||
|
||||
// Total light
|
||||
output_color = vec4<f32>(
|
||||
transmitted_light + direct_light + indirect_light + emissive_light,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#define_import_path bevy_pbr::utils
|
||||
|
||||
const PI: f32 = 3.141592653589793;
|
||||
const E: f32 = 2.718281828459045;
|
||||
|
||||
fn hsv2rgb(hue: f32, saturation: f32, value: f32) -> vec3<f32> {
|
||||
let rgb = clamp(
|
||||
|
|
Loading…
Add table
Reference in a new issue