From 669d2552e8bbe386610cfd935cbe85f379f5a786 Mon Sep 17 00:00:00 2001 From: Vijfhoek Date: Fri, 18 Jun 2021 10:34:31 +0200 Subject: [PATCH] Implement block coloring --- src/hud/hotbar_hud.rs | 32 ++++++++++++++---------- src/hud/widgets_hud.rs | 34 ++++++++++++------------- src/shaders/ui.wgsl | 8 +++--- src/shaders/world.wgsl | 5 +++- src/text_renderer.rs | 8 +++--- src/texture.rs | 3 ++- src/vertex.rs | 10 +++++--- src/world/block.rs | 11 ++++++++ src/world/npc.rs | 1 + src/world/quad.rs | 57 +++++++++++++++++++++--------------------- 10 files changed, 97 insertions(+), 72 deletions(-) diff --git a/src/hud/hotbar_hud.rs b/src/hud/hotbar_hud.rs index edde130..8810d71 100644 --- a/src/hud/hotbar_hud.rs +++ b/src/hud/hotbar_hud.rs @@ -1,3 +1,4 @@ +use cgmath::{ElementWise, Vector4}; use wgpu::{BufferUsage, RenderPass}; use crate::{ @@ -27,7 +28,7 @@ impl HotbarHud { Some(BlockType::Cobblestone), Some(BlockType::OakPlanks), Some(BlockType::OakLog), - None, + Some(BlockType::OakLeaves), ]; Self { @@ -73,6 +74,11 @@ impl HotbarHud { if let Some(block) = self.blocks[slot as usize] { let x = (-92 + 20 * slot as i32) as f32; let texture_indices = block.texture_indices(); + let color = block.color(); + + let color_left = color.mul_element_wise(Vector4::new(0.5, 0.5, 0.5, 1.0)).into(); + let color_front = color.mul_element_wise(Vector4::new(0.15, 0.15, 0.15, 1.0)).into(); + let color_top = color.into(); vertices.extend(&[ // Left face @@ -80,25 +86,25 @@ impl HotbarHud { position: [UI_SCALE_X * (x + 12.0), -1.0 + UI_SCALE_Y * 3.5], texture_coordinates: [1.0, 1.0], texture_index: texture_indices.0 as i32, - value: 0.5, + color: color_left, }, HudVertex { position: [UI_SCALE_X * (x + 5.0), -1.0 + UI_SCALE_Y * 6.5], texture_coordinates: [0.0, 1.0], texture_index: texture_indices.0 as i32, - value: 0.5, + color: color_left, }, HudVertex { position: [UI_SCALE_X * (x + 5.0), -1.0 + UI_SCALE_Y * 15.5], texture_coordinates: [0.0, 0.0], texture_index: texture_indices.0 as i32, - value: 0.5, + color: color_left, }, HudVertex { position: [UI_SCALE_X * (x + 12.0), -1.0 + UI_SCALE_Y * 12.5], texture_coordinates: [1.0, 0.0], texture_index: texture_indices.0 as i32, - value: 0.5, + color: color_left, }, // Front face @@ -106,25 +112,25 @@ impl HotbarHud { position: [UI_SCALE_X * (x + 19.0), -1.0 + UI_SCALE_Y * 15.5], texture_coordinates: [1.0, 0.0], texture_index: texture_indices.3 as i32, - value: 0.15, + color: color_front, }, HudVertex { position: [UI_SCALE_X * (x + 12.0), -1.0 + UI_SCALE_Y * 12.5], texture_coordinates: [0.0, 0.0], texture_index: texture_indices.3 as i32, - value: 0.15, + color: color_front, }, HudVertex { position: [UI_SCALE_X * (x + 12.0), -1.0 + UI_SCALE_Y * 3.5], texture_coordinates: [0.0, 1.0], texture_index: texture_indices.3 as i32, - value: 0.15, + color: color_front, }, HudVertex { position: [UI_SCALE_X * (x + 19.0), -1.0 + UI_SCALE_Y * 6.5], texture_coordinates: [1.0, 1.0], texture_index: texture_indices.3 as i32, - value: 0.15, + color: color_front, }, // Top face @@ -132,25 +138,25 @@ impl HotbarHud { position: [UI_SCALE_X * (x + 19.0), -1.0 + UI_SCALE_Y * 15.5], texture_coordinates: [1.0, 0.0], texture_index: texture_indices.5 as i32, - value: 1.0, + color: color_top, }, HudVertex { position: [UI_SCALE_X * (x + 12.0), -1.0 + UI_SCALE_Y * 18.5], texture_coordinates: [0.0, 0.0], texture_index: texture_indices.5 as i32, - value: 1.0, + color: color_top, }, HudVertex { position: [UI_SCALE_X * (x + 5.0), -1.0 + UI_SCALE_Y * 15.5], texture_coordinates: [0.0, 1.0], texture_index: texture_indices.5 as i32, - value: 1.0, + color: color_top, }, HudVertex { position: [UI_SCALE_X * (x + 12.0), -1.0 + UI_SCALE_Y * 12.5], texture_coordinates: [1.0, 1.0], texture_index: texture_indices.5 as i32, - value: 1.0, + color: color_top, }, ]); diff --git a/src/hud/widgets_hud.rs b/src/hud/widgets_hud.rs index 39e9c44..1b441fb 100644 --- a/src/hud/widgets_hud.rs +++ b/src/hud/widgets_hud.rs @@ -112,14 +112,14 @@ impl WidgetsHud { pub fn redraw_hotbar_cursor(&self, render_context: &RenderContext) { let x = (-92 + 20 * self.hotbar_cursor_position as i32) as f32; let texture_index = 0; - let value = 1.0; + let color = [1.0; 4]; #[rustfmt::skip] let vertices = [ - HudVertex { position: [UI_SCALE_X * (x ), -1.0 + UI_SCALE_Y * 23.0], texture_coordinates: [ 0.0 / 256.0, 22.0 / 256.0], texture_index, value }, - HudVertex { position: [UI_SCALE_X * (x + 24.0), -1.0 + UI_SCALE_Y * 23.0], texture_coordinates: [ 24.0 / 256.0, 22.0 / 256.0], texture_index, value }, - HudVertex { position: [UI_SCALE_X * (x + 24.0), -1.0 + UI_SCALE_Y * -1.0], texture_coordinates: [ 24.0 / 256.0, 46.0 / 256.0], texture_index, value }, - HudVertex { position: [UI_SCALE_X * (x ), -1.0 + UI_SCALE_Y * -1.0], texture_coordinates: [ 0.0 / 256.0, 46.0 / 256.0], texture_index, value }, + HudVertex { position: [UI_SCALE_X * (x ), -1.0 + UI_SCALE_Y * 23.0], texture_coordinates: [ 0.0 / 256.0, 22.0 / 256.0], texture_index, color }, + HudVertex { position: [UI_SCALE_X * (x + 24.0), -1.0 + UI_SCALE_Y * 23.0], texture_coordinates: [ 24.0 / 256.0, 22.0 / 256.0], texture_index, color }, + HudVertex { position: [UI_SCALE_X * (x + 24.0), -1.0 + UI_SCALE_Y * -1.0], texture_coordinates: [ 24.0 / 256.0, 46.0 / 256.0], texture_index, color }, + HudVertex { position: [UI_SCALE_X * (x ), -1.0 + UI_SCALE_Y * -1.0], texture_coordinates: [ 0.0 / 256.0, 46.0 / 256.0], texture_index, color }, ]; render_context.queue.write_buffer( @@ -143,22 +143,22 @@ impl WidgetsHud { #[rustfmt::skip] pub const VERTICES: [HudVertex; 12] = [ // Crosshair - HudVertex { position: [UI_SCALE_X * -8.0, UI_SCALE_Y * 8.0], texture_coordinates: [240.0 / 256.0, 0.0 / 256.0], texture_index: 0, value: 1.0 }, - HudVertex { position: [UI_SCALE_X * 8.0, UI_SCALE_Y * 8.0], texture_coordinates: [ 1.0, 0.0 / 256.0], texture_index: 0, value: 1.0 }, - HudVertex { position: [UI_SCALE_X * 8.0, UI_SCALE_Y * -8.0], texture_coordinates: [ 1.0, 16.0 / 256.0], texture_index: 0, value: 1.0 }, - HudVertex { position: [UI_SCALE_X * -8.0, UI_SCALE_Y * -8.0], texture_coordinates: [240.0 / 256.0, 16.0 / 256.0], texture_index: 0, value: 1.0 }, + HudVertex { position: [UI_SCALE_X * -8.0, UI_SCALE_Y * 8.0], texture_coordinates: [240.0 / 256.0, 0.0 / 256.0], texture_index: 0, color: [1.0; 4] }, + HudVertex { position: [UI_SCALE_X * 8.0, UI_SCALE_Y * 8.0], texture_coordinates: [ 1.0, 0.0 / 256.0], texture_index: 0, color: [1.0; 4] }, + HudVertex { position: [UI_SCALE_X * 8.0, UI_SCALE_Y * -8.0], texture_coordinates: [ 1.0, 16.0 / 256.0], texture_index: 0, color: [1.0; 4] }, + HudVertex { position: [UI_SCALE_X * -8.0, UI_SCALE_Y * -8.0], texture_coordinates: [240.0 / 256.0, 16.0 / 256.0], texture_index: 0, color: [1.0; 4] }, // Hotbar - HudVertex { position: [UI_SCALE_X * -91.0, -1.0 + UI_SCALE_Y * 22.0], texture_coordinates: [ 0.0 / 256.0, 0.0 / 256.0], texture_index: 0, value: 1.0 }, - HudVertex { position: [UI_SCALE_X * 91.0, -1.0 + UI_SCALE_Y * 22.0], texture_coordinates: [182.0 / 256.0, 0.0 / 256.0], texture_index: 0, value: 1.0 }, - HudVertex { position: [UI_SCALE_X * 91.0, -1.0 ], texture_coordinates: [182.0 / 256.0, 22.0 / 256.0], texture_index: 0, value: 1.0 }, - HudVertex { position: [UI_SCALE_X * -91.0, -1.0 ], texture_coordinates: [ 0.0 / 256.0, 22.0 / 256.0], texture_index: 0, value: 1.0 }, + HudVertex { position: [UI_SCALE_X * -91.0, -1.0 + UI_SCALE_Y * 22.0], texture_coordinates: [ 0.0 / 256.0, 0.0 / 256.0], texture_index: 0, color: [1.0; 4] }, + HudVertex { position: [UI_SCALE_X * 91.0, -1.0 + UI_SCALE_Y * 22.0], texture_coordinates: [182.0 / 256.0, 0.0 / 256.0], texture_index: 0, color: [1.0; 4] }, + HudVertex { position: [UI_SCALE_X * 91.0, -1.0 ], texture_coordinates: [182.0 / 256.0, 22.0 / 256.0], texture_index: 0, color: [1.0; 4] }, + HudVertex { position: [UI_SCALE_X * -91.0, -1.0 ], texture_coordinates: [ 0.0 / 256.0, 22.0 / 256.0], texture_index: 0, color: [1.0; 4] }, // Hotbar cursor - HudVertex { position: [UI_SCALE_X * -92.0, -1.0 + UI_SCALE_Y * 23.0], texture_coordinates: [ 0.0 / 256.0, 22.0 / 256.0], texture_index: 0, value: 1.0 }, - HudVertex { position: [UI_SCALE_X * -68.0, -1.0 + UI_SCALE_Y * 23.0], texture_coordinates: [ 24.0 / 256.0, 22.0 / 256.0], texture_index: 0, value: 1.0 }, - HudVertex { position: [UI_SCALE_X * -68.0, -1.0 + UI_SCALE_Y * -1.0], texture_coordinates: [ 24.0 / 256.0, 46.0 / 256.0], texture_index: 0, value: 1.0 }, - HudVertex { position: [UI_SCALE_X * -92.0, -1.0 + UI_SCALE_Y * -1.0], texture_coordinates: [ 0.0 / 256.0, 46.0 / 256.0], texture_index: 0, value: 1.0 }, + HudVertex { position: [UI_SCALE_X * -92.0, -1.0 + UI_SCALE_Y * 23.0], texture_coordinates: [ 0.0 / 256.0, 22.0 / 256.0], texture_index: 0, color: [1.0; 4] }, + HudVertex { position: [UI_SCALE_X * -68.0, -1.0 + UI_SCALE_Y * 23.0], texture_coordinates: [ 24.0 / 256.0, 22.0 / 256.0], texture_index: 0, color: [1.0; 4] }, + HudVertex { position: [UI_SCALE_X * -68.0, -1.0 + UI_SCALE_Y * -1.0], texture_coordinates: [ 24.0 / 256.0, 46.0 / 256.0], texture_index: 0, color: [1.0; 4] }, + HudVertex { position: [UI_SCALE_X * -92.0, -1.0 + UI_SCALE_Y * -1.0], texture_coordinates: [ 0.0 / 256.0, 46.0 / 256.0], texture_index: 0, color: [1.0; 4] }, ]; #[rustfmt::skip] diff --git a/src/shaders/ui.wgsl b/src/shaders/ui.wgsl index df3da54..528a389 100644 --- a/src/shaders/ui.wgsl +++ b/src/shaders/ui.wgsl @@ -2,14 +2,14 @@ struct VertexInput { [[location(0)]] position: vec2; [[location(1)]] texture_coordinates: vec2; [[location(2)]] texture_index: i32; - [[location(3)]] value: f32; + [[location(3)]] color: vec4; }; struct VertexOutput { [[builtin(position)]] clip_position: vec4; [[location(0)]] texture_coordinates: vec2; [[location(1)]] texture_index: i32; - [[location(2)]] value: f32; + [[location(2)]] color: vec4; }; [[stage(vertex)]] @@ -18,7 +18,7 @@ fn main(model: VertexInput) -> VertexOutput { out.texture_coordinates = model.texture_coordinates; out.clip_position = vec4(model.position, 0.0, 1.0); out.texture_index = model.texture_index; - out.value = model.value; + out.color = model.color; return out; } @@ -28,5 +28,5 @@ fn main(model: VertexInput) -> VertexOutput { [[stage(fragment)]] fn main(in: VertexOutput) -> [[location(0)]] vec4 { return textureSample(texture, sampler, in.texture_coordinates, in.texture_index) - * vec4(vec3(in.value), 1.0); + * in.color; } diff --git a/src/shaders/world.wgsl b/src/shaders/world.wgsl index 37b15f0..54efb20 100644 --- a/src/shaders/world.wgsl +++ b/src/shaders/world.wgsl @@ -21,6 +21,7 @@ struct VertexInput { [[location(2)]] normal: vec3; [[location(3)]] highlighted: i32; [[location(4)]] texture_id: i32; + [[location(5)]] color: vec4; }; struct VertexOutput { @@ -30,6 +31,7 @@ struct VertexOutput { [[location(2)]] world_position: vec3; [[location(3)]] highlighted: i32; [[location(4)]] texture_id: i32; + [[location(5)]] color: vec4; }; let pi: f32 = 3.14159265359; @@ -53,6 +55,7 @@ fn main(model: VertexInput) -> VertexOutput { out.clip_position = view.projection * vec4(out.world_position, 1.0); out.highlighted = model.highlighted; + out.color = model.color; return out; } @@ -66,7 +69,7 @@ fn main(in: VertexOutput) -> [[location(0)]] vec4 { texture_sampler, in.texture_coordinates, in.texture_id - ); + ) * in.color; let light_position = vec3(-100.0, 500.0, -200.0); let light_color = vec3(1.0, 1.0, 1.0); diff --git a/src/text_renderer.rs b/src/text_renderer.rs index 3f6d07e..434aa4d 100644 --- a/src/text_renderer.rs +++ b/src/text_renderer.rs @@ -107,10 +107,10 @@ impl TextRenderer { #[rustfmt::skip] let vertices = [ - HudVertex { position: [x, y ], texture_coordinates: [tx, ty ], texture_index: 0, value: 1.0 }, - HudVertex { position: [x + DX, y ], texture_coordinates: [tx + s, ty ], texture_index: 0, value: 1.0 }, - HudVertex { position: [x + DX, y - DY], texture_coordinates: [tx + s, ty + s], texture_index: 0, value: 1.0 }, - HudVertex { position: [x, y - DY], texture_coordinates: [tx, ty + s], texture_index: 0, value: 1.0 }, + HudVertex { position: [x, y ], texture_coordinates: [tx, ty ], texture_index: 0, color: [1.0; 4]}, + HudVertex { position: [x + DX, y ], texture_coordinates: [tx + s, ty ], texture_index: 0, color: [1.0; 4]}, + HudVertex { position: [x + DX, y - DY], texture_coordinates: [tx + s, ty + s], texture_index: 0, color: [1.0; 4]}, + HudVertex { position: [x, y - DY], texture_coordinates: [tx, ty + s], texture_index: 0, color: [1.0; 4]}, ]; #[rustfmt::skip] diff --git a/src/texture.rs b/src/texture.rs index 55809b8..0f4ff99 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -114,7 +114,7 @@ impl Texture { } } -pub const TEXTURE_COUNT: usize = 43; +pub const TEXTURE_COUNT: usize = 44; pub struct TextureManager { pub bind_group_layout: wgpu::BindGroupLayout, @@ -189,6 +189,7 @@ impl TextureManager { self.load(render_context, "assets/block/oak_log.png")?; // 40 self.load(render_context, "assets/block/oak_log_top.png")?; // 41 self.load(render_context, "assets/block/oak_planks.png")?; // 42 + self.load(render_context, "assets/block/oak_leaves.png")?; // 43 assert_eq!(TEXTURE_COUNT, self.textures.len()); let texture_array = render_context diff --git a/src/vertex.rs b/src/vertex.rs index 81d9c82..c397b61 100644 --- a/src/vertex.rs +++ b/src/vertex.rs @@ -17,14 +17,14 @@ pub struct HudVertex { pub position: [f32; 2], pub texture_coordinates: [f32; 2], pub texture_index: i32, - pub value: f32, + pub color: [f32; 4], } const HUD_VERTEX_ATTRIBUTES: &[VertexAttribute] = &wgpu::vertex_attr_array![ 0 => Float32x2, 1 => Float32x2, 2 => Sint32, - 3 => Float32, + 3 => Float32x4, ]; impl Vertex for HudVertex { @@ -40,8 +40,8 @@ impl Vertex for HudVertex { /// Represents a vertex in world geometry. /// /// Aside from the usual vertex position, texture coordinates and normal, this "vertex" also -/// contains whether the block is highlighted (i.e. the player is pointing at the block) and its -/// texture index (to address the texture arrays) +/// contains whether the block is highlighted (i.e. the player is pointing at the block), its +/// texture index (to address the texture arrays) and a color multiplier. #[repr(C)] #[derive(Copy, Clone, Debug, Default, bytemuck::Pod, bytemuck::Zeroable)] pub struct BlockVertex { @@ -50,6 +50,7 @@ pub struct BlockVertex { pub normal: [f32; 3], pub highlighted: i32, pub texture_id: i32, + pub color: [f32; 4], } const BLOCK_VERTEX_ATTRIBUTES: &[VertexAttribute] = &wgpu::vertex_attr_array![ @@ -58,6 +59,7 @@ const BLOCK_VERTEX_ATTRIBUTES: &[VertexAttribute] = &wgpu::vertex_attr_array![ 2 => Float32x3, 3 => Sint32, 4 => Sint32, + 5 => Float32x4, ]; impl Vertex for BlockVertex { diff --git a/src/world/block.rs b/src/world/block.rs index d52816c..a62831e 100644 --- a/src/world/block.rs +++ b/src/world/block.rs @@ -1,3 +1,4 @@ +use cgmath::Vector4; use serde::{Deserialize, Serialize}; use serde_repr::{Deserialize_repr, Serialize_repr}; @@ -15,6 +16,7 @@ pub enum BlockType { Water, OakLog, OakPlanks, + OakLeaves, } impl BlockType { @@ -31,6 +33,15 @@ impl BlockType { BlockType::Water => ( 8, 8, 8, 8, 8, 8), // up to 39 BlockType::OakLog => (40, 40, 40, 40, 41, 41), BlockType::OakPlanks => (42, 42, 42, 42, 42, 42), + BlockType::OakLeaves => (43, 43, 43, 43, 43, 43), + } + } + + pub const fn color(self) -> Vector4 { + match self { + Self::Water => Vector4::new(0.1540, 0.2885, 0.5575, 1.0), + Self::OakLeaves => Vector4::new(0.4784, 0.7294, 0.1255, 1.0), + _ => Vector4::new(1.0, 1.0, 1.0, 1.0), } } diff --git a/src/world/npc.rs b/src/world/npc.rs index 18ad5ed..393874e 100644 --- a/src/world/npc.rs +++ b/src/world/npc.rs @@ -47,6 +47,7 @@ impl Npc { normal, highlighted: 0, texture_id: 0, + color: [1.0, 1.0, 1.0, 1.0], }; vertices.push(current_vert); diff --git a/src/world/quad.rs b/src/world/quad.rs index 899450b..6d71c94 100644 --- a/src/world/quad.rs +++ b/src/world/quad.rs @@ -1,4 +1,4 @@ -use cgmath::{Point3, Vector3, Zero}; +use cgmath::{Point3, Vector3, Vector4, Zero}; use crate::{ geometry::Geometry, @@ -58,10 +58,11 @@ impl Quad { let y = self.position.y as f32; let z = self.position.z as f32; - let t = match self.block_type { - Some(block_type) => block_type.texture_indices(), - None => (0, 0, 0, 0, 0, 0), + let (t, color) = match self.block_type { + Some(block_type) => (block_type.texture_indices(), block_type.color()), + None => ((0, 0, 0, 0, 0, 0), Vector4::new(1.0, 1.0, 1.0, 1.0)), }; + let color = color.into(); let mut current_index = start_index; let mut vertices = Vec::new(); @@ -72,10 +73,10 @@ impl Quad { let highlighted = (self.highlighted_normal == normal) as i32; let normal = normal.cast().unwrap().into(); vertices.extend(&[ - BlockVertex { position: [x, y, z ], texture_coordinates: [dz, 1.0], texture_id: t.0 as i32, normal, highlighted }, - BlockVertex { position: [x, y, z + dz], texture_coordinates: [0.0, 1.0], texture_id: t.0 as i32, normal, highlighted }, - BlockVertex { position: [x, y + dy, z + dz], texture_coordinates: [0.0, 0.0], texture_id: t.0 as i32, normal, highlighted }, - BlockVertex { position: [x, y + dy, z ], texture_coordinates: [dz, 0.0], texture_id: t.0 as i32, normal, highlighted }, + BlockVertex { position: [x, y, z ], texture_coordinates: [dz, 1.0], texture_id: t.0 as i32, normal, highlighted, color }, + BlockVertex { position: [x, y, z + dz], texture_coordinates: [0.0, 1.0], texture_id: t.0 as i32, normal, highlighted, color }, + BlockVertex { position: [x, y + dy, z + dz], texture_coordinates: [0.0, 0.0], texture_id: t.0 as i32, normal, highlighted, color }, + BlockVertex { position: [x, y + dy, z ], texture_coordinates: [dz, 0.0], texture_id: t.0 as i32, normal, highlighted, color }, ]); indices.extend(&[ 2 + current_index, current_index, 1 + current_index, @@ -89,10 +90,10 @@ impl Quad { let highlighted = (self.highlighted_normal == normal) as i32; let normal = normal.cast().unwrap().into(); vertices.extend(&[ - BlockVertex { position: [x + dx, y, z ], texture_coordinates: [0.0, 1.0], texture_id: t.1 as i32, normal, highlighted }, - BlockVertex { position: [x + dx, y, z + dz], texture_coordinates: [dz, 1.0], texture_id: t.1 as i32, normal, highlighted }, - BlockVertex { position: [x + dx, y + dy, z + dz], texture_coordinates: [dz, 0.0], texture_id: t.1 as i32, normal, highlighted }, - BlockVertex { position: [x + dx, y + dy, z ], texture_coordinates: [0.0, 0.0], texture_id: t.1 as i32, normal, highlighted }, + BlockVertex { position: [x + dx, y, z ], texture_coordinates: [0.0, 1.0], texture_id: t.1 as i32, normal, highlighted, color }, + BlockVertex { position: [x + dx, y, z + dz], texture_coordinates: [dz, 1.0], texture_id: t.1 as i32, normal, highlighted, color }, + BlockVertex { position: [x + dx, y + dy, z + dz], texture_coordinates: [dz, 0.0], texture_id: t.1 as i32, normal, highlighted, color }, + BlockVertex { position: [x + dx, y + dy, z ], texture_coordinates: [0.0, 0.0], texture_id: t.1 as i32, normal, highlighted, color }, ]); indices.extend(&[ 1 + current_index, current_index, 2 + current_index, @@ -106,10 +107,10 @@ impl Quad { let highlighted = (self.highlighted_normal == normal) as i32; let normal = normal.cast().unwrap().into(); vertices.extend(&[ - BlockVertex { position: [x, y, z], texture_coordinates: [dx, 1.0], texture_id: t.2 as i32, normal, highlighted }, - BlockVertex { position: [x, y + dy, z], texture_coordinates: [dx, 0.0], texture_id: t.2 as i32, normal, highlighted }, - BlockVertex { position: [x + dx, y + dy, z], texture_coordinates: [0.0, 0.0], texture_id: t.2 as i32, normal, highlighted }, - BlockVertex { position: [x + dx, y, z], texture_coordinates: [0.0, 1.0], texture_id: t.2 as i32, normal, highlighted }, + BlockVertex { position: [x, y, z], texture_coordinates: [dx, 1.0], texture_id: t.2 as i32, normal, highlighted, color }, + BlockVertex { position: [x, y + dy, z], texture_coordinates: [dx, 0.0], texture_id: t.2 as i32, normal, highlighted, color }, + BlockVertex { position: [x + dx, y + dy, z], texture_coordinates: [0.0, 0.0], texture_id: t.2 as i32, normal, highlighted, color }, + BlockVertex { position: [x + dx, y, z], texture_coordinates: [0.0, 1.0], texture_id: t.2 as i32, normal, highlighted, color }, ]); indices.extend(&[ 2 + current_index, current_index, 1 + current_index, @@ -123,10 +124,10 @@ impl Quad { let highlighted = (self.highlighted_normal == normal) as i32; let normal = normal.cast().unwrap().into(); vertices.extend(&[ - BlockVertex { position: [x, y, z + dz], texture_coordinates: [0.0, 1.0], texture_id: t.3 as i32, normal, highlighted }, - BlockVertex { position: [x, y + dy, z + dz], texture_coordinates: [0.0, 0.0], texture_id: t.3 as i32, normal, highlighted }, - BlockVertex { position: [x + dx, y + dy, z + dz], texture_coordinates: [dx, 0.0], texture_id: t.3 as i32, normal, highlighted }, - BlockVertex { position: [x + dx, y, z + dz], texture_coordinates: [dx, 1.0], texture_id: t.3 as i32, normal, highlighted }, + BlockVertex { position: [x, y, z + dz], texture_coordinates: [0.0, 1.0], texture_id: t.3 as i32, normal, highlighted, color }, + BlockVertex { position: [x, y + dy, z + dz], texture_coordinates: [0.0, 0.0], texture_id: t.3 as i32, normal, highlighted, color }, + BlockVertex { position: [x + dx, y + dy, z + dz], texture_coordinates: [dx, 0.0], texture_id: t.3 as i32, normal, highlighted, color }, + BlockVertex { position: [x + dx, y, z + dz], texture_coordinates: [dx, 1.0], texture_id: t.3 as i32, normal, highlighted, color }, ]); indices.extend(&[ 1 + current_index, current_index, 2 + current_index, @@ -140,10 +141,10 @@ impl Quad { let highlighted = (self.highlighted_normal == normal) as i32; let normal = normal.cast().unwrap().into(); vertices.extend(&[ - BlockVertex { position: [x, y, z ], texture_coordinates: [dx, 0.0], texture_id: t.4 as i32, normal, highlighted }, - BlockVertex { position: [x, y, z + dz], texture_coordinates: [dx, dz ], texture_id: t.4 as i32, normal, highlighted }, - BlockVertex { position: [x + dx, y, z + dz], texture_coordinates: [0.0, dz ], texture_id: t.4 as i32, normal, highlighted }, - BlockVertex { position: [x + dx, y, z ], texture_coordinates: [0.0, 0.0], texture_id: t.4 as i32, normal, highlighted }, + BlockVertex { position: [x, y, z ], texture_coordinates: [dx, 0.0], texture_id: t.4 as i32, normal, highlighted, color }, + BlockVertex { position: [x, y, z + dz], texture_coordinates: [dx, dz ], texture_id: t.4 as i32, normal, highlighted, color }, + BlockVertex { position: [x + dx, y, z + dz], texture_coordinates: [0.0, dz ], texture_id: t.4 as i32, normal, highlighted, color }, + BlockVertex { position: [x + dx, y, z ], texture_coordinates: [0.0, 0.0], texture_id: t.4 as i32, normal, highlighted, color }, ]); indices.extend(&[ current_index, 2 + current_index, 1 + current_index, @@ -157,10 +158,10 @@ impl Quad { let highlighted = (self.highlighted_normal == normal) as i32; let normal = normal.cast().unwrap().into(); vertices.extend(&[ - BlockVertex { position: [x, y + dy, z ], texture_coordinates: [0.0, 0.0], texture_id: t.5 as i32, normal, highlighted }, - BlockVertex { position: [x, y + dy, z + dz], texture_coordinates: [0.0, dz ], texture_id: t.5 as i32, normal, highlighted }, - BlockVertex { position: [x + dx, y + dy, z + dz], texture_coordinates: [dx, dz ], texture_id: t.5 as i32, normal, highlighted }, - BlockVertex { position: [x + dx, y + dy, z ], texture_coordinates: [dx, 0.0], texture_id: t.5 as i32, normal, highlighted }, + BlockVertex { position: [x, y + dy, z ], texture_coordinates: [0.0, 0.0], texture_id: t.5 as i32, normal, highlighted, color }, + BlockVertex { position: [x, y + dy, z + dz], texture_coordinates: [0.0, dz ], texture_id: t.5 as i32, normal, highlighted, color }, + BlockVertex { position: [x + dx, y + dy, z + dz], texture_coordinates: [dx, dz ], texture_id: t.5 as i32, normal, highlighted, color }, + BlockVertex { position: [x + dx, y + dy, z ], texture_coordinates: [dx, 0.0], texture_id: t.5 as i32, normal, highlighted, color }, ]); indices.extend(&[ current_index, 1 + current_index, 2 + current_index,