summaryrefslogtreecommitdiff
path: root/engine/src/material.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/material.rs')
-rw-r--r--engine/src/material.rs53
1 files changed, 28 insertions, 25 deletions
diff --git a/engine/src/material.rs b/engine/src/material.rs
index 240d7e2..5af3282 100644
--- a/engine/src/material.rs
+++ b/engine/src/material.rs
@@ -1,32 +1,32 @@
-use crate::color::Color;
+use crate::texture::Id as TextureId;
#[derive(Debug, Clone)]
pub struct Material
{
- ambient: Color<f32>,
- diffuse: Color<f32>,
- specular: Color<f32>,
+ ambient_map: TextureId,
+ diffuse_map: TextureId,
+ specular_map: TextureId,
shininess: f32,
}
impl Material
{
#[must_use]
- pub fn ambient(&self) -> &Color<f32>
+ pub fn ambient_map(&self) -> &TextureId
{
- &self.ambient
+ &self.ambient_map
}
#[must_use]
- pub fn diffuse(&self) -> &Color<f32>
+ pub fn diffuse_map(&self) -> &TextureId
{
- &self.diffuse
+ &self.diffuse_map
}
#[must_use]
- pub fn specular(&self) -> &Color<f32>
+ pub fn specular_map(&self) -> &TextureId
{
- &self.specular
+ &self.specular_map
}
#[must_use]
@@ -40,9 +40,9 @@ impl Material
#[derive(Debug, Clone)]
pub struct Builder
{
- ambient: Color<f32>,
- diffuse: Color<f32>,
- specular: Color<f32>,
+ ambient_map: Option<TextureId>,
+ diffuse_map: Option<TextureId>,
+ specular_map: Option<TextureId>,
shininess: f32,
}
@@ -52,33 +52,33 @@ impl Builder
pub fn new() -> Self
{
Self {
- ambient: 0.2.into(),
- diffuse: 0.5.into(),
- specular: 1.0.into(),
+ ambient_map: None,
+ diffuse_map: None,
+ specular_map: None,
shininess: 32.0,
}
}
#[must_use]
- pub fn ambient(mut self, ambient: Color<f32>) -> Self
+ pub fn ambient_map(mut self, ambient_map: TextureId) -> Self
{
- self.ambient = ambient;
+ self.ambient_map = Some(ambient_map);
self
}
#[must_use]
- pub fn diffuse(mut self, diffuse: Color<f32>) -> Self
+ pub fn diffuse_map(mut self, diffuse_map: TextureId) -> Self
{
- self.diffuse = diffuse;
+ self.diffuse_map = Some(diffuse_map);
self
}
#[must_use]
- pub fn specular(mut self, specular: Color<f32>) -> Self
+ pub fn specular_map(mut self, specular_map: TextureId) -> Self
{
- self.specular = specular;
+ self.specular_map = Some(specular_map);
self
}
@@ -92,13 +92,16 @@ impl Builder
}
/// Builds a new [`Material`].
+ ///
+ /// # Panics
+ /// Will panic if no ambient map, diffuse map or specular map is set.
#[must_use]
pub fn build(&self) -> Material
{
Material {
- ambient: self.ambient.clone(),
- diffuse: self.diffuse.clone(),
- specular: self.specular.clone(),
+ ambient_map: self.ambient_map.unwrap(),
+ diffuse_map: self.diffuse_map.unwrap(),
+ specular_map: self.specular_map.unwrap(),
shininess: self.shininess,
}
}