use rin_math::{Mat4, Rad};
use super::texture::TextureSampler;
use super::AlphaType;
use color::*;
use color::consts::*;
use color::color_space::LinearRgb;
use mutiny_derive::Material;
use derive_builder::Builder;
use super::Parameter;
#[derive(Debug, Material, Builder, Clone)]
#[material(default)]
#[builder(default)]
#[builder(setter(into))]
#[builder(build_fn(name = "_build", private, validate = "Self::check_material"))]
pub struct StandardMaterial{
#[builder(setter(name = "base_color_map_opt"))]
pub base_color_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "normal_map_opt"))]
pub normal_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "occlusion_map_opt"))]
pub occlusion_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "metallic_roughness_map_opt"))]
pub metallic_roughness_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "metallic_map_opt"))]
pub metallic_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "roughness_map_opt"))]
pub roughness_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "emissive_map_opt"))]
pub emissive_map: Parameter<Option<TextureSampler>>,
#[material(not_data)]
base_color_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
normal_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
occlusion_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
metallic_roughness_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
emissive_map_matrix: Parameter<Option<Mat4>>,
#[material(default = "WHITE.to_rgba().to_linear()")]
#[builder(private)]
#[builder(setter(name = "hidden_base_color"))]
pub base_color: Parameter<Rgba<f32, LinearRgb>>,
#[material(default = "BLACK.to_rgb().to_linear()")]
#[builder(private)]
#[builder(setter(name = "hidden_emissive_color"))]
pub emissive_color: Parameter<Rgb<f32, LinearRgb>>,
#[material(default = 1.0)]
pub normal_scale: Parameter<f32>,
#[material(default = 0.5)]
pub roughness: Parameter<f32>,
#[material(default = 0.0)]
pub metallic: Parameter<f32>,
#[material(default = 0.5)]
pub reflectance: Parameter<f32>,
#[material(default = 0.0)]
pub reflectance_tint: Parameter<f32>,
#[material(default = false)]
#[material(not_data)]
pub double_sided: Parameter<bool>,
#[material(not_data)]
pub alpha_type: Parameter<AlphaType>,
#[material(not_data)]
pub shader_precision: Parameter<super::ShaderPrecision>,
#[material(not_data)]
pub override_translucent: Parameter<Option<bool>>,
#[material(not_data)]
pub debug_texcoords: Parameter<bool>,
#[material(not_data)]
pub debug_normals: Parameter<bool>,
}
impl StandardMaterialBuilder{
pub fn new() -> Self {
Self::default()
}
pub fn color<C: ToRgba>(&mut self, color: C) -> &mut StandardMaterialBuilder{
self.base_color = Some(color.to_rgba().to_linear().into());
self
}
pub fn emissive_color<C: ToRgb>(&mut self, color: C) -> &mut StandardMaterialBuilder{
self.emissive_color = Some(color.to_rgb().to_linear().into());
self
}
pub fn base_color_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.base_color_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn normal_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.normal_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn occlusion_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.occlusion_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn metallic_roughness_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.metallic_roughness_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn metallic_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.metallic_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn roughness_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.roughness_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn emissive_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.emissive_map = Some(Parameter::new(Some(texture.into())));
self
}
fn check_material(&self) -> Result<(), String> {
if self.metallic_roughness_map.as_ref().map(|map| map.is_some()).unwrap_or(false)
&& self.metallic_roughness_map.as_ref().map(|map| map.is_some()).unwrap_or(false)
&& self.roughness_map.as_ref().map(|map| map.is_some()).unwrap_or(false)
{
Err("A material cant have both material_roughness_map and separate metallic or roughness maps".to_owned())
}else{
Ok(())
}
}
pub fn build(&mut self) -> StandardMaterial{
self._build().unwrap()
}
}
#[derive(Debug, Builder, Material, Clone)]
#[builder(build_fn(name = "_build", private))]
#[material(default)]
#[builder(default)]
#[builder(setter(into))]
pub struct LambertMaterial{
#[builder(setter(name = "base_color_map_opt"))]
pub base_color_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "normal_map_opt"))]
pub normal_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "occlusion_map_opt"))]
pub occlusion_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "roughness_map_opt"))]
pub roughness_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "emissive_map_opt"))]
pub emissive_map: Parameter<Option<TextureSampler>>,
#[material(not_data)]
base_color_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
normal_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
occlusion_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
metallic_roughness_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
emissive_map_matrix: Parameter<Option<Mat4>>,
#[doc = "hidden"]
#[material(default="Rgba::new(Rgb::new(1., 1., 1.), 1.)")]
#[builder(private)]
#[builder(setter(name = "hidden_base_color"))]
pub base_color: Parameter<Rgba<f32, LinearRgb>>,
#[doc = "hidden"]
#[material(default="Rgb::new(0., 0., 0.)")]
#[builder(private)]
#[builder(setter(name = "hidden_emissive_color"))]
pub emissive_color: Parameter<Rgb<f32, LinearRgb>>,
#[material(default = 0.5)]
#[material(not_data)]
pub roughness: Parameter<f32>,
#[material(not_data)]
pub double_sided: Parameter<bool>,
#[material(default = 1.)]
pub normal_scale: Parameter<f32>,
#[material(not_data)]
pub alpha_type: Parameter<AlphaType>,
#[material(not_data)]
pub shader_precision: Parameter<super::ShaderPrecision>,
#[material(not_data)]
pub override_translucent: Parameter<Option<bool>>,
#[material(not_data)]
pub debug_texcoords: Parameter<bool>,
#[material(not_data)]
pub debug_normals: Parameter<bool>,
}
impl LambertMaterialBuilder{
pub fn new() -> Self {
Self::default()
}
pub fn color<C: ToRgba>(&mut self, color: C) -> &mut LambertMaterialBuilder{
self.base_color = Some(Parameter::new(color.to_rgba().to_linear()));
self
}
pub fn emissive_color<C: ToRgb>(&mut self, color: C) -> &mut LambertMaterialBuilder{
self.emissive_color = Some(Parameter::new(color.to_rgb().to_linear()));
self
}
pub fn base_color_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.base_color_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn normal_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.normal_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn occlusion_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.occlusion_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn roughness_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.roughness_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn emissive_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.emissive_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn build(&mut self) -> LambertMaterial{
self._build().unwrap()
}
}
#[derive(Debug, Builder, Material, Clone)]
#[builder(build_fn(name = "_build", private, validate = "Self::check_material"))]
#[material(default)]
#[builder(default)]
#[builder(setter(into))]
pub struct AnisotropicMaterial{
#[builder(setter(name = "base_color_map_opt"))]
pub base_color_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "normal_map_opt"))]
pub normal_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "occlusion_map_opt"))]
pub occlusion_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "metallic_roughness_map_opt"))]
pub metallic_roughness_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "metallic_map_opt"))]
pub metallic_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "roughness_map_opt"))]
pub roughness_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "emissive_map_opt"))]
pub emissive_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "anisotropy_map_opt"))]
pub anisotropy_map: Parameter<Option<TextureSampler>>,
#[material(not_data)]
base_color_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
normal_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
occlusion_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
metallic_roughness_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
emissive_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
anisotropy_map_matrix: Parameter<Option<Mat4>>,
#[doc = "hidden"]
#[material(default="Rgba::new(Rgb::new(1., 1., 1.), 1.)")]
#[builder(private)]
#[builder(setter(name = "hidden_base_color"))]
pub base_color: Parameter<Rgba<f32, LinearRgb>>,
#[doc = "hidden"]
#[material(default="Rgb::new(0., 0., 0.)")]
#[builder(private)]
#[builder(setter(name = "hidden_emissive_color"))]
pub emissive_color: Parameter<Rgb<f32, LinearRgb>>,
#[material(default = 1.)]
pub normal_scale: Parameter<f32>,
#[material(default = 0.5)]
pub roughness: Parameter<f32>,
#[material(default = 0.)]
pub metallic: Parameter<f32>,
#[material(default = 0.5)]
pub reflectance: Parameter<f32>,
#[material(default = 0.)]
pub reflectance_tint: Parameter<f32>,
pub anisotropy: Parameter<f32>,
pub anisotropic_rotation: Parameter<Rad<f32>>,
#[material(not_data)]
pub double_sided: Parameter<bool>,
#[material(not_data)]
pub alpha_type: Parameter<AlphaType>,
#[material(not_data)]
pub shader_precision: Parameter<super::ShaderPrecision>,
#[material(not_data)]
pub override_translucent: Parameter<Option<bool>>,
#[material(not_data)]
pub debug_texcoords: Parameter<bool>,
#[material(not_data)]
pub debug_normals: Parameter<bool>,
}
impl AnisotropicMaterialBuilder{
pub fn new() -> Self {
Self::default()
}
pub fn color<C: ToRgba>(&mut self, color: C) -> &mut AnisotropicMaterialBuilder{
self.base_color = Some(Parameter::new(color.to_rgba().to_linear()));
self
}
pub fn emissive_color<C: ToRgb>(&mut self, color: C) -> &mut AnisotropicMaterialBuilder{
self.emissive_color = Some(Parameter::new(color.to_rgb().to_linear()));
self
}
pub fn base_color_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.base_color_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn normal_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.normal_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn anisotropy_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.anisotropy_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn occlusion_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.occlusion_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn metallic_roughness_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.metallic_roughness_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn metallic_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.metallic_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn roughness_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.roughness_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn emissive_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.emissive_map = Some(Parameter::new(Some(texture.into())));
self
}
fn check_material(&self) -> Result<(), String> {
if self.metallic_roughness_map.as_ref().map(|map| map.is_some()).unwrap_or(false)
&& self.metallic_roughness_map.as_ref().map(|map| map.is_some()).unwrap_or(false)
&& self.roughness_map.as_ref().map(|map| map.is_some()).unwrap_or(false)
{
Err("A material cant have both material_roughness_map and separate metallic or roughness maps".to_owned())
}else{
Ok(())
}
}
pub fn build(&mut self) -> AnisotropicMaterial{
self._build().unwrap()
}
}
#[derive(Debug, Builder, Material, Clone)]
#[builder(build_fn(name = "_build", private))]
#[material(default)]
#[builder(default)]
#[builder(setter(into))]
pub struct ClothMaterial{
#[builder(setter(name = "base_color_map_opt"))]
pub base_color_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "normal_map_opt"))]
pub normal_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "occlusion_map_opt"))]
pub occlusion_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "emissive_map_opt"))]
pub emissive_map: Parameter<Option<TextureSampler>>,
#[material(not_data)]
base_color_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
normal_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
occlusion_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
emissive_map_matrix: Parameter<Option<Mat4>>,
#[doc = "hidden"]
#[material(default = "Rgba::new(Rgb::new(1., 1., 1.), 1.)")]
#[builder(private)]
#[builder(setter(name = "hidden_base_color"))]
pub base_color: Parameter<Rgba<f32, LinearRgb>>,
#[doc = "hidden"]
#[material(default = "Rgba::new(Rgb::new(0.04, 0.04, 0.04), 1.)")]
#[builder(private)]
#[builder(setter(name = "hidden_sheen_color"))]
pub sheen_color: Parameter<Rgba<f32, LinearRgb>>,
#[doc = "hidden"]
#[material(default="Rgb::new(0., 0., 0.)")]
#[builder(private)]
#[builder(setter(name = "hidden_emissive_color"))]
pub emissive_color: Parameter<Rgb<f32, LinearRgb>>,
#[material(default = "0.5")]
pub roughness: Parameter<f32>,
#[material(not_data)]
pub double_sided: Parameter<bool>,
#[material(default = "1.")]
pub normal_scale: Parameter<f32>,
#[material(not_data)]
pub alpha_type: Parameter<AlphaType>,
#[material(not_data)]
pub shader_precision: Parameter<super::ShaderPrecision>,
#[material(not_data)]
pub override_translucent: Parameter<Option<bool>>,
#[material(not_data)]
pub debug_texcoords: Parameter<bool>,
#[material(not_data)]
pub debug_normals: Parameter<bool>,
}
impl ClothMaterialBuilder{
pub fn new() -> Self {
Self::default()
}
pub fn color<C: ToRgba>(&mut self, color: C) -> &mut ClothMaterialBuilder{
self.base_color = Some(Parameter::new(color.to_rgba().to_linear()));
self
}
pub fn sheen_color<C: ToRgba>(&mut self, color: C) -> &mut ClothMaterialBuilder{
self.sheen_color = Some(Parameter::new(color.to_rgba().to_linear()));
self
}
pub fn emissive_color<C: ToRgb>(&mut self, color: C) -> &mut ClothMaterialBuilder{
self.emissive_color = Some(Parameter::new(color.to_rgb().to_linear()));
self
}
pub fn base_color_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.base_color_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn normal_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.normal_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn occlusion_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.occlusion_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn emissive_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.emissive_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn build(&mut self) -> ClothMaterial{
self._build().unwrap()
}
}
#[derive(Debug, Builder, Material, Clone)]
#[builder(build_fn(name = "_build", private))]
#[material(default)]
#[builder(default)]
#[builder(setter(into))]
pub struct ClothSubsurfaceMaterial{
#[builder(setter(name = "base_color_map_opt"))]
pub base_color_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "normal_map_opt"))]
pub normal_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "occlusion_map_opt"))]
pub occlusion_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "emissive_map_opt"))]
pub emissive_map: Parameter<Option<TextureSampler>>,
#[material(not_data)]
base_color_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
normal_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
occlusion_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
emissive_map_matrix: Parameter<Option<Mat4>>,
#[doc = "hidden"]
#[material(default = "Rgba::new(Rgb::new(1., 1., 1.), 1.)")]
#[builder(private)]
#[builder(setter(name = "hidden_base_color"))]
pub base_color: Parameter<Rgba<f32, LinearRgb>>,
#[doc = "hidden"]
#[material(default = "Rgba::new(Rgb::new(0.04, 0.04, 0.04), 1.)")]
#[builder(private)]
#[builder(setter(name = "hidden_sheen_color"))]
pub sheen_color: Parameter<Rgba<f32, LinearRgb>>,
#[doc = "hidden"]
#[material(default = "Rgba::new(Rgb::new(1., 1., 1.), 1.)")]
#[builder(private)]
#[builder(setter(name = "hidden_subsurface_color"))]
pub subsurface_color: Parameter<Rgba<f32, LinearRgb>>,
#[doc = "hidden"]
#[material(default="Rgb::new(0., 0., 0.)")]
#[builder(private)]
#[builder(setter(name = "hidden_emissive_color"))]
pub emissive_color: Parameter<Rgb<f32, LinearRgb>>,
#[material(default = "0.5")]
pub roughness: Parameter<f32>,
#[material(not_data)]
pub double_sided: Parameter<bool>,
#[material(default = "1.")]
pub normal_scale: Parameter<f32>,
#[material(not_data)]
pub alpha_type: Parameter<AlphaType>,
#[material(not_data)]
pub shader_precision: Parameter<super::ShaderPrecision>,
#[material(not_data)]
pub override_translucent: Parameter<Option<bool>>,
#[material(not_data)]
pub debug_texcoords: Parameter<bool>,
#[material(not_data)]
pub debug_normals: Parameter<bool>,
}
impl ClothSubsurfaceMaterialBuilder{
pub fn new() -> Self {
Self::default()
}
pub fn color<C: ToRgba>(&mut self, color: C) -> &mut ClothSubsurfaceMaterialBuilder{
self.base_color = Some(Parameter::new(color.to_rgba().to_linear()));
self
}
pub fn sheen_color<C: ToRgba>(&mut self, color: C) -> &mut ClothSubsurfaceMaterialBuilder{
self.sheen_color = Some(Parameter::new(color.to_rgba().to_linear()));
self
}
pub fn subsurface_color<C: ToRgba>(&mut self, color: C) -> &mut ClothSubsurfaceMaterialBuilder{
self.subsurface_color = Some(Parameter::new(color.to_rgba().to_linear()));
self
}
pub fn emissive_color<C: ToRgb>(&mut self, color: C) -> &mut ClothSubsurfaceMaterialBuilder{
self.emissive_color = Some(Parameter::new(color.to_rgb().to_linear()));
self
}
pub fn base_color_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.base_color_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn normal_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.normal_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn occlusion_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.occlusion_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn emissive_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.emissive_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn build(&mut self) -> ClothSubsurfaceMaterial{
self._build().unwrap()
}
}
#[derive(Debug, Builder, Material, Clone)]
#[builder(build_fn(name = "_build", private, validate = "Self::check_material"))]
#[material(default)]
#[builder(default)]
#[builder(setter(into))]
pub struct SubsurfaceMaterial{
#[builder(setter(name = "base_color_map_opt"))]
pub base_color_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "normal_map_opt"))]
pub normal_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "occlusion_map_opt"))]
pub occlusion_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "metallic_roughness_map_opt"))]
pub metallic_roughness_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "metallic_map_opt"))]
pub metallic_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "roughness_map_opt"))]
pub roughness_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "emissive_map_opt"))]
pub emissive_map: Parameter<Option<TextureSampler>>,
#[material(not_data)]
base_color_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
normal_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
occlusion_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
metallic_roughness_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
emissive_map_matrix: Parameter<Option<Mat4>>,
#[doc = "hidden"]
#[material(default = "Rgba::new(Rgb::new(1., 1., 1.), 1.)")]
#[builder(private)]
#[builder(setter(name = "hidden_base_color"))]
pub base_color: Parameter<Rgba<f32, LinearRgb>>,
#[doc = "hidden"]
#[material(default = "Rgba::new(Rgb::new(1., 1., 1.), 1.)")]
#[builder(private)]
#[builder(setter(name = "hidden_subsurface_color"))]
pub subsurface_color: Parameter<Rgba<f32, LinearRgb>>,
#[doc = "hidden"]
#[material(default="Rgb::new(0., 0., 0.)")]
#[builder(private)]
#[builder(setter(name = "hidden_emissive_color"))]
pub emissive_color: Parameter<Rgb<f32, LinearRgb>>,
#[material(default = "12.234")]
pub subsurface_power: Parameter<f32>,
#[material(default = "0.5")]
pub thickness: Parameter<f32>,
#[material(default = "0.5")]
pub roughness: Parameter<f32>,
#[material(default = "0.0")]
pub metallic: Parameter<f32>,
#[material(default = "0.5")]
pub reflectance: Parameter<f32>,
#[material(default = "0.0")]
pub reflectance_tint: Parameter<f32>,
#[material(not_data)]
pub double_sided: Parameter<bool>,
#[material(default = "1.")]
pub normal_scale: Parameter<f32>,
#[material(not_data)]
pub alpha_type: Parameter<AlphaType>,
#[material(not_data)]
pub shader_precision: Parameter<super::ShaderPrecision>,
#[material(not_data)]
pub override_translucent: Parameter<Option<bool>>,
#[material(not_data)]
pub debug_texcoords: Parameter<bool>,
#[material(not_data)]
pub debug_normals: Parameter<bool>,
}
impl SubsurfaceMaterialBuilder{
pub fn new() -> Self {
Self::default()
}
pub fn color<C: ToRgba>(&mut self, color: C) -> &mut SubsurfaceMaterialBuilder{
self.base_color = Some(Parameter::new(color.to_rgba().to_linear()));
self
}
pub fn subsurface_color<C: ToRgba>(&mut self, color: C) -> &mut SubsurfaceMaterialBuilder{
self.subsurface_color = Some(Parameter::new(color.to_rgba().to_linear()));
self
}
pub fn emissive_color<C: ToRgb>(&mut self, color: C) -> &mut SubsurfaceMaterialBuilder{
self.emissive_color = Some(Parameter::new(color.to_rgb().to_linear()));
self
}
pub fn base_color_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.base_color_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn normal_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.normal_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn occlusion_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.occlusion_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn metallic_roughness_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.metallic_roughness_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn metallic_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.metallic_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn roughness_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.roughness_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn emissive_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.emissive_map = Some(Parameter::new(Some(texture.into())));
self
}
fn check_material(&self) -> Result<(), String> {
if self.metallic_roughness_map.as_ref().map(|map| map.is_some()).unwrap_or(false)
&& self.metallic_roughness_map.as_ref().map(|map| map.is_some()).unwrap_or(false)
&& self.roughness_map.as_ref().map(|map| map.is_some()).unwrap_or(false)
{
Err("A material cant have both material_roughness_map and separate metallic or roughness maps".to_owned())
}else{
Ok(())
}
}
pub fn build(&mut self) -> SubsurfaceMaterial{
self._build().unwrap()
}
}
#[derive(Debug, Builder, Material, Clone)]
#[builder(build_fn(name = "_build", private, validate = "Self::check_material"))]
#[material(default)]
#[builder(default)]
#[builder(setter(into))]
pub struct ClearcoatMaterial{
#[builder(setter(name = "base_color_map_opt"))]
pub base_color_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "normal_map_opt"))]
pub normal_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "occlusion_map_opt"))]
pub occlusion_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "metallic_roughness_map_opt"))]
pub metallic_roughness_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "metallic_map_opt"))]
pub metallic_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "roughness_map_opt"))]
pub roughness_map: Parameter<Option<TextureSampler>>,
#[builder(setter(name = "emissive_map_opt"))]
pub emissive_map: Parameter<Option<TextureSampler>>,
#[material(not_data)]
base_color_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
normal_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
occlusion_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
metallic_roughness_map_matrix: Parameter<Option<Mat4>>,
#[material(not_data)]
emissive_map_matrix: Parameter<Option<Mat4>>,
#[doc = "hidden"]
#[material(default = "Rgba::new(Rgb::new(1., 1., 1.), 1.)")]
#[builder(private)]
#[builder(setter(name = "hidden_base_color"))]
pub base_color: Parameter<Rgba<f32, LinearRgb>>,
#[doc = "hidden"]
#[material(default="Rgb::new(0., 0., 0.)")]
#[builder(private)]
#[builder(setter(name = "hidden_emissive_color"))]
pub emissive_color: Parameter<Rgb<f32, LinearRgb>>,
#[material(default = "0.5")]
pub roughness: Parameter<f32>,
#[material(default = "0.0")]
pub metallic: Parameter<f32>,
#[material(default = "0.5")]
pub reflectance: Parameter<f32>,
#[material(default = "0.0")]
pub reflectance_tint: Parameter<f32>,
#[material(default = "0.0")]
pub clearcoat: Parameter<f32>,
#[material(default = "0.5")]
pub clearcoat_roughness: Parameter<f32>,
#[material(not_data)]
pub double_sided: Parameter<bool>,
#[material(default = "1.")]
pub normal_scale: Parameter<f32>,
#[material(not_data)]
pub alpha_type: Parameter<AlphaType>,
#[material(not_data)]
pub shader_precision: Parameter<super::ShaderPrecision>,
#[material(not_data)]
pub override_translucent: Parameter<Option<bool>>,
#[material(not_data)]
pub debug_texcoords: Parameter<bool>,
#[material(not_data)]
pub debug_normals: Parameter<bool>,
}
impl ClearcoatMaterialBuilder{
pub fn new() -> Self {
Self::default()
}
pub fn color<C: ToRgba>(&mut self, color: C) -> &mut ClearcoatMaterialBuilder{
self.base_color = Some(Parameter::new(color.to_rgba().to_linear()));
self
}
pub fn emissive_color<C: ToRgb>(&mut self, color: C) -> &mut ClearcoatMaterialBuilder{
self.emissive_color = Some(Parameter::new(color.to_rgb().to_linear()));
self
}
pub fn base_color_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.base_color_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn normal_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.normal_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn occlusion_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.occlusion_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn metallic_roughness_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.metallic_roughness_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn metallic_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.metallic_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn roughness_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.roughness_map = Some(Parameter::new(Some(texture.into())));
self
}
pub fn emissive_map<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut Self{
self.emissive_map = Some(Parameter::new(Some(texture.into())));
self
}
fn check_material(&self) -> Result<(), String> {
if self.metallic_roughness_map.as_ref().map(|map| map.is_some()).unwrap_or(false)
&& self.metallic_roughness_map.as_ref().map(|map| map.is_some()).unwrap_or(false)
&& self.roughness_map.as_ref().map(|map| map.is_some()).unwrap_or(false)
{
Err("A material cant have both material_roughness_map and separate metallic or roughness maps".to_owned())
}else{
Ok(())
}
}
pub fn build(&mut self) -> ClearcoatMaterial{
self._build().unwrap()
}
}
pub trait PbrMaterial{
fn base_color(&self) -> &Parameter<Rgba<f32, LinearRgb>>;
fn metallic_roughness_map(&self) -> Parameter<Option<&TextureSampler>>;
fn metallic_map(&self) -> Parameter<Option<&TextureSampler>>;
fn roughness_map(&self) -> Parameter<Option<&TextureSampler>>;
fn base_color_map(&self) -> Parameter<Option<&TextureSampler>>;
fn normal_map(&self) -> Parameter<Option<&TextureSampler>>;
fn emissive_map(&self) -> Parameter<Option<&TextureSampler>>;
fn anisotropy_map(&self) -> Parameter<Option<&TextureSampler>>;
fn occlusion_map(&self) -> Parameter<Option<&TextureSampler>>;
fn alpha_ty(&self) -> &Parameter<AlphaType>;
fn pbr_material_type(&self) -> MaterialType;
fn is_double_sided(&self) -> &Parameter<bool>;
fn normal_scale(&self) -> &Parameter<f32>;
fn base_color_alpha(&self) -> f32;
fn shader_precision(&self) -> &Parameter<super::ShaderPrecision>;
fn override_translucent(&self) -> &Parameter<Option<bool>>;
fn debug_texcoords(&self) -> &Parameter<bool>;
fn debug_normals(&self) -> &Parameter<bool>;
}
impl PbrMaterial for StandardMaterial{
fn base_color(&self) -> &Parameter<Rgba<f32, LinearRgb>>{
&self.base_color
}
fn metallic_roughness_map(&self) -> Parameter<Option<&TextureSampler>>{
self.metallic_roughness_map.as_ref().map(|t| t.as_ref())
}
fn metallic_map(&self) -> Parameter<Option<&TextureSampler>>{
self.metallic_map.as_ref().map(|t| t.as_ref())
}
fn roughness_map(&self) -> Parameter<Option<&TextureSampler>>{
self.roughness_map.as_ref().map(|t| t.as_ref())
}
fn base_color_map(&self) -> Parameter<Option<&TextureSampler>>{
self.base_color_map.as_ref().map(|t| t.as_ref())
}
fn normal_map(&self) -> Parameter<Option<&TextureSampler>>{
self.normal_map.as_ref().map(|t| t.as_ref())
}
fn emissive_map(&self) -> Parameter<Option<&TextureSampler>>{
self.emissive_map.as_ref().map(|t| t.as_ref())
}
fn occlusion_map(&self) -> Parameter<Option<&TextureSampler>>{
self.occlusion_map.as_ref().map(|t| t.as_ref())
}
fn anisotropy_map(&self) -> Parameter<Option<&TextureSampler>>{
Parameter::new(None)
}
fn alpha_ty(&self) -> &Parameter<AlphaType>{
&self.alpha_type
}
fn normal_scale(&self) -> &Parameter<f32>{
&self.normal_scale
}
fn pbr_material_type(&self) -> MaterialType {
MaterialType::Standard
}
fn is_double_sided(&self) -> &Parameter<bool>{
&self.double_sided
}
fn base_color_alpha(&self) -> f32{
match *self.alpha_type{
AlphaType::None => 1.,
AlphaType::AlphaToCoverage
| AlphaType::Blending
| AlphaType::ScreenDoor
| AlphaType::BlendingFactors(_,_) => self.base_color.a,
AlphaType::Threshold => if self.base_color.a > 0.5 { 1. } else { 0. }
}
}
fn shader_precision(&self) -> &Parameter<super::ShaderPrecision>{
&self.shader_precision
}
fn override_translucent(&self) -> &Parameter<Option<bool>>{
&self.override_translucent
}
fn debug_texcoords(&self) -> &Parameter<bool>{
&self.debug_texcoords
}
fn debug_normals(&self) -> &Parameter<bool>{
&self.debug_normals
}
}
impl PbrMaterial for LambertMaterial{
fn base_color(&self) -> &Parameter<Rgba<f32, LinearRgb>>{
&self.base_color
}
fn metallic_roughness_map(&self) -> Parameter<Option<&TextureSampler>>{
Parameter::new(None)
}
fn metallic_map(&self) -> Parameter<Option<&TextureSampler>>{
Parameter::new(None)
}
fn roughness_map(&self) -> Parameter<Option<&TextureSampler>>{
self.roughness_map.as_ref().map(|t| t.as_ref())
}
fn base_color_map(&self) -> Parameter<Option<&TextureSampler>>{
self.base_color_map.as_ref().map(|t| t.as_ref())
}
fn normal_map(&self) -> Parameter<Option<&TextureSampler>>{
self.normal_map.as_ref().map(|t| t.as_ref())
}
fn emissive_map(&self) -> Parameter<Option<&TextureSampler>>{
self.emissive_map.as_ref().map(|t| t.as_ref())
}
fn occlusion_map(&self) -> Parameter<Option<&TextureSampler>>{
self.occlusion_map.as_ref().map(|t| t.as_ref())
}
fn anisotropy_map(&self) -> Parameter<Option<&TextureSampler>>{
Parameter::new(None)
}
fn alpha_ty(&self) -> &Parameter<AlphaType>{
&self.alpha_type
}
fn normal_scale(&self) -> &Parameter<f32>{
&self.normal_scale
}
fn pbr_material_type(&self) -> MaterialType {
MaterialType::Lambert
}
fn is_double_sided(&self) -> &Parameter<bool>{
&self.double_sided
}
fn base_color_alpha(&self) -> f32{
match *self.alpha_type{
AlphaType::None => 1.,
AlphaType::AlphaToCoverage
| AlphaType::Blending
| AlphaType::ScreenDoor
| AlphaType::BlendingFactors(_,_) => self.base_color.a,
AlphaType::Threshold => if self.base_color.a > 0.5 { 1. } else { 0. }
}
}
fn shader_precision(&self) -> &Parameter<super::ShaderPrecision>{
&self.shader_precision
}
fn override_translucent(&self) -> &Parameter<Option<bool>>{
&self.override_translucent
}
fn debug_texcoords(&self) -> &Parameter<bool>{
&self.debug_texcoords
}
fn debug_normals(&self) -> &Parameter<bool>{
&self.debug_normals
}
}
impl PbrMaterial for AnisotropicMaterial{
fn base_color(&self) -> &Parameter<Rgba<f32, LinearRgb>>{
&self.base_color
}
fn metallic_roughness_map(&self) -> Parameter<Option<&TextureSampler>>{
self.metallic_roughness_map.as_ref().map(|t| t.as_ref())
}
fn metallic_map(&self) -> Parameter<Option<&TextureSampler>>{
self.metallic_map.as_ref().map(|t| t.as_ref())
}
fn roughness_map(&self) -> Parameter<Option<&TextureSampler>>{
self.roughness_map.as_ref().map(|t| t.as_ref())
}
fn base_color_map(&self) -> Parameter<Option<&TextureSampler>>{
self.base_color_map.as_ref().map(|t| t.as_ref())
}
fn normal_map(&self) -> Parameter<Option<&TextureSampler>>{
self.normal_map.as_ref().map(|t| t.as_ref())
}
fn emissive_map(&self) -> Parameter<Option<&TextureSampler>>{
self.emissive_map.as_ref().map(|t| t.as_ref())
}
fn occlusion_map(&self) -> Parameter<Option<&TextureSampler>>{
self.occlusion_map.as_ref().map(|t| t.as_ref())
}
fn anisotropy_map(&self) -> Parameter<Option<&TextureSampler>>{
self.anisotropy_map.as_ref().map(|t| t.as_ref())
}
fn alpha_ty(&self) -> &Parameter<AlphaType>{
&self.alpha_type
}
fn normal_scale(&self) -> &Parameter<f32>{
&self.normal_scale
}
fn pbr_material_type(&self) -> MaterialType {
MaterialType::Anisotropic
}
fn is_double_sided(&self) -> &Parameter<bool>{
&self.double_sided
}
fn base_color_alpha(&self) -> f32{
match *self.alpha_type{
AlphaType::None => 1.,
AlphaType::AlphaToCoverage
| AlphaType::Blending
| AlphaType::ScreenDoor
| AlphaType::BlendingFactors(_,_) => self.base_color.a,
AlphaType::Threshold => if self.base_color.a > 0.5 { 1. } else { 0. }
}
}
fn shader_precision(&self) -> &Parameter<super::ShaderPrecision>{
&self.shader_precision
}
fn override_translucent(&self) -> &Parameter<Option<bool>>{
&self.override_translucent
}
fn debug_texcoords(&self) -> &Parameter<bool>{
&self.debug_texcoords
}
fn debug_normals(&self) -> &Parameter<bool>{
&self.debug_normals
}
}
impl PbrMaterial for ClothMaterial{
fn base_color(&self) -> &Parameter<Rgba<f32, LinearRgb>>{
&self.base_color
}
fn metallic_roughness_map(&self) -> Parameter<Option<&TextureSampler>>{
Parameter::new(None)
}
fn metallic_map(&self) -> Parameter<Option<&TextureSampler>>{
Parameter::new(None)
}
fn roughness_map(&self) -> Parameter<Option<&TextureSampler>>{
Parameter::new(None)
}
fn base_color_map(&self) -> Parameter<Option<&TextureSampler>>{
self.base_color_map.as_ref().map(|t| t.as_ref())
}
fn normal_map(&self) -> Parameter<Option<&TextureSampler>>{
self.normal_map.as_ref().map(|t| t.as_ref())
}
fn emissive_map(&self) -> Parameter<Option<&TextureSampler>>{
self.emissive_map.as_ref().map(|t| t.as_ref())
}
fn occlusion_map(&self) -> Parameter<Option<&TextureSampler>>{
self.occlusion_map.as_ref().map(|t| t.as_ref())
}
fn anisotropy_map(&self) -> Parameter<Option<&TextureSampler>>{
Parameter::new(None)
}
fn alpha_ty(&self) -> &Parameter<AlphaType>{
&self.alpha_type
}
fn normal_scale(&self) -> &Parameter<f32>{
&self.normal_scale
}
fn pbr_material_type(&self) -> MaterialType {
MaterialType::Cloth
}
fn is_double_sided(&self) -> &Parameter<bool>{
&self.double_sided
}
fn base_color_alpha(&self) -> f32{
match *self.alpha_type{
AlphaType::None => 1.,
AlphaType::AlphaToCoverage
| AlphaType::Blending
| AlphaType::ScreenDoor
| AlphaType::BlendingFactors(_,_) => self.base_color.a,
AlphaType::Threshold => if self.base_color.a > 0.5 { 1. } else { 0. }
}
}
fn shader_precision(&self) -> &Parameter<super::ShaderPrecision>{
&self.shader_precision
}
fn override_translucent(&self) -> &Parameter<Option<bool>>{
&self.override_translucent
}
fn debug_texcoords(&self) -> &Parameter<bool>{
&self.debug_texcoords
}
fn debug_normals(&self) -> &Parameter<bool>{
&self.debug_normals
}
}
impl PbrMaterial for ClothSubsurfaceMaterial{
fn base_color(&self) -> &Parameter<Rgba<f32, LinearRgb>>{
&self.base_color
}
fn metallic_roughness_map(&self) -> Parameter<Option<&TextureSampler>>{
Parameter::new(None)
}
fn metallic_map(&self) -> Parameter<Option<&TextureSampler>>{
Parameter::new(None)
}
fn roughness_map(&self) -> Parameter<Option<&TextureSampler>>{
Parameter::new(None)
}
fn base_color_map(&self) -> Parameter<Option<&TextureSampler>>{
self.base_color_map.as_ref().map(|t| t.as_ref())
}
fn normal_map(&self) -> Parameter<Option<&TextureSampler>>{
self.normal_map.as_ref().map(|t| t.as_ref())
}
fn emissive_map(&self) -> Parameter<Option<&TextureSampler>>{
self.emissive_map.as_ref().map(|t| t.as_ref())
}
fn occlusion_map(&self) -> Parameter<Option<&TextureSampler>>{
self.occlusion_map.as_ref().map(|t| t.as_ref())
}
fn anisotropy_map(&self) -> Parameter<Option<&TextureSampler>>{
Parameter::new(None)
}
fn alpha_ty(&self) -> &Parameter<AlphaType>{
&self.alpha_type
}
fn normal_scale(&self) -> &Parameter<f32>{
&self.normal_scale
}
fn pbr_material_type(&self) -> MaterialType {
MaterialType::ClothSubsurface
}
fn is_double_sided(&self) -> &Parameter<bool>{
&self.double_sided
}
fn base_color_alpha(&self) -> f32{
match *self.alpha_type{
AlphaType::None => 1.,
AlphaType::AlphaToCoverage
| AlphaType::Blending
| AlphaType::ScreenDoor
| AlphaType::BlendingFactors(_,_) => self.base_color.a,
AlphaType::Threshold => if self.base_color.a > 0.5 { 1. } else { 0. }
}
}
fn shader_precision(&self) -> &Parameter<super::ShaderPrecision>{
&self.shader_precision
}
fn override_translucent(&self) -> &Parameter<Option<bool>>{
&self.override_translucent
}
fn debug_texcoords(&self) -> &Parameter<bool>{
&self.debug_texcoords
}
fn debug_normals(&self) -> &Parameter<bool>{
&self.debug_normals
}
}
impl PbrMaterial for SubsurfaceMaterial{
fn base_color(&self) -> &Parameter<Rgba<f32, LinearRgb>>{
&self.base_color
}
fn metallic_roughness_map(&self) -> Parameter<Option<&TextureSampler>>{
self.metallic_roughness_map.as_ref().map(|t| t.as_ref())
}
fn metallic_map(&self) -> Parameter<Option<&TextureSampler>>{
self.metallic_map.as_ref().map(|t| t.as_ref())
}
fn roughness_map(&self) -> Parameter<Option<&TextureSampler>>{
self.roughness_map.as_ref().map(|t| t.as_ref())
}
fn base_color_map(&self) -> Parameter<Option<&TextureSampler>>{
self.base_color_map.as_ref().map(|t| t.as_ref())
}
fn normal_map(&self) -> Parameter<Option<&TextureSampler>>{
self.normal_map.as_ref().map(|t| t.as_ref())
}
fn emissive_map(&self) -> Parameter<Option<&TextureSampler>>{
self.emissive_map.as_ref().map(|t| t.as_ref())
}
fn occlusion_map(&self) -> Parameter<Option<&TextureSampler>>{
self.occlusion_map.as_ref().map(|t| t.as_ref())
}
fn anisotropy_map(&self) -> Parameter<Option<&TextureSampler>>{
Parameter::new(None)
}
fn alpha_ty(&self) -> &Parameter<AlphaType>{
&self.alpha_type
}
fn normal_scale(&self) -> &Parameter<f32>{
&self.normal_scale
}
fn pbr_material_type(&self) -> MaterialType {
MaterialType::Subsurface
}
fn is_double_sided(&self) -> &Parameter<bool>{
&self.double_sided
}
fn base_color_alpha(&self) -> f32{
match *self.alpha_type{
AlphaType::None => 1.,
AlphaType::AlphaToCoverage
| AlphaType::Blending
| AlphaType::ScreenDoor
| AlphaType::BlendingFactors(_,_) => self.base_color.a,
AlphaType::Threshold => if self.base_color.a > 0.5 { 1. } else { 0. }
}
}
fn shader_precision(&self) -> &Parameter<super::ShaderPrecision>{
&self.shader_precision
}
fn override_translucent(&self) -> &Parameter<Option<bool>>{
&self.override_translucent
}
fn debug_texcoords(&self) -> &Parameter<bool>{
&self.debug_texcoords
}
fn debug_normals(&self) -> &Parameter<bool>{
&self.debug_normals
}
}
impl PbrMaterial for ClearcoatMaterial{
fn base_color(&self) -> &Parameter<Rgba<f32, LinearRgb>>{
&self.base_color
}
fn metallic_roughness_map(&self) -> Parameter<Option<&TextureSampler>>{
self.metallic_roughness_map.as_ref().map(|t| t.as_ref())
}
fn metallic_map(&self) -> Parameter<Option<&TextureSampler>>{
self.metallic_map.as_ref().map(|t| t.as_ref())
}
fn roughness_map(&self) -> Parameter<Option<&TextureSampler>>{
self.roughness_map.as_ref().map(|t| t.as_ref())
}
fn base_color_map(&self) -> Parameter<Option<&TextureSampler>>{
self.base_color_map.as_ref().map(|t| t.as_ref())
}
fn normal_map(&self) -> Parameter<Option<&TextureSampler>>{
self.normal_map.as_ref().map(|t| t.as_ref())
}
fn emissive_map(&self) -> Parameter<Option<&TextureSampler>>{
self.emissive_map.as_ref().map(|t| t.as_ref())
}
fn occlusion_map(&self) -> Parameter<Option<&TextureSampler>>{
self.occlusion_map.as_ref().map(|t| t.as_ref())
}
fn anisotropy_map(&self) -> Parameter<Option<&TextureSampler>>{
Parameter::new(None)
}
fn alpha_ty(&self) -> &Parameter<AlphaType>{
&self.alpha_type
}
fn normal_scale(&self) -> &Parameter<f32>{
&self.normal_scale
}
fn pbr_material_type(&self) -> MaterialType {
MaterialType::Clearcoat
}
fn is_double_sided(&self) -> &Parameter<bool>{
&self.double_sided
}
fn base_color_alpha(&self) -> f32{
match *self.alpha_type{
AlphaType::None => 1.,
AlphaType::AlphaToCoverage
| AlphaType::Blending
| AlphaType::ScreenDoor
| AlphaType::BlendingFactors(_,_) => self.base_color.a,
AlphaType::Threshold => if self.base_color.a > 0.5 { 1. } else { 0. }
}
}
fn shader_precision(&self) -> &Parameter<super::ShaderPrecision>{
&self.shader_precision
}
fn override_translucent(&self) -> &Parameter<Option<bool>>{
&self.override_translucent
}
fn debug_texcoords(&self) -> &Parameter<bool>{
&self.debug_texcoords
}
fn debug_normals(&self) -> &Parameter<bool>{
&self.debug_normals
}
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub enum MaterialType{
Lambert,
Standard,
Cloth,
ClothSubsurface,
Clearcoat,
Anisotropic,
Subsurface,
DisneyPrincipled,
}
impl ToString for MaterialType{
fn to_string(&self) -> String{
match self{
MaterialType::Lambert => "LAMBERT_MATERIAL",
MaterialType::Standard => "STANDARD_MATERIAL",
MaterialType::Cloth => "CLOTH_MATERIAL",
MaterialType::ClothSubsurface => "CLOTH_SUBSURFACE_MATERIAL",
MaterialType::Clearcoat => "CLEARCOAT_MATERIAL",
MaterialType::Anisotropic => "ANISOTROPIC_MATERIAL",
MaterialType::Subsurface => "SUBSURFACE_MATERIAL",
MaterialType::DisneyPrincipled => "DISNEY_PRINCIPLED_MATERIAL",
}.to_owned()
}
}
impl MaterialType {
pub fn is_cloth(self) -> bool {
match self{
MaterialType::Cloth | MaterialType::ClothSubsurface => true,
_ => false,
}
}
}