Rename transmission to specular_transmission

This commit is contained in:
Marco Buono 2023-09-26 00:54:50 -03:00
parent 15ebf76341
commit e973e17660
7 changed files with 57 additions and 57 deletions

View file

@ -708,7 +708,7 @@ fn load_material(
});
#[cfg(feature = "pbr_transmission_textures")]
let (transmission, transmission_texture) =
let (specular_transmission, transmission_texture) =
material.transmission().map_or((0.0, None), |transmission| {
let transmission_texture: Option<Handle<Image>> = transmission
.transmission_texture()
@ -721,7 +721,7 @@ fn load_material(
});
#[cfg(not(feature = "pbr_transmission_textures"))]
let transmission = material
let specular_transmission = material
.transmission()
.map_or(0.0, |transmission| transmission.transmission_factor());
@ -776,7 +776,7 @@ fn load_material(
emissive: Color::rgb_linear(emissive[0], emissive[1], emissive[2])
* material.emissive_strength().unwrap_or(1.0),
emissive_texture,
transmission,
specular_transmission,
#[cfg(feature = "pbr_transmission_textures")]
transmission_texture,
thickness,

View file

@ -145,7 +145,7 @@ pub struct StandardMaterial {
/// which provides an inexpensive but plausible approximation of translucency for thin dieletric objects (e.g. paper,
/// leaves, some fabrics) or thicker volumetric materials with short scattering distances (e.g. porcelain, wax).
///
/// For specular transmission usecases with refraction (e.g. glass) use the [`StandardMaterial::transmission`] and
/// For specular transmission usecases with refraction (e.g. glass) use the [`StandardMaterial::specular_transmission`] and
/// [`StandardMaterial::ior`] properties instead.
///
/// - When set to `0.0` (the default) no diffuse light is transmitted;
@ -185,17 +185,17 @@ pub struct StandardMaterial {
///
/// - [`Camera3d::transmissive_steps`](bevy_core_pipeline::core_3d::Camera3d::transmissive_steps) can be used to enable transmissive objects
/// to be seen through other transmissive objects, at the cost of additional draw calls and texture copies; (Use with caution!)
/// - If a simplified approximation of transmission using only environment map lighting is sufficient, consider setting
/// - If a simplified approximation of specular transmission using only environment map lighting is sufficient, consider setting
/// [`Camera3d::transmissive_steps`](bevy_core_pipeline::core_3d::Camera3d::transmissive_steps) to `0`.
/// - If purely diffuse light transmission is needed, (i.e. “translucency”) consider using [`StandardMaterial::diffuse_transmission`] instead,
/// for a much less expensive effect.
#[doc(alias = "refraction")]
pub transmission: f32,
pub specular_transmission: f32,
/// A map that modulates specular transmission via its **R channel**. Multiplied by [`StandardMaterial::transmission`]
/// A map that modulates specular transmission via its **R channel**. Multiplied by [`StandardMaterial::specular_transmission`]
/// to obtain the final result.
///
/// **Important:** The [`StandardMaterial::transmission`] property must be set to a value higher than 0.0,
/// **Important:** The [`StandardMaterial::specular_transmission`] property must be set to a value higher than 0.0,
/// or this texture won't have any effect.
#[texture(13)]
#[sampler(14)]
@ -209,7 +209,7 @@ pub struct StandardMaterial {
///
/// When set to any other value, the material distorts light like a thick lens.
///
/// **Note:** Typically used in conjunction with [`StandardMaterial::transmission`] and [`StandardMaterial::ior`], or with
/// **Note:** Typically used in conjunction with [`StandardMaterial::specular_transmission`] and [`StandardMaterial::ior`], or with
/// [`StandardMaterial::diffuse_transmission`].
#[doc(alias = "volume")]
#[doc(alias = "thin_walled")]
@ -250,7 +250,7 @@ pub struct StandardMaterial {
/// | Diamond | 2.42 |
/// | Moissanite | 2.65 |
///
/// **Note:** Typically used in conjunction with [`StandardMaterial::transmission`] and [`StandardMaterial::thickness`].
/// **Note:** Typically used in conjunction with [`StandardMaterial::specular_transmission`] and [`StandardMaterial::thickness`].
#[doc(alias = "index_of_refraction")]
#[doc(alias = "refraction_index")]
#[doc(alias = "refractive_index")]
@ -264,7 +264,7 @@ pub struct StandardMaterial {
/// **Note:** To have any effect, must be used in conjunction with:
/// - [`StandardMaterial::attenuation_color`];
/// - [`StandardMaterial::thickness`];
/// - [`StandardMaterial::diffuse_transmission`] or [`StandardMaterial::transmission`].
/// - [`StandardMaterial::diffuse_transmission`] or [`StandardMaterial::specular_transmission`].
#[doc(alias = "absorption_distance")]
#[doc(alias = "extinction_distance")]
pub attenuation_distance: f32,
@ -276,7 +276,7 @@ pub struct StandardMaterial {
/// **Note:** To have any effect, must be used in conjunction with:
/// - [`StandardMaterial::attenuation_distance`];
/// - [`StandardMaterial::thickness`];
/// - [`StandardMaterial::diffuse_transmission`] or [`StandardMaterial::transmission`].
/// - [`StandardMaterial::diffuse_transmission`] or [`StandardMaterial::specular_transmission`].
#[doc(alias = "absorption_color")]
#[doc(alias = "extinction_color")]
pub attenuation_color: Color,
@ -479,7 +479,7 @@ impl Default for StandardMaterial {
diffuse_transmission: 0.0,
#[cfg(feature = "pbr_transmission_textures")]
diffuse_transmission_texture: None,
transmission: 0.0,
specular_transmission: 0.0,
#[cfg(feature = "pbr_transmission_textures")]
transmission_texture: None,
thickness: 0.0,
@ -585,7 +585,7 @@ pub struct StandardMaterialUniform {
/// Amount of diffuse light transmitted through the material
pub diffuse_transmission: f32,
/// Amount of specular light transmitted through the material
pub transmission: f32,
pub specular_transmission: f32,
/// Thickness of the volume underneath the material surface
pub thickness: f32,
/// Index of Refraction
@ -694,7 +694,7 @@ impl AsBindGroupShaderType<StandardMaterialUniform> for StandardMaterial {
metallic: self.metallic,
reflectance: self.reflectance,
diffuse_transmission: self.diffuse_transmission,
transmission: self.transmission,
specular_transmission: self.specular_transmission,
thickness: self.thickness,
ior: self.ior,
attenuation_distance: self.attenuation_distance,
@ -778,6 +778,6 @@ impl Material for StandardMaterial {
#[inline]
fn reads_view_transmission_texture(&self) -> bool {
self.transmission > 0.0
self.specular_transmission > 0.0
}
}

View file

@ -95,13 +95,13 @@ fn fragment(
pbr_input.material.metallic = metallic;
pbr_input.material.perceptual_roughness = perceptual_roughness;
var transmission: f32 = pbr_bindings::material.transmission;
var specular_transmission: f32 = pbr_bindings::material.specular_transmission;
#ifdef PBR_TRANSMISSION_TEXTURES_SUPPORTED
if ((pbr_bindings::material.flags & STANDARD_MATERIAL_FLAGS_TRANSMISSION_TEXTURE_BIT) != 0u) {
transmission *= textureSample(pbr_bindings::transmission_texture, pbr_bindings::transmission_sampler, uv).r;
specular_transmission *= textureSample(pbr_bindings::transmission_texture, pbr_bindings::transmission_sampler, uv).r;
}
#endif
pbr_input.material.transmission = transmission;
pbr_input.material.specular_transmission = specular_transmission;
var thickness: f32 = pbr_bindings::material.thickness;
#ifdef PBR_TRANSMISSION_TEXTURES_SUPPORTED

View file

@ -189,9 +189,9 @@ fn pbr(
let ior = in.material.ior;
let thickness = in.material.thickness;
let diffuse_transmission = in.material.diffuse_transmission;
let transmission = in.material.transmission;
let specular_transmission = in.material.specular_transmission;
let transmissive_color = transmission * in.material.base_color.rgb;
let specular_transmissive_color = specular_transmission * in.material.base_color.rgb;
let occlusion = in.occlusion;
@ -206,10 +206,10 @@ fn pbr(
let F0 = 0.16 * reflectance * reflectance * (1.0 - metallic) + output_color.rgb * metallic;
// Diffuse strength is inversely related to metallicity, specular and diffuse transmission
let diffuse_color = output_color.rgb * (1.0 - metallic) * (1.0 - transmission) * (1.0 - diffuse_transmission);
let diffuse_color = output_color.rgb * (1.0 - metallic) * (1.0 - specular_transmission) * (1.0 - diffuse_transmission);
// Diffuse transmissive strength is inversely related to metallicity and specular transmission, but directly related to diffuse transmission
let diffuse_transmissive_color = output_color.rgb * (1.0 - metallic) * (1.0 - transmission) * diffuse_transmission;
let diffuse_transmissive_color = output_color.rgb * (1.0 - metallic) * (1.0 - specular_transmission) * diffuse_transmission;
// Calculate the world position of the second Lambertian lobe used for diffuse transmission, by subtracting material thickness
let diffuse_transmissive_lobe_world_position = in.world_position - vec4<f32>(in.world_normal, 0.0) * thickness;
@ -350,10 +350,10 @@ fn pbr(
indirect_light += (environment_light.diffuse * occlusion) + environment_light.specular;
// we'll use the specular component of the transmitted environment
// light in the call to `transmissive_light()` below
var transmitted_environment_light_specular = vec3<f32>(0.0);
// light in the call to `specular_transmissive_light()` below
var specular_transmitted_environment_light = vec3<f32>(0.0);
if diffuse_transmission > 0.0 || transmission > 0.0 {
if diffuse_transmission > 0.0 || specular_transmission > 0.0 {
// NOTE: We use the diffuse transmissive color, inverted normal and view vectors,
// and the following simplified values for the transmitted environment light contribution
// approximation:
@ -371,18 +371,18 @@ fn pbr(
let transmitted_environment_light = bevy_pbr::environment_map::environment_map_light(perceptual_roughness, roughness, diffuse_transmissive_color, 1.0, vec2<f32>(0.1), -in.N, T, vec3<f32>(0.16));
transmitted_light += transmitted_environment_light.diffuse;
transmitted_environment_light_specular = transmitted_environment_light.specular;
specular_transmitted_environment_light = transmitted_environment_light.specular;
}
#else
// If there's no environment map light, there's no transmitted environment
// light specular component, so we can just hardcode it to zero.
let transmitted_environment_light_specular = vec3<f32>(0.0);
let specular_transmitted_environment_light = vec3<f32>(0.0);
#endif
let emissive_light = emissive.rgb * output_color.a;
if transmission > 0.0 {
transmitted_light += lighting::transmissive_light(in.world_position, in.frag_coord.xyz, view_z, in.N, in.V, ior, thickness, perceptual_roughness, transmissive_color, transmitted_environment_light_specular).rgb;
if specular_transmission > 0.0 {
transmitted_light += lighting::specular_transmissive_light(in.world_position, in.frag_coord.xyz, view_z, in.N, in.V, ior, thickness, perceptual_roughness, specular_transmissive_color, specular_transmitted_environment_light).rgb;
}
if (in.material.flags & pbr_types::STANDARD_MATERIAL_FLAGS_ATTENUATION_ENABLED_BIT) != 0u {

View file

@ -286,7 +286,7 @@ fn directional_light(light_id: u32, roughness: f32, NdotV: f32, normal: vec3<f32
return (specular_light + diffuse) * (*light).color.rgb * NoL;
}
fn transmissive_light(world_position: vec4<f32>, frag_coord: vec3<f32>, view_z: f32, N: vec3<f32>, V: vec3<f32>, ior: f32, thickness: f32, perceptual_roughness: f32, transmissive_color: vec3<f32>, transmitted_environment_light_specular: vec3<f32>) -> vec3<f32> {
fn specular_transmissive_light(world_position: vec4<f32>, frag_coord: vec3<f32>, view_z: f32, N: vec3<f32>, V: vec3<f32>, ior: f32, thickness: f32, perceptual_roughness: f32, specular_transmissive_color: vec3<f32>, transmitted_environment_light_specular: vec3<f32>) -> vec3<f32> {
// Calculate the ratio between refaction indexes. Assume air/vacuum for the space outside the mesh
let eta = 1.0 / ior;
@ -310,9 +310,9 @@ fn transmissive_light(world_position: vec4<f32>, frag_coord: vec3<f32>, view_z:
// Fetch background color
let background_color = fetch_transmissive_background(offset_position, frag_coord, view_z, perceptual_roughness);
// Calculate final color by applying transmissive color to a mix of background color and transmitted specular environment light
// Calculate final color by applying specular transmissive color to a mix of background color and transmitted specular environment light
// TODO: Add support for attenuationColor and attenuationDistance
return transmissive_color * mix(transmitted_environment_light_specular, background_color.rgb, background_color.a);
return specular_transmissive_color * mix(transmitted_environment_light_specular, background_color.rgb, background_color.a);
}
// https://blog.demofox.org/2022/01/01/interleaved-gradient-noise-a-different-kind-of-low-discrepancy-sequence

View file

@ -7,7 +7,7 @@ struct StandardMaterial {
metallic: f32,
reflectance: f32,
diffuse_transmission: f32,
transmission: f32,
specular_transmission: f32,
thickness: f32,
ior: f32,
attenuation_distance: f32,
@ -55,7 +55,7 @@ fn standard_material_new() -> StandardMaterial {
material.metallic = 0.00;
material.reflectance = 0.5;
material.diffuse_transmission = 0.0;
material.transmission = 0.0;
material.specular_transmission = 0.0;
material.thickness = 0.0;
material.ior = 1.5;
material.attenuation_distance = 1.0;

View file

@ -5,7 +5,7 @@
//! | Key Binding | Action |
//! |:-------------------|:------------------------------------------|
//! | `1` / `2` | Decrease / Increase Diffuse Transmission |
//! | `Q` / `W` | Decrease / Increase Transmission |
//! | `Q` / `W` | Decrease / Increase Specular Transmission |
//! | `A` / `S` | Decrease / Increase Thickness |
//! | `Z` / `X` | Decrease / Increase IOR |
//! | `E` / `R` | Decrease / Increase Perceptual Roughness |
@ -96,7 +96,7 @@ fn setup(
},
ExampleControls {
color: true,
transmission: false,
specular_transmission: false,
diffuse_transmission: false,
},
));
@ -116,7 +116,7 @@ fn setup(
},
ExampleControls {
color: true,
transmission: false,
specular_transmission: false,
diffuse_transmission: false,
},
));
@ -138,7 +138,7 @@ fn setup(
NotTransmittedShadowReceiver,
ExampleControls {
color: true,
transmission: false,
specular_transmission: false,
diffuse_transmission: true,
},
));
@ -165,7 +165,7 @@ fn setup(
mesh: icosphere_mesh.clone(),
material: materials.add(StandardMaterial {
base_color: Color::WHITE,
transmission: 0.9,
specular_transmission: 0.9,
diffuse_transmission: 1.0,
thickness: 1.8,
ior: 1.5,
@ -178,7 +178,7 @@ fn setup(
NotTransmittedShadowReceiver,
ExampleControls {
color: true,
transmission: true,
specular_transmission: true,
diffuse_transmission: false,
},
));
@ -189,7 +189,7 @@ fn setup(
mesh: icosphere_mesh.clone(),
material: materials.add(StandardMaterial {
base_color: Color::RED,
transmission: 0.9,
specular_transmission: 0.9,
diffuse_transmission: 1.0,
thickness: 1.8,
ior: 1.5,
@ -202,7 +202,7 @@ fn setup(
NotTransmittedShadowReceiver,
ExampleControls {
color: true,
transmission: true,
specular_transmission: true,
diffuse_transmission: false,
},
));
@ -213,7 +213,7 @@ fn setup(
mesh: icosphere_mesh.clone(),
material: materials.add(StandardMaterial {
base_color: Color::GREEN,
transmission: 0.9,
specular_transmission: 0.9,
diffuse_transmission: 1.0,
thickness: 1.8,
ior: 1.5,
@ -226,7 +226,7 @@ fn setup(
NotTransmittedShadowReceiver,
ExampleControls {
color: true,
transmission: true,
specular_transmission: true,
diffuse_transmission: false,
},
));
@ -237,7 +237,7 @@ fn setup(
mesh: icosphere_mesh,
material: materials.add(StandardMaterial {
base_color: Color::BLUE,
transmission: 0.9,
specular_transmission: 0.9,
diffuse_transmission: 1.0,
thickness: 1.8,
ior: 1.5,
@ -250,7 +250,7 @@ fn setup(
NotTransmittedShadowReceiver,
ExampleControls {
color: true,
transmission: true,
specular_transmission: true,
diffuse_transmission: false,
},
));
@ -285,7 +285,7 @@ fn setup(
},
ExampleControls {
color: true,
transmission: false,
specular_transmission: false,
diffuse_transmission: false,
},
));
@ -311,7 +311,7 @@ fn setup(
..default()
},
ExampleControls {
transmission: false,
specular_transmission: false,
color: false,
diffuse_transmission: true,
},
@ -396,13 +396,13 @@ struct Flicker;
#[derive(Component)]
struct ExampleControls {
diffuse_transmission: bool,
transmission: bool,
specular_transmission: bool,
color: bool,
}
struct ExampleState {
diffuse_transmission: f32,
transmission: f32,
specular_transmission: f32,
thickness: f32,
ior: f32,
perceptual_roughness: f32,
@ -415,7 +415,7 @@ impl Default for ExampleState {
fn default() -> Self {
ExampleState {
diffuse_transmission: 0.5,
transmission: 0.9,
specular_transmission: 0.9,
thickness: 1.8,
ior: 1.5,
perceptual_roughness: 0.12,
@ -450,9 +450,9 @@ fn example_control_system(
}
if input.pressed(KeyCode::W) {
state.transmission = (state.transmission + time.delta_seconds()).min(1.0);
state.specular_transmission = (state.specular_transmission + time.delta_seconds()).min(1.0);
} else if input.pressed(KeyCode::Q) {
state.transmission = (state.transmission - time.delta_seconds()).max(0.0);
state.specular_transmission = (state.specular_transmission - time.delta_seconds()).max(0.0);
}
if input.pressed(KeyCode::S) {
@ -477,8 +477,8 @@ fn example_control_system(
for (material_handle, controls) in &controllable {
let material = materials.get_mut(material_handle).unwrap();
if controls.transmission {
material.transmission = state.transmission;
if controls.specular_transmission {
material.specular_transmission = state.specular_transmission;
material.thickness = state.thickness;
material.ior = state.ior;
material.perceptual_roughness = state.perceptual_roughness;
@ -556,7 +556,7 @@ fn example_control_system(
"N/A"
},
state.diffuse_transmission,
state.transmission,
state.specular_transmission,
state.thickness,
state.ior,
state.perceptual_roughness,