use densevec::Key;
use rin_math::Rect;
use rinecs::OneToNComponent;
use serde_derive::{Serialize, Deserialize};
pub use self::pbr_material::*;
pub use self::basic_material::{BasicMaterial, BasicMaterialBuilder};
pub use self::parameter::{Parameter, UniformValueRef, ParameterAny, ParameterMutAny, UniformRef};
pub use self::outline_material::{OutlineMaterial, OutlineMaterialBuilder};
#[macro_use] pub mod parameter;
pub mod texture;
mod pbr_material;
mod basic_material;
mod outline_material;
pub mod metals{
use color::{Rgb, rgb_linear, color_space::LinearRgb};
pub const IRON: Rgb<f32, LinearRgb> = rgb_linear!(0.560, 0.570, 0.580);
pub const SILVER: Rgb<f32, LinearRgb> = rgb_linear!(0.972, 0.960, 0.915);
pub const ALUMINUM: Rgb<f32, LinearRgb> = rgb_linear!(0.913, 0.921, 0.925);
pub const GOLD: Rgb<f32, LinearRgb> = rgb_linear!(1.000, 0.766, 0.336);
pub const COPPER: Rgb<f32, LinearRgb> = rgb_linear!(0.955, 0.637, 0.538);
pub const CHROMIUM: Rgb<f32, LinearRgb> = rgb_linear!(0.550, 0.556, 0.554);
pub const NICKEL: Rgb<f32, LinearRgb> = rgb_linear!(0.660, 0.609, 0.526);
pub const TITANIUM: Rgb<f32, LinearRgb> = rgb_linear!(0.542, 0.497, 0.449);
pub const COBALT: Rgb<f32, LinearRgb> = rgb_linear!(0.662, 0.655, 0.634);
pub const PLATINUM: Rgb<f32, LinearRgb> = rgb_linear!(0.672, 0.637, 0.585);
}
#[derive(Debug,Clone,Copy,Eq,PartialEq,Hash)]
pub enum BlendFactor{
Zero,
One,
SrcColor,
OneMinusSrcColor,
SrcAlpha,
OneMinusSrcAlpha,
DstColor,
OneMinusDstColor,
DstAlpha,
OneMinusDstAlpha,
}
#[derive(Debug,Clone,Copy,Eq,PartialEq,Hash)]
pub struct ColorBlendFactor{
pub src: BlendFactor,
pub dst: BlendFactor,
}
#[derive(Debug,Clone,Copy,Eq,PartialEq,Hash)]
pub struct AlphaBlendFactor{
pub src: BlendFactor,
pub dst: BlendFactor,
}
#[derive(Debug,Clone,Copy,Eq,PartialEq,Hash)]
pub enum AlphaType{
None,
Blending,
BlendingFactors(ColorBlendFactor, AlphaBlendFactor),
AlphaToCoverage,
ScreenDoor,
Threshold,
}
impl Default for AlphaType{
fn default() -> AlphaType {
AlphaType::None
}
}
impl ToString for AlphaType{
fn to_string(&self) -> String{
match self{
AlphaType::None => "ALPHA_NONE",
AlphaType::Blending
| AlphaType::BlendingFactors(_,_) => "ALPHA_BLENDING",
AlphaType::AlphaToCoverage => "ALPHA_TO_COVERAGE",
AlphaType::ScreenDoor => "ALPHA_SCREEN_DOOR",
AlphaType::Threshold => "ALPHA_THRESHOLD",
}.to_owned()
}
}
#[derive(OneToNComponent, Clone, Copy, Eq, PartialEq, Debug, Ord, PartialOrd, Serialize, Deserialize, Hash)]
#[autochanges]
pub struct MaterialRef{id: usize}
impl Key for MaterialRef{
fn to_usize(self) -> usize{
self.id
}
fn from_usize(id: usize) -> MaterialRef{
MaterialRef{id}
}
}
impl rinecs::Changes for MaterialRef{
fn has_changed(&self) -> bool {
false
}
fn reset_changed(&mut self){
}
}
#[derive(OneToNComponent, Clone, Eq, PartialEq, Debug, Ord, PartialOrd, Serialize, Deserialize)]
#[autochanges]
pub struct MaterialMultiRef(Vec<MaterialRef>);
impl MaterialMultiRef{
pub fn new(mats: Vec<MaterialRef>) -> MaterialMultiRef{
MaterialMultiRef(mats)
}
}
impl rinecs::Changes for MaterialMultiRef{
fn has_changed(&self) -> bool {
false
}
fn reset_changed(&mut self){
}
}
#[derive(OneToNComponent, Clone, Copy, Eq, PartialEq, Debug, Ord, PartialOrd, Serialize, Deserialize)]
#[autochanges]
pub struct ShadowMaterialRef{id: usize}
impl Key for ShadowMaterialRef{
fn to_usize(self) -> usize{
self.id
}
fn from_usize(id: usize) -> ShadowMaterialRef{
ShadowMaterialRef{id}
}
}
impl rinecs::Changes for ShadowMaterialRef{
fn has_changed(&self) -> bool {
false
}
fn reset_changed(&mut self){
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Face{
Front,
Back,
}
#[derive(Clone, Debug, PartialEq)]
pub enum Property{
ClipDistance(Vec<u32>),
CullFace(Option<Face>),
FrontFace(Face),
DepthClamp(bool),
DepthTest(bool),
Dither(bool),
LineSmooth(bool),
Multisample(bool),
PolygonOffsetFill(Option<(f32, f32)>),
PolygonOffsetLine(Option<(f32, f32)>),
PolygonOffsetPoint(Option<(f32, f32)>),
PolygonSmooth(bool),
RasterizerDiscard(bool),
StencilMask(u32),
Scissor(Option<Rect<u32>>),
StencilTest(bool),
TextureCubemapSeamless(bool),
ProgramPointSize(bool),
DepthMask(bool),
ColorMask(bool, bool, bool, bool),
DepthRange(f32, f32),
LineWidth(f32),
PointSize(f32),
}
pub trait Material{
fn type_name(&self) -> &str;
fn parameter_names(&self) -> Vec<&str>;
fn parameters(&self) -> Vec<ParameterAny>;
fn parameters_mut(&mut self) -> Vec<ParameterMutAny>;
fn parameter(&self, name: &str) -> Option<ParameterAny>;
fn parameter_mut(&mut self, name: &str) -> Option<ParameterMutAny>;
fn parameter_type_name(&self, name: &str) -> Option<&str>;
fn reset_changed(&mut self);
}
pub trait MaterialParameterTypes{
fn uniform_parameters(&self) -> Vec<UniformRef>;
fn texture_parameters(&self) -> Vec<UniformRef>;
fn cubemap_parameters(&self) -> Vec<UniformRef>;
fn properties_parameter(&self) -> Option<&Parameter<Vec<Property>>>;
fn alpha_type_parameter(&self) -> Option<&Parameter<AlphaType>>;
fn any_uniform_changed(&self) -> bool;
fn any_texture_changed(&self) -> bool;
fn any_cubemap_changed(&self) -> bool;
fn any_data_changed(&self) -> bool;
fn any_uniform_option_changed(&self) -> bool;
fn any_texture_option_changed(&self) -> bool;
fn any_cubemap_option_changed(&self) -> bool;
fn any_data_option_changed(&self) -> bool;
fn has_data(&self) -> bool;
fn has_uniforms(&self) -> bool;
fn has_textures(&self) -> bool;
fn has_cubemaps(&self) -> bool;
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub enum ShaderPrecision{
Low,
Medium,
High,
}
impl Default for ShaderPrecision{
fn default() -> Self {
ShaderPrecision::High
}
}