summaryrefslogtreecommitdiff
path: root/engine/src/vertex.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-11-12 22:38:52 +0100
committerHampusM <hampus@hampusmat.com>2023-11-12 22:57:19 +0100
commit8d821588cd4f51d4ae9c4ef52d45c0af0e1ce9e5 (patch)
treeed1b0dd30e801b9a70537b9806a445e4212978b3 /engine/src/vertex.rs
parent67023d6a095f457a2579367d59d13c6c804e7108 (diff)
feat(engine): add basic flat lighting
Diffstat (limited to 'engine/src/vertex.rs')
-rw-r--r--engine/src/vertex.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/engine/src/vertex.rs b/engine/src/vertex.rs
index 9df646f..bb0e890 100644
--- a/engine/src/vertex.rs
+++ b/engine/src/vertex.rs
@@ -10,6 +10,7 @@ pub struct Vertex
pos: Vec3<f32>,
color: Color<f32>,
texture_coords: Vec2<f32>,
+ normal: Vec3<f32>,
}
#[derive(Debug, Default)]
@@ -18,6 +19,7 @@ pub struct Builder
pos: Option<Vec3<f32>>,
color: Option<Color<f32>>,
texture_coords: Vec2<f32>,
+ normal: Option<Vec3<f32>>,
}
impl Builder
@@ -53,15 +55,25 @@ impl Builder
}
#[must_use]
+ pub fn normal(mut self, normal: Vec3<f32>) -> Self
+ {
+ self.normal = Some(normal);
+
+ self
+ }
+
+ #[must_use]
pub fn build(self) -> Option<Vertex>
{
let pos = self.pos?;
- let color = self.color?;
+ let color = self.color.unwrap_or_default();
+ let normal = self.normal.unwrap_or_default();
Some(Vertex {
pos,
color,
texture_coords: self.texture_coords,
+ normal,
})
}
}
@@ -89,6 +101,12 @@ impl Vertex
component_cnt: AttributeComponentCnt::Two,
component_size: size_of::<f32>(),
},
+ Attribute {
+ index: 3,
+ component_type: AttributeComponentType::Float,
+ component_cnt: AttributeComponentCnt::Three,
+ component_size: size_of::<f32>(),
+ },
]
}
}