use super::{PhysicalMaterial, TransparencyMode};
use crate::math::Color;
pub fn gold_foil() -> PhysicalMaterial {
PhysicalMaterial::new(Color::new(1.000, 0.766, 0.336))
.with_metalness(1.0)
.with_roughness(0.25)
}
pub fn silver_foil() -> PhysicalMaterial {
PhysicalMaterial::new(Color::new(0.972, 0.960, 0.915))
.with_metalness(1.0)
.with_roughness(0.18)
}
pub fn aluminum() -> PhysicalMaterial {
PhysicalMaterial::new(Color::new(0.913, 0.921, 0.925))
.with_metalness(1.0)
.with_roughness(0.35)
}
pub fn brushed_aluminum(rotation: f32) -> PhysicalMaterial {
aluminum()
.with_roughness(0.3)
.with_anisotropy(0.8, rotation)
}
pub fn titanium() -> PhysicalMaterial {
PhysicalMaterial::new(Color::new(0.542, 0.497, 0.449))
.with_metalness(1.0)
.with_roughness(0.4)
}
pub fn anodized_titanium(thickness_nm: f32) -> PhysicalMaterial {
titanium()
.with_roughness(0.28)
.with_iridescence(1.0, 1.8, thickness_nm)
}
pub fn solar_cell() -> PhysicalMaterial {
PhysicalMaterial::new(Color::from_hex(0x0a1633))
.with_metalness(0.1)
.with_roughness(0.35)
.with_clearcoat(1.0, 0.04)
.with_anisotropy(0.6, 0.0)
}
pub fn array_backing() -> PhysicalMaterial {
PhysicalMaterial::new(Color::from_hex(0x1b1d24))
.with_metalness(0.0)
.with_roughness(0.8)
}
pub fn optical_glass() -> PhysicalMaterial {
PhysicalMaterial::new(Color::from_hex(0xffffff))
.with_transmission(1.0, 1.52, 0.4)
.with_roughness(0.03)
.with_attenuation(Color::from_hex(0xdff0ff), 2.0)
.with_transparency(TransparencyMode::Refract)
}
pub fn white_thermal_paint() -> PhysicalMaterial {
PhysicalMaterial::new(Color::from_hex(0xf2f0ea))
.with_metalness(0.0)
.with_roughness(0.7)
}
pub fn black_kapton() -> PhysicalMaterial {
PhysicalMaterial::new(Color::from_hex(0x0a0a0c))
.with_metalness(0.0)
.with_roughness(0.55)
.with_sheen(0.35, Color::from_hex(0x3a4050), 0.7)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn metal_presets_are_fully_metallic() {
for m in [gold_foil(), silver_foil(), aluminum(), titanium()] {
assert_eq!(m.metalness, 1.0);
}
}
#[test]
fn gold_f0_is_warm() {
let g = gold_foil().color;
assert!(g.r > g.g && g.g > g.b);
}
#[test]
fn glass_opts_into_refraction() {
let g = optical_glass();
assert_eq!(g.transparency, TransparencyMode::Refract);
assert!(g.transmission > 0.0);
assert!(g.attenuation_distance.is_finite());
}
#[test]
fn anodized_titanium_enables_thin_film() {
let t = anodized_titanium(300.0);
assert!(t.iridescence > 0.0);
assert_eq!(t.iridescence_thickness_range[1], 300.0);
}
}