use color::Rgba;
use na::Mat4;
use angle::Rad;
use super::texture::TextureSampler;
use super::AlphaType;
use rin::color::*;
use super::parameter::*;
use crate::light::LightInfo;
#[derive(Debug, Builder)]
#[builder(build_fn(name = "BUILD", private))]
pub struct StandardMaterial{
#[builder(default)]
#[builder(setter(into))]
pub texture: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub normal_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub occlusion_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub metallic_roughness_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub emissive_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub texture_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub normal_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub occlusion_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub metallic_roughness_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub emissive_map_matrix: Option<Mat4>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 1., g: 1., b: 1.}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_base_color"))]
pub base_color: Rgba<f32>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 0., g: 0., b: 0.}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_emissive_color"))]
pub emissive_color: Rgba<f32>,
#[builder(default="0.5")]
pub roughness: f32,
#[builder(default="0.0")]
pub metallic: f32,
#[builder(default="0.5")]
pub reflectance: f32,
#[builder(default="0.0")]
pub reflectance_tint: f32,
#[builder(default="false")]
pub double_sided: bool,
#[builder(default="1.0")]
pub normal_scale: f32,
#[builder(default)]
pub alpha_type: AlphaType,
#[builder(default)]
#[builder(setter(skip))]
changed: Changed,
#[builder(default)]
#[builder(setter(skip))]
program_id: Option<ProgramId>,
}
impl StandardMaterialBuilder{
pub fn color<C: ToRgba>(&mut self, color: C) -> &mut StandardMaterialBuilder{
self.base_color = Some(color.to_rgba());
self
}
pub fn emissive_color<C: ToRgba>(&mut self, color: C) -> &mut StandardMaterialBuilder{
self.emissive_color = Some(color.to_rgba());
self
}
pub fn build(&mut self) -> StandardMaterial{
self.BUILD().unwrap()
}
}
impl super::Material for StandardMaterial{
fn parameters(&mut self) -> Vec<super::Parameter>{
vec![
Parameter::new("base_color", &mut self.base_color, &self.changed),
Parameter::new("emissive_color", &mut self.emissive_color, &self.changed),
Parameter::new("roughness", &mut self.roughness, &self.changed),
Parameter::new("metallic", &mut self.metallic, &self.changed),
Parameter::new("reflectance", &mut self.reflectance, &self.changed),
Parameter::new("reflectance_tint", &mut self.reflectance_tint, &self.changed),
Parameter::new("double_sided", &mut self.double_sided, &self.changed),
Parameter::new("normal_scale", &mut self.normal_scale, &self.changed),
Parameter::new("alpha_type", &mut self.alpha_type, &self.changed),
]
}
fn parameter(&mut self, name: &str) -> Option<Parameter>{
match name{
"base_color" => Some(Parameter::new("base_color", &mut self.base_color, &self.changed)),
"emissive_color" => Some(Parameter::new("emissive_color", &mut self.emissive_color, &self.changed)),
"roughness" => Some(Parameter::new("roughness", &mut self.roughness, &self.changed)),
"metallic" => Some(Parameter::new("metallic", &mut self.metallic, &self.changed)),
"reflectance" => Some(Parameter::new("reflectance", &mut self.reflectance, &self.changed)),
"reflectance_tint" => Some(Parameter::new("reflectance_tint", &mut self.reflectance_tint, &self.changed)),
"double_sided" => Some(Parameter::new("double_sided", &mut self.double_sided, &self.changed)),
"normal_scale" => Some(Parameter::new("normal_scale", &mut self.normal_scale, &self.changed)),
"alpha_type" => Some(Parameter::new("alpha_type", &mut self.alpha_type, &self.changed)),
_ => None
}
}
fn changed(&self) -> bool{
self.changed.changed()
}
fn reset_changed(&mut self){
self.changed.reset();
}
}
#[derive(Debug, Builder)]
#[builder(build_fn(name = "BUILD", private))]
pub struct LambertMaterial{
#[builder(default)]
#[builder(setter(into))]
pub texture: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub normal_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub occlusion_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub metallic_roughness_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub emissive_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub texture_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub normal_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub occlusion_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub metallic_roughness_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub emissive_map_matrix: Option<Mat4>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 1., g: 1., b: 1.}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_base_color"))]
pub base_color: Rgba<f32>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 0., g: 0., b: 0.}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_emissive_color"))]
pub emissive_color: Rgba<f32>,
#[builder(default="0.5")]
pub roughness: f32,
#[builder(default)]
pub double_sided: bool,
#[builder(default="1.")]
pub normal_scale: f32,
#[builder(default="AlphaType::None")]
pub alpha_type: AlphaType,
#[builder(default)]
#[builder(setter(skip))]
changed: Changed,
#[builder(default)]
#[builder(setter(skip))]
program_id: Option<ProgramId>,
}
impl LambertMaterialBuilder{
pub fn color<C: ToRgba>(&mut self, color: C) -> &mut LambertMaterialBuilder{
self.base_color = Some(color.to_rgba());
self
}
pub fn emissive_color<C: ToRgba>(&mut self, color: C) -> &mut LambertMaterialBuilder{
self.emissive_color = Some(color.to_rgba());
self
}
pub fn build(&mut self) -> LambertMaterial{
self.BUILD().unwrap()
}
}
impl super::Material for LambertMaterial{
fn parameters(&mut self) -> Vec<super::Parameter>{
vec![
Parameter::new("base_color", &mut self.base_color, &self.changed),
Parameter::new("emissive_color", &mut self.emissive_color, &self.changed),
Parameter::new("roughness", &mut self.roughness, &self.changed),
Parameter::new("double_sided", &mut self.double_sided, &self.changed),
Parameter::new("normal_scale", &mut self.normal_scale, &self.changed),
Parameter::new("alpha_type", &mut self.alpha_type, &self.changed),
]
}
fn parameter(&mut self, name: &str) -> Option<Parameter>{
match name{
"base_color" => Some(Parameter::new("base_color", &mut self.base_color, &self.changed)),
"emissive_color" => Some(Parameter::new("emissive_color", &mut self.emissive_color, &self.changed)),
"roughness" => Some(Parameter::new("roughness", &mut self.roughness, &self.changed)),
"double_sided" => Some(Parameter::new("double_sided", &mut self.double_sided, &self.changed)),
"normal_scale" => Some(Parameter::new("normal_scale", &mut self.normal_scale, &self.changed)),
"alpha_type" => Some(Parameter::new("alpha_type", &mut self.alpha_type, &self.changed)),
_ => None
}
}
fn changed(&self) -> bool{
self.changed.changed()
}
fn reset_changed(&mut self){
self.changed.reset();
}
}
#[derive(Debug, Builder)]
#[builder(build_fn(name = "BUILD", private))]
pub struct AnisotropicMaterial{
#[builder(default)]
#[builder(setter(into))]
pub texture: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub normal_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub occlusion_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub metallic_roughness_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub emissive_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub anisotropy_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub texture_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub normal_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub occlusion_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub metallic_roughness_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub emissive_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub anisotropy_map_matrix: Option<Mat4>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 1., g: 1., b: 1.}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_base_color"))]
pub base_color: Rgba<f32>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 0., g: 0., b: 0.}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_emissive_color"))]
pub emissive_color: Rgba<f32>,
#[builder(default="0.5")]
pub roughness: f32,
#[builder(default="0.0")]
pub metallic: f32,
#[builder(default="0.5")]
pub reflectance: f32,
#[builder(default="0.0")]
pub reflectance_tint: f32,
#[builder(default)]
pub anisotropy: f32,
#[builder(default)]
pub anisotropic_rotation: Rad<f32>,
#[builder(default)]
pub double_sided: bool,
#[builder(default="1.")]
pub normal_scale: f32,
#[builder(default)]
pub alpha_type: AlphaType,
#[builder(default)]
#[builder(setter(skip))]
changed: Changed,
#[builder(default)]
#[builder(setter(skip))]
program_id: Option<ProgramId>,
}
impl AnisotropicMaterialBuilder{
pub fn color<C: ToRgba>(&mut self, color: C) -> &mut AnisotropicMaterialBuilder{
self.base_color = Some(color.to_rgba());
self
}
pub fn emissive_color<C: ToRgba>(&mut self, color: C) -> &mut AnisotropicMaterialBuilder{
self.emissive_color = Some(color.to_rgba());
self
}
pub fn build(&mut self) -> AnisotropicMaterial{
self.BUILD().unwrap()
}
}
impl super::Material for AnisotropicMaterial{
fn parameters(&mut self) -> Vec<super::Parameter>{
vec![
Parameter::new("base_color", &mut self.base_color, &self.changed),
Parameter::new("emissive_color", &mut self.emissive_color, &self.changed),
Parameter::new("roughness", &mut self.roughness, &self.changed),
Parameter::new("metallic", &mut self.metallic, &self.changed),
Parameter::new("reflectance", &mut self.reflectance, &self.changed),
Parameter::new("reflectance_tint", &mut self.reflectance_tint, &self.changed),
Parameter::new("anisotropy", &mut self.anisotropy, &self.changed),
Parameter::new("anisotropic_rotation", &mut self.anisotropic_rotation, &self.changed),
Parameter::new("double_sided", &mut self.double_sided, &self.changed),
Parameter::new("normal_scale", &mut self.normal_scale, &self.changed),
Parameter::new("alpha_type", &mut self.alpha_type, &self.changed),
]
}
fn parameter(&mut self, name: &str) -> Option<Parameter>{
match name{
"base_color" => Some(Parameter::new("base_color", &mut self.base_color, &self.changed)),
"emissive_color" => Some(Parameter::new("emissive_color", &mut self.emissive_color, &self.changed)),
"roughness" => Some(Parameter::new("roughness", &mut self.roughness, &self.changed)),
"metallic" => Some(Parameter::new("metallic", &mut self.metallic, &self.changed)),
"reflectance" => Some(Parameter::new("reflectance", &mut self.reflectance, &self.changed)),
"reflectance_tint" => Some(Parameter::new("reflectance_tint", &mut self.reflectance_tint, &self.changed)),
"anisotropy" => Some(Parameter::new("anisotropy", &mut self.anisotropy, &self.changed)),
"anisotropic_rotation" => Some(Parameter::new("anisotropic_rotation", &mut self.anisotropic_rotation, &self.changed)),
"double_sided" => Some(Parameter::new("double_sided", &mut self.double_sided, &self.changed)),
"normal_scale" => Some(Parameter::new("normal_scale", &mut self.normal_scale, &self.changed)),
"alpha_type" => Some(Parameter::new("alpha_type", &mut self.alpha_type, &self.changed)),
_ => None
}
}
fn changed(&self) -> bool{
self.changed.changed()
}
fn reset_changed(&mut self){
self.changed.reset();
}
}
#[derive(Debug, Builder)]
#[builder(build_fn(name = "BUILD", private))]
pub struct ClothMaterial{
#[builder(default)]
#[builder(setter(into))]
pub texture: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub normal_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub occlusion_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub emissive_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub texture_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub normal_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub occlusion_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub emissive_map_matrix: Option<Mat4>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 1., g: 1., b: 1.}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_base_color"))]
pub base_color: Rgba<f32>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 0.04, g: 0.04, b: 0.04}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_sheen_color"))]
pub sheen_color: Rgba<f32>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 0., g: 0., b: 0.}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_emissive_color"))]
pub emissive_color: Rgba<f32>,
#[builder(default="0.5")]
pub roughness: f32,
#[builder(default)]
pub double_sided: bool,
#[builder(default="1.")]
pub normal_scale: f32,
#[builder(default)]
pub alpha_type: AlphaType,
#[builder(default)]
#[builder(setter(skip))]
changed: Changed,
#[builder(default)]
#[builder(setter(skip))]
program_id: Option<ProgramId>,
}
impl ClothMaterialBuilder{
pub fn color<C: ToRgba>(&mut self, color: C) -> &mut ClothMaterialBuilder{
self.base_color = Some(color.to_rgba());
self
}
pub fn sheen_color<C: ToRgba>(&mut self, color: C) -> &mut ClothMaterialBuilder{
self.sheen_color = Some(color.to_rgba());
self
}
pub fn emissive_color<C: ToRgba>(&mut self, color: C) -> &mut ClothMaterialBuilder{
self.emissive_color = Some(color.to_rgba());
self
}
pub fn build(&mut self) -> ClothMaterial{
self.BUILD().unwrap()
}
}
impl super::Material for ClothMaterial{
fn parameters(&mut self) -> Vec<super::Parameter>{
vec![
Parameter::new("base_color", &mut self.base_color, &self.changed),
Parameter::new("emissive_color", &mut self.emissive_color, &self.changed),
Parameter::new("roughness", &mut self.roughness, &self.changed),
Parameter::new("sheen_color", &mut self.sheen_color, &self.changed),
Parameter::new("double_sided", &mut self.double_sided, &self.changed),
Parameter::new("normal_scale", &mut self.normal_scale, &self.changed),
Parameter::new("alpha_type", &mut self.alpha_type, &self.changed),
]
}
fn parameter(&mut self, name: &str) -> Option<Parameter>{
match name{
"base_color" => Some(Parameter::new("base_color", &mut self.base_color, &self.changed)),
"emissive_color" => Some(Parameter::new("emissive_color", &mut self.emissive_color, &self.changed)),
"roughness" => Some(Parameter::new("roughness", &mut self.roughness, &self.changed)),
"sheen_color" => Some(Parameter::new("sheen_color", &mut self.sheen_color, &self.changed)),
"double_sided" => Some(Parameter::new("double_sided", &mut self.double_sided, &self.changed)),
"normal_scale" => Some(Parameter::new("normal_scale", &mut self.normal_scale, &self.changed)),
"alpha_type" => Some(Parameter::new("alpha_type", &mut self.alpha_type, &self.changed)),
_ => None
}
}
fn changed(&self) -> bool{
self.changed.changed()
}
fn reset_changed(&mut self){
self.changed.reset();
}
}
#[derive(Debug, Builder)]
#[builder(build_fn(name = "BUILD", private))]
pub struct ClothSubsurfaceMaterial{
#[builder(default)]
#[builder(setter(into))]
pub texture: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub normal_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub occlusion_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub emissive_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub texture_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub normal_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub occlusion_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub emissive_map_matrix: Option<Mat4>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 1., g: 1., b: 1.}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_base_color"))]
pub base_color: Rgba<f32>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 0.04, g: 0.04, b: 0.04}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_sheen_color"))]
pub sheen_color: Rgba<f32>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 1., g: 1., b: 1.}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_subsurface_color"))]
pub subsurface_color: Rgba<f32>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 0., g: 0., b: 0.}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_emissive_color"))]
pub emissive_color: Rgba<f32>,
#[builder(default="0.5")]
pub roughness: f32,
#[builder(default)]
pub double_sided: bool,
#[builder(default="1.")]
pub normal_scale: f32,
#[builder(default)]
pub alpha_type: AlphaType,
#[builder(default)]
#[builder(setter(skip))]
changed: Changed,
#[builder(default)]
#[builder(setter(skip))]
program_id: Option<ProgramId>,
}
impl ClothSubsurfaceMaterialBuilder{
pub fn color<C: ToRgba>(&mut self, color: C) -> &mut ClothSubsurfaceMaterialBuilder{
self.base_color = Some(color.to_rgba());
self
}
pub fn sheen_color<C: ToRgba>(&mut self, color: C) -> &mut ClothSubsurfaceMaterialBuilder{
self.sheen_color = Some(color.to_rgba());
self
}
pub fn subsurface_color<C: ToRgba>(&mut self, color: C) -> &mut ClothSubsurfaceMaterialBuilder{
self.subsurface_color = Some(color.to_rgba());
self
}
pub fn emissive_color<C: ToRgba>(&mut self, color: C) -> &mut ClothSubsurfaceMaterialBuilder{
self.emissive_color = Some(color.to_rgba());
self
}
pub fn build(&mut self) -> ClothSubsurfaceMaterial{
self.BUILD().unwrap()
}
}
impl super::Material for ClothSubsurfaceMaterial{
fn parameters(&mut self) -> Vec<super::Parameter>{
vec![
Parameter::new("base_color", &mut self.base_color, &self.changed),
Parameter::new("emissive_color", &mut self.emissive_color, &self.changed),
Parameter::new("roughness", &mut self.roughness, &self.changed),
Parameter::new("sheen_color", &mut self.sheen_color, &self.changed),
Parameter::new("subsurface_color", &mut self.subsurface_color, &self.changed),
Parameter::new("double_sided", &mut self.double_sided, &self.changed),
Parameter::new("normal_scale", &mut self.normal_scale, &self.changed),
Parameter::new("alpha_type", &mut self.alpha_type, &self.changed),
]
}
fn parameter(&mut self, name: &str) -> Option<Parameter>{
match name{
"base_color" => Some(Parameter::new("base_color", &mut self.base_color, &self.changed)),
"emissive_color" => Some(Parameter::new("emissive_color", &mut self.emissive_color, &self.changed)),
"roughness" => Some(Parameter::new("roughness", &mut self.roughness, &self.changed)),
"sheen_color" => Some(Parameter::new("sheen_color", &mut self.sheen_color, &self.changed)),
"subsurface_color" => Some(Parameter::new("subsurface_color", &mut self.subsurface_color, &self.changed)),
"double_sided" => Some(Parameter::new("double_sided", &mut self.double_sided, &self.changed)),
"normal_scale" => Some(Parameter::new("normal_scale", &mut self.normal_scale, &self.changed)),
"alpha_type" => Some(Parameter::new("alpha_type", &mut self.alpha_type, &self.changed)),
_ => None
}
}
fn changed(&self) -> bool{
self.changed.changed()
}
fn reset_changed(&mut self){
self.changed.reset();
}
}
#[derive(Debug, Builder)]
#[builder(build_fn(name = "BUILD", private))]
pub struct SubsurfaceMaterial{
#[builder(default)]
#[builder(setter(into))]
pub texture: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub normal_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub occlusion_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub metallic_roughness_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub emissive_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub texture_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub normal_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub occlusion_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub metallic_roughness_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub emissive_map_matrix: Option<Mat4>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 1., g: 1., b: 1.}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_base_color"))]
pub base_color: Rgba<f32>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 1., g: 1., b: 1.}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_subsurface_color"))]
pub subsurface_color: Rgba<f32>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 0., g: 0., b: 0.}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_emissive_color"))]
pub emissive_color: Rgba<f32>,
#[builder(default="12.234")]
pub subsurface_power: f32,
#[builder(default="0.5")]
pub thickness: f32,
#[builder(default="0.5")]
pub roughness: f32,
#[builder(default="0.0")]
pub metallic: f32,
#[builder(default="0.5")]
pub reflectance: f32,
#[builder(default="0.0")]
pub reflectance_tint: f32,
#[builder(default)]
pub double_sided: bool,
#[builder(default="1.")]
pub normal_scale: f32,
#[builder(default)]
pub alpha_type: AlphaType,
#[builder(default)]
#[builder(setter(skip))]
changed: Changed,
#[builder(default)]
#[builder(setter(skip))]
program_id: Option<ProgramId>,
}
impl SubsurfaceMaterialBuilder{
pub fn color<C: ToRgba>(&mut self, color: C) -> &mut SubsurfaceMaterialBuilder{
self.base_color = Some(color.to_rgba());
self
}
pub fn subsurface_color<C: ToRgba>(&mut self, color: C) -> &mut SubsurfaceMaterialBuilder{
self.subsurface_color = Some(color.to_rgba());
self
}
pub fn emissive_color<C: ToRgba>(&mut self, color: C) -> &mut SubsurfaceMaterialBuilder{
self.emissive_color = Some(color.to_rgba());
self
}
pub fn build(&mut self) -> SubsurfaceMaterial{
self.BUILD().unwrap()
}
}
impl super::Material for SubsurfaceMaterial{
fn parameters(&mut self) -> Vec<super::Parameter>{
vec![
Parameter::new("base_color", &mut self.base_color, &self.changed),
Parameter::new("emissive_color", &mut self.emissive_color, &self.changed),
Parameter::new("roughness", &mut self.roughness, &self.changed),
Parameter::new("metallic", &mut self.metallic, &self.changed),
Parameter::new("thickness", &mut self.thickness, &self.changed),
Parameter::new("subsurface_color", &mut self.subsurface_color, &self.changed),
Parameter::new("subsurface_power", &mut self.subsurface_power, &self.changed),
Parameter::new("reflectance", &mut self.reflectance, &self.changed),
Parameter::new("reflectance_tint", &mut self.reflectance_tint, &self.changed),
Parameter::new("double_sided", &mut self.double_sided, &self.changed),
Parameter::new("normal_scale", &mut self.normal_scale, &self.changed),
Parameter::new("alpha_type", &mut self.alpha_type, &self.changed),
]
}
fn parameter(&mut self, name: &str) -> Option<Parameter>{
match name{
"base_color" => Some(Parameter::new("base_color", &mut self.base_color, &self.changed)),
"emissive_color" => Some(Parameter::new("emissive_color", &mut self.emissive_color, &self.changed)),
"roughness" => Some(Parameter::new("roughness", &mut self.roughness, &self.changed)),
"metallic" => Some(Parameter::new("metallic", &mut self.metallic, &self.changed)),
"thickness" => Some(Parameter::new("thickness", &mut self.thickness, &self.changed)),
"reflectance" => Some(Parameter::new("reflectance", &mut self.reflectance_tint, &self.changed)),
"reflectance_tint" => Some(Parameter::new("reflectance_tint", &mut self.reflectance_tint, &self.changed)),
"subsurface_color" => Some(Parameter::new("subsurface_color", &mut self.subsurface_color, &self.changed)),
"subsurface_power" => Some(Parameter::new("subsurface_power", &mut self.subsurface_power, &self.changed)),
"double_sided" => Some(Parameter::new("double_sided", &mut self.double_sided, &self.changed)),
"normal_scale" => Some(Parameter::new("normal_scale", &mut self.normal_scale, &self.changed)),
"alpha_type" => Some(Parameter::new("alpha_type", &mut self.alpha_type, &self.changed)),
_ => None
}
}
fn changed(&self) -> bool{
self.changed.changed()
}
fn reset_changed(&mut self){
self.changed.reset();
}
}
#[derive(Debug, Builder)]
#[builder(build_fn(name = "BUILD", private))]
pub struct ClearcoatMaterial{
#[builder(default)]
#[builder(setter(into))]
pub texture: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub normal_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub occlusion_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub metallic_roughness_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub emissive_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub texture_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub normal_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub occlusion_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub metallic_roughness_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub emissive_map_matrix: Option<Mat4>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 1., g: 1., b: 1.}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_base_color"))]
pub base_color: Rgba<f32>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 0., g: 0., b: 0.}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_emissive_color"))]
pub emissive_color: Rgba<f32>,
#[builder(default="0.5")]
pub roughness: f32,
#[builder(default="0.0")]
pub metallic: f32,
#[builder(default="0.5")]
pub reflectance: f32,
#[builder(default="0.0")]
pub reflectance_tint: f32,
#[builder(default="0.0")]
pub clearcoat: f32,
#[builder(default="0.5")]
pub clearcoat_roughness: f32,
#[builder(default)]
pub double_sided: bool,
#[builder(default="1.")]
pub normal_scale: f32,
#[builder(default)]
pub alpha_type: AlphaType,
#[builder(default)]
#[builder(setter(skip))]
changed: Changed,
#[builder(default)]
#[builder(setter(skip))]
program_id: Option<ProgramId>,
}
impl ClearcoatMaterialBuilder{
pub fn color<C: ToRgba>(&mut self, color: C) -> &mut ClearcoatMaterialBuilder{
self.base_color = Some(color.to_rgba());
self
}
pub fn emissive_color<C: ToRgba>(&mut self, color: C) -> &mut ClearcoatMaterialBuilder{
self.emissive_color = Some(color.to_rgba());
self
}
pub fn build(&mut self) -> ClearcoatMaterial{
self.BUILD().unwrap()
}
}
impl super::Material for ClearcoatMaterial{
fn parameters(&mut self) -> Vec<super::Parameter>{
vec![
Parameter::new("base_color", &mut self.base_color, &self.changed),
Parameter::new("emissive_color", &mut self.emissive_color, &self.changed),
Parameter::new("roughness", &mut self.roughness, &self.changed),
Parameter::new("metallic", &mut self.metallic, &self.changed),
Parameter::new("clearcoat", &mut self.clearcoat, &self.changed),
Parameter::new("clearcoat_roughness", &mut self.clearcoat_roughness, &self.changed),
Parameter::new("reflectance", &mut self.reflectance, &self.changed),
Parameter::new("reflectance_tint", &mut self.reflectance_tint, &self.changed),
Parameter::new("double_sided", &mut self.double_sided, &self.changed),
Parameter::new("normal_scale", &mut self.normal_scale, &self.changed),
Parameter::new("alpha_type", &mut self.alpha_type, &self.changed),
]
}
fn parameter(&mut self, name: &str) -> Option<Parameter>{
match name{
"base_color" => Some(Parameter::new("base_color", &mut self.base_color, &self.changed)),
"emissive_color" => Some(Parameter::new("emissive_color", &mut self.emissive_color, &self.changed)),
"roughness" => Some(Parameter::new("roughness", &mut self.roughness, &self.changed)),
"metallic" => Some(Parameter::new("metallic", &mut self.metallic, &self.changed)),
"reflectance" => Some(Parameter::new("reflectance", &mut self.reflectance, &self.changed)),
"reflectance_tint" => Some(Parameter::new("reflectance_tint", &mut self.reflectance_tint, &self.changed)),
"clearcoat" => Some(Parameter::new("clearcoat", &mut self.clearcoat, &self.changed)),
"clearcoat_roughness" => Some(Parameter::new("clearcoat_roughness", &mut self.clearcoat_roughness, &self.changed)),
"double_sided" => Some(Parameter::new("double_sided", &mut self.double_sided, &self.changed)),
"normal_scale" => Some(Parameter::new("normal_scale", &mut self.normal_scale, &self.changed)),
"alpha_type" => Some(Parameter::new("alpha_type", &mut self.alpha_type, &self.changed)),
_ => None
}
}
fn changed(&self) -> bool{
self.changed.changed()
}
fn reset_changed(&mut self){
self.changed.reset();
}
}
#[derive(Debug, Builder)]
#[builder(build_fn(name = "BUILD", private))]
pub struct DisneyPrincipledMaterial{
#[builder(default)]
#[builder(setter(into))]
pub texture: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub normal_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub occlusion_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub metallic_roughness_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub emissive_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub anisotropy_map: Option<TextureSampler>,
#[builder(default)]
#[builder(setter(into))]
pub texture_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub normal_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub occlusion_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub metallic_roughness_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub emissive_map_matrix: Option<Mat4>,
#[builder(default)]
#[builder(setter(into))]
pub anisotropy_map_matrix: Option<Mat4>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 1., g: 1., b: 1.}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_base_color"))]
pub base_color: Rgba<f32>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 0.04, g: 0.04, b: 0.04}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_sheen_color"))]
pub sheen_color: Rgba<f32>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 1., g: 1., b: 1.}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_subsurface_color"))]
pub subsurface_color: Rgba<f32>,
#[doc = "hidden"]
#[builder(default="Rgba{c: Rgb{r: 0., g: 0., b: 0.}, a: 1.}")]
#[builder(private)]
#[builder(setter(name = "hidden_emissive_color"))]
pub emissive_color: Rgba<f32>,
#[builder(default="12.234")]
pub subsurface_power: f32,
#[builder(default="0.5")]
pub thickness: f32,
#[builder(default="0.5")]
pub roughness: f32,
#[builder(default="0.0")]
pub metallic: f32,
#[builder(default="0.5")]
pub reflectance: f32,
#[builder(default="0.0")]
pub reflectance_tint: f32,
#[builder(default)]
pub anisotropy: f32,
#[builder(default)]
pub anisotropic_rotation: Rad<f32>,
#[builder(default="0.0")]
pub clearcoat: f32,
#[builder(default="0.5")]
pub clearcoat_roughness: f32,
#[builder(default)]
pub double_sided: bool,
#[builder(default="1.")]
pub normal_scale: f32,
#[builder(default)]
pub alpha_type: AlphaType,
#[builder(default)]
#[builder(setter(skip))]
changed: Changed,
#[builder(default)]
#[builder(setter(skip))]
program_id: Option<ProgramId>,
}
impl DisneyPrincipledMaterialBuilder{
pub fn color<C: ToRgba>(&mut self, color: C) -> &mut DisneyPrincipledMaterialBuilder{
self.base_color = Some(color.to_rgba());
self
}
pub fn emissive_color<C: ToRgba>(&mut self, color: C) -> &mut DisneyPrincipledMaterialBuilder{
self.emissive_color = Some(color.to_rgba());
self
}
pub fn subsurface_color<C: ToRgba>(&mut self, color: C) -> &mut DisneyPrincipledMaterialBuilder{
self.subsurface_color = Some(color.to_rgba());
self
}
pub fn sheen_color<C: ToRgba>(&mut self, color: C) -> &mut DisneyPrincipledMaterialBuilder{
self.sheen_color = Some(color.to_rgba());
self
}
pub fn build(&mut self) -> DisneyPrincipledMaterial{
self.BUILD().unwrap()
}
}
fn program_id<M: PbrMaterial>(material: &M, light_info: &LightInfo) -> ProgramId{
let mat_ty = material.pbr_material_type();
let is_double_sided = material.is_double_sided();
let has_metallic_map = material.metallic_roughness_map().is_some();
let has_base_color_map = material.base_color_map().is_some();
let has_normal_map = material.normal_map().is_some();
let has_emissive_map = material.emissive_map().is_some();
let has_anisotropy_map = material.anisotropy_map().is_some();
let alpha_type = material.alpha_ty();
ProgramId{
light_info: *light_info,
has_base_color_map,
has_emissive_map,
has_metallic_map,
has_normal_map,
has_anisotropy_map,
has_tangents: false,
has_separate_alpha: false,
has_clip_plane: true,
is_double_sided,
ty: mat_ty,
alpha_type,
}
}
pub trait PbrMaterial{
fn metallic_roughness_map(&self) -> Option<&TextureSampler>;
fn base_color_map(&self) -> Option<&TextureSampler>;
fn normal_map(&self) -> Option<&TextureSampler>;
fn emissive_map(&self) -> Option<&TextureSampler>;
fn anisotropy_map(&self) -> Option<&TextureSampler>;
fn occlusion_map(&self) -> Option<&TextureSampler>;
fn alpha_ty(&self) -> AlphaType;
fn pbr_material_type(&self) -> MaterialType;
fn is_double_sided(&self) -> bool;
fn normal_scale(&self) -> f32;
fn base_color_alpha(&self) -> f32;
fn update_program_id(&mut self, light_info: &LightInfo) -> bool;
fn program_id(&self) -> &ProgramId;
}
impl PbrMaterial for StandardMaterial{
fn metallic_roughness_map(&self) -> Option<&TextureSampler>{
self.metallic_roughness_map.as_ref()
}
fn base_color_map(&self) -> Option<&TextureSampler>{
self.texture.as_ref()
}
fn normal_map(&self) -> Option<&TextureSampler>{
self.normal_map.as_ref()
}
fn emissive_map(&self) -> Option<&TextureSampler>{
self.emissive_map.as_ref()
}
fn occlusion_map(&self) -> Option<&TextureSampler>{
self.occlusion_map.as_ref()
}
fn anisotropy_map(&self) -> Option<&TextureSampler>{
None
}
fn alpha_ty(&self) -> AlphaType{
self.alpha_type
}
fn normal_scale(&self) -> f32{
self.normal_scale
}
fn pbr_material_type(&self) -> MaterialType{
MaterialType::Standard
}
fn is_double_sided(&self) -> bool{
self.double_sided
}
fn base_color_alpha(&self) -> f32{
match self.alpha_type{
AlphaType::None => 1.,
AlphaType::AlphaToCoverage | AlphaType::Blending |
AlphaType::ScreenDoor => self.base_color.a,
AlphaType::Threshold => if self.base_color.a > 0.5 { 1. } else { 0. }
}
}
fn update_program_id(&mut self, light_info: &LightInfo) -> bool{
if self.program_id.is_none() || self.changed.changed() || light_info.has_changed(){
let program_id = program_id(self, light_info);
let changed = if let Some(old_program_id) = self.program_id.as_ref() {
&program_id != old_program_id
}else{
true
};
self.program_id = Some(program_id);
changed
}else{
false
}
}
fn program_id(&self) -> &ProgramId{
self.program_id.as_ref().unwrap()
}
}
impl PbrMaterial for LambertMaterial{
fn metallic_roughness_map(&self) -> Option<&TextureSampler>{
self.metallic_roughness_map.as_ref()
}
fn base_color_map(&self) -> Option<&TextureSampler>{
self.texture.as_ref()
}
fn normal_map(&self) -> Option<&TextureSampler>{
self.normal_map.as_ref()
}
fn emissive_map(&self) -> Option<&TextureSampler>{
self.emissive_map.as_ref()
}
fn occlusion_map(&self) -> Option<&TextureSampler>{
self.occlusion_map.as_ref()
}
fn anisotropy_map(&self) -> Option<&TextureSampler>{
None
}
fn alpha_ty(&self) -> AlphaType{
self.alpha_type
}
fn normal_scale(&self) -> f32{
self.normal_scale
}
fn pbr_material_type(&self) -> MaterialType{
MaterialType::Lambert
}
fn is_double_sided(&self) -> bool{
self.double_sided
}
fn base_color_alpha(&self) -> f32{
match self.alpha_type{
AlphaType::None => 1.,
AlphaType::AlphaToCoverage | AlphaType::Blending |
AlphaType::ScreenDoor => self.base_color.a,
AlphaType::Threshold => if self.base_color.a > 0.5 { 1. } else { 0. }
}
}
fn update_program_id(&mut self, light_info: &LightInfo) -> bool{
if self.changed.changed() || light_info.has_changed(){
let program_id = program_id(self, light_info);
let changed = if let Some(old_program_id) = self.program_id.as_ref() {
&program_id != old_program_id
}else{
true
};
self.program_id = Some(program_id);
changed
}else{
false
}
}
fn program_id(&self) -> &ProgramId{
self.program_id.as_ref().unwrap()
}
}
impl PbrMaterial for AnisotropicMaterial{
fn metallic_roughness_map(&self) -> Option<&TextureSampler>{
self.metallic_roughness_map.as_ref()
}
fn base_color_map(&self) -> Option<&TextureSampler>{
self.texture.as_ref()
}
fn normal_map(&self) -> Option<&TextureSampler>{
self.normal_map.as_ref()
}
fn emissive_map(&self) -> Option<&TextureSampler>{
self.emissive_map.as_ref()
}
fn occlusion_map(&self) -> Option<&TextureSampler>{
self.occlusion_map.as_ref()
}
fn anisotropy_map(&self) -> Option<&TextureSampler>{
self.anisotropy_map.as_ref()
}
fn alpha_ty(&self) -> AlphaType{
self.alpha_type
}
fn normal_scale(&self) -> f32{
self.normal_scale
}
fn pbr_material_type(&self) -> MaterialType{
MaterialType::Anisotropic
}
fn is_double_sided(&self) -> bool{
self.double_sided
}
fn base_color_alpha(&self) -> f32{
match self.alpha_type{
AlphaType::None => 1.,
AlphaType::AlphaToCoverage | AlphaType::Blending |
AlphaType::ScreenDoor => self.base_color.a,
AlphaType::Threshold => if self.base_color.a > 0.5 { 1. } else { 0. }
}
}
fn update_program_id(&mut self, light_info: &LightInfo) -> bool{
if self.changed.changed() || light_info.has_changed(){
let program_id = program_id(self, light_info);
let changed = if let Some(old_program_id) = self.program_id.as_ref() {
&program_id != old_program_id
}else{
true
};
self.program_id = Some(program_id);
changed
}else{
false
}
}
fn program_id(&self) -> &ProgramId{
self.program_id.as_ref().unwrap()
}
}
impl PbrMaterial for ClothMaterial{
fn metallic_roughness_map(&self) -> Option<&TextureSampler>{
None
}
fn base_color_map(&self) -> Option<&TextureSampler>{
self.texture.as_ref()
}
fn normal_map(&self) -> Option<&TextureSampler>{
self.normal_map.as_ref()
}
fn emissive_map(&self) -> Option<&TextureSampler>{
self.emissive_map.as_ref()
}
fn occlusion_map(&self) -> Option<&TextureSampler>{
self.occlusion_map.as_ref()
}
fn anisotropy_map(&self) -> Option<&TextureSampler>{
None
}
fn alpha_ty(&self) -> AlphaType{
self.alpha_type
}
fn normal_scale(&self) -> f32{
self.normal_scale
}
fn pbr_material_type(&self) -> MaterialType{
MaterialType::Cloth
}
fn is_double_sided(&self) -> bool{
self.double_sided
}
fn base_color_alpha(&self) -> f32{
match self.alpha_type{
AlphaType::None => 1.,
AlphaType::AlphaToCoverage | AlphaType::Blending |
AlphaType::ScreenDoor => self.base_color.a,
AlphaType::Threshold => if self.base_color.a > 0.5 { 1. } else { 0. }
}
}
fn update_program_id(&mut self, light_info: &LightInfo) -> bool{
if self.changed.changed() || light_info.has_changed(){
let program_id = program_id(self, light_info);
let changed = if let Some(old_program_id) = self.program_id.as_ref() {
&program_id != old_program_id
}else{
true
};
self.program_id = Some(program_id);
changed
}else{
false
}
}
fn program_id(&self) -> &ProgramId{
self.program_id.as_ref().unwrap()
}
}
impl PbrMaterial for ClothSubsurfaceMaterial{
fn metallic_roughness_map(&self) -> Option<&TextureSampler>{
None
}
fn base_color_map(&self) -> Option<&TextureSampler>{
self.texture.as_ref()
}
fn normal_map(&self) -> Option<&TextureSampler>{
self.normal_map.as_ref()
}
fn emissive_map(&self) -> Option<&TextureSampler>{
self.emissive_map.as_ref()
}
fn occlusion_map(&self) -> Option<&TextureSampler>{
self.occlusion_map.as_ref()
}
fn anisotropy_map(&self) -> Option<&TextureSampler>{
None
}
fn alpha_ty(&self) -> AlphaType{
self.alpha_type
}
fn normal_scale(&self) -> f32{
self.normal_scale
}
fn pbr_material_type(&self) -> MaterialType{
MaterialType::ClothSubsurface
}
fn is_double_sided(&self) -> bool{
self.double_sided
}
fn base_color_alpha(&self) -> f32{
match self.alpha_type{
AlphaType::None => 1.,
AlphaType::AlphaToCoverage | AlphaType::Blending |
AlphaType::ScreenDoor => self.base_color.a,
AlphaType::Threshold => if self.base_color.a > 0.5 { 1. } else { 0. }
}
}
fn update_program_id(&mut self, light_info: &LightInfo) -> bool{
if self.changed.changed() || light_info.has_changed(){
let program_id = program_id(self, light_info);
let changed = if let Some(old_program_id) = self.program_id.as_ref() {
&program_id != old_program_id
}else{
true
};
self.program_id = Some(program_id);
changed
}else{
false
}
}
fn program_id(&self) -> &ProgramId{
self.program_id.as_ref().unwrap()
}
}
impl PbrMaterial for SubsurfaceMaterial{
fn metallic_roughness_map(&self) -> Option<&TextureSampler>{
self.metallic_roughness_map.as_ref()
}
fn base_color_map(&self) -> Option<&TextureSampler>{
self.texture.as_ref()
}
fn normal_map(&self) -> Option<&TextureSampler>{
self.normal_map.as_ref()
}
fn emissive_map(&self) -> Option<&TextureSampler>{
self.emissive_map.as_ref()
}
fn occlusion_map(&self) -> Option<&TextureSampler>{
self.occlusion_map.as_ref()
}
fn anisotropy_map(&self) -> Option<&TextureSampler>{
None
}
fn alpha_ty(&self) -> AlphaType{
self.alpha_type
}
fn normal_scale(&self) -> f32{
self.normal_scale
}
fn pbr_material_type(&self) -> MaterialType{
MaterialType::Subsurface
}
fn is_double_sided(&self) -> bool{
self.double_sided
}
fn base_color_alpha(&self) -> f32{
match self.alpha_type{
AlphaType::None => 1.,
AlphaType::AlphaToCoverage | AlphaType::Blending |
AlphaType::ScreenDoor => self.base_color.a,
AlphaType::Threshold => if self.base_color.a > 0.5 { 1. } else { 0. }
}
}
fn update_program_id(&mut self, light_info: &LightInfo) -> bool{
if self.changed.changed() || light_info.has_changed(){
let program_id = program_id(self, light_info);
let changed = if let Some(old_program_id) = self.program_id.as_ref() {
&program_id != old_program_id
}else{
true
};
self.program_id = Some(program_id);
changed
}else{
false
}
}
fn program_id(&self) -> &ProgramId{
self.program_id.as_ref().unwrap()
}
}
impl PbrMaterial for ClearcoatMaterial{
fn metallic_roughness_map(&self) -> Option<&TextureSampler>{
self.metallic_roughness_map.as_ref()
}
fn base_color_map(&self) -> Option<&TextureSampler>{
self.texture.as_ref()
}
fn normal_map(&self) -> Option<&TextureSampler>{
self.normal_map.as_ref()
}
fn emissive_map(&self) -> Option<&TextureSampler>{
self.emissive_map.as_ref()
}
fn occlusion_map(&self) -> Option<&TextureSampler>{
self.occlusion_map.as_ref()
}
fn anisotropy_map(&self) -> Option<&TextureSampler>{
None
}
fn alpha_ty(&self) -> AlphaType{
self.alpha_type
}
fn normal_scale(&self) -> f32{
self.normal_scale
}
fn pbr_material_type(&self) -> MaterialType{
MaterialType::Clearcoat
}
fn is_double_sided(&self) -> bool{
self.double_sided
}
fn base_color_alpha(&self) -> f32{
match self.alpha_type{
AlphaType::None => 1.,
AlphaType::AlphaToCoverage | AlphaType::Blending |
AlphaType::ScreenDoor => self.base_color.a,
AlphaType::Threshold => if self.base_color.a > 0.5 { 1. } else { 0. }
}
}
fn update_program_id(&mut self, light_info: &LightInfo) -> bool{
if self.changed.changed() || light_info.has_changed(){
let program_id = program_id(self, light_info);
let changed = if let Some(old_program_id) = self.program_id.as_ref() {
&program_id != old_program_id
}else{
true
};
self.program_id = Some(program_id);
changed
}else{
false
}
}
fn program_id(&self) -> &ProgramId{
self.program_id.as_ref().unwrap()
}
}
#[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()
}
}
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct ProgramId{
pub light_info: LightInfo,
pub has_metallic_map: bool,
pub has_base_color_map: bool,
pub has_normal_map: bool,
pub has_emissive_map: bool,
pub has_anisotropy_map: bool,
pub has_tangents: bool,
pub has_separate_alpha: bool,
pub has_clip_plane: bool,
pub is_double_sided: bool,
pub ty: MaterialType,
pub alpha_type: AlphaType,
}