From 8d821588cd4f51d4ae9c4ef52d45c0af0e1ce9e5 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 12 Nov 2023 22:38:52 +0100 Subject: feat(engine): add basic flat lighting --- engine/src/vertex.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'engine/src/vertex.rs') 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, color: Color, texture_coords: Vec2, + normal: Vec3, } #[derive(Debug, Default)] @@ -18,6 +19,7 @@ pub struct Builder pos: Option>, color: Option>, texture_coords: Vec2, + normal: Option>, } impl Builder @@ -52,16 +54,26 @@ impl Builder self } + #[must_use] + pub fn normal(mut self, normal: Vec3) -> Self + { + self.normal = Some(normal); + + self + } + #[must_use] pub fn build(self) -> Option { 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::(), }, + Attribute { + index: 3, + component_type: AttributeComponentType::Float, + component_cnt: AttributeComponentCnt::Three, + component_size: size_of::(), + }, ] } } -- cgit v1.2.3-18-g5258