1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*!
 * MAterials in mutiny. This module is renderer independent and the Components in it only
 * specify materials data and some utilities. Each specific renderer should read this components in
 * the scene and implement their behaivour
 */

use densevec::Key;
use rin::math::Rect;

pub use self::pbr_material::*;
pub use self::basic_material::BasicMaterial;
pub use self::parameter::Parameter;
pub use self::outline_material::OutlineMaterial;

#[macro_use] pub mod parameter;
pub mod texture;
mod pbr_material;
pub mod basic_material;
pub mod water;
pub mod outline_material;

pub mod metals{
    use color::Rgb;

    pub const IRON: Rgb<f32>     = Rgb{r: 0.560, g: 0.570, b: 0.580};
    pub const SILVER: Rgb<f32>   = Rgb{r: 0.972, g: 0.960, b: 0.915};
    pub const ALUMINUM: Rgb<f32> = Rgb{r: 0.913, g: 0.921, b: 0.925};
    pub const GOLD: Rgb<f32>     = Rgb{r: 1.000, g: 0.766, b: 0.336};
    pub const COPPER: Rgb<f32>   = Rgb{r: 0.955, g: 0.637, b: 0.538};
    pub const CHROMIUM: Rgb<f32> = Rgb{r: 0.550, g: 0.556, b: 0.554};
    pub const NICKEL: Rgb<f32>   = Rgb{r: 0.660, g: 0.609, b: 0.526};
    pub const TITANIUM: Rgb<f32> = Rgb{r: 0.542, g: 0.497, b: 0.449};
    pub const COBALT: Rgb<f32>   = Rgb{r: 0.662, g: 0.655, b: 0.634};
    pub const PLATINUM: Rgb<f32> = Rgb{r: 0.672, g: 0.637, b: 0.585};
}

#[derive(Debug,Clone,Copy,Eq,PartialEq,Hash)]
pub enum AlphaType{
    None,
    Blending,
    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 => "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)]
pub struct MaterialRef{id: usize}

impl Key for MaterialRef{
    fn to_usize(self) -> usize{
        self.id
    }

    fn from_usize(id: usize) -> MaterialRef{
        MaterialRef{id}
    }
}

#[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),
    // SampleAlphaToCoverage(bool),
    // SampleAlphaToOne(bool),
    // SampleCoverage(Option<(f32, bool)>),
    StencilMask(u32),
	Scissor(Option<Rect<u32>>),
	StencilTest(bool),
    // StencilFunc(GLenum, GLint, GLuint),
    // StencilOp(GLenum,GLenum,GLenum),
    TextureCubemapSeamless(bool),
	// BlendEquation(GLenum),
	// BlendFunc(GLenum,GLenum),
	// BlendColor([GLclampf;4]),
    // Blend(bool),
	// DepthFunc(GLenum),
	DepthMask(bool),
    ColorMask(bool, bool, bool, bool),
	DepthRange(f32, f32),
	LineWidth(f32),
	PointSize(f32),
}


pub trait Material{
    fn parameters(&mut self) -> Vec<Parameter>;
    fn parameter(&mut self, name: &str) -> Option<Parameter>;
    fn changed(&self) -> bool;
    fn reset_changed(&mut self);
}