diff --git a/src/graphics.rs b/src/graphics.rs index 2ac3cf2..fb564a9 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -17,7 +17,7 @@ impl Vertex { const DESC: VertexBufferLayout<'static> = VertexBufferLayout { array_stride: std::mem::size_of::() as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Vertex, - attributes: &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x4], + attributes: &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x4, 2 => Uint32], }; } diff --git a/src/shader.wgsl b/src/shader.wgsl index 75a49da..944c794 100644 --- a/src/shader.wgsl +++ b/src/shader.wgsl @@ -16,8 +16,25 @@ fn vs_main( @location(2) effect: u32 ) -> VertexOutput { var out: VertexOutput; - out.color = color; - out.pos = vec4f((pos - uniforms.camera) * uniforms.zooms, 0, 1); + switch effect { + case 1u, 3u: { + var v = (color.r*0.299) + (color.g*0.587) + (color.b*0.114); + out.color = vec4f(v, v, v, color.a); + } + case 0u, 2u: { + out.color = color; + } + default: {} + } + switch effect { + case 0u, 1u: { + out.pos = vec4f(pos, 0, 1); + } + case 2u, 3u: { + out.pos = vec4f((pos - uniforms.camera) * uniforms.zooms, 0, 1); + } + default: {} + } return out; } diff --git a/src/state/ui.rs b/src/state/ui.rs index 33d7f39..e948cda 100644 --- a/src/state/ui.rs +++ b/src/state/ui.rs @@ -1,8 +1,8 @@ use winit::event::{Touch, TouchPhase, WindowEvent}; use crate::graphics::Vertex; -const BOTTOM_TAB_BAR_HEIGHT: f32 = 0.1; -const SECONDARY_COLOR: [f32; 4] = [255./84., 255./33., 255./32., 1.]; +const BOTTOM_TAB_BAR_HEIGHT: f32 = 0.2; +const SECONDARY_COLOR: [f32; 4] = [84./255., 33./255., 32./255., 1.]; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Kind { @@ -65,8 +65,27 @@ impl UI { } } pub fn render(&self, vertices: &mut Vec, indices: &mut Vec) { - //let vs = [ - // Vertex { color: SECONDARY_COLOR, pos: [] } - //]; + let vs = [ + // Terrain + Vertex { color: SECONDARY_COLOR, pos: [-1., -1.+(BOTTOM_TAB_BAR_HEIGHT*2.)], effect: 0 }, + Vertex { color: SECONDARY_COLOR, pos: [-1., -1.], effect: 0 }, + Vertex { color: SECONDARY_COLOR, pos: [0., -1.], effect: 0 }, + Vertex { color: SECONDARY_COLOR, pos: [0., -1.+(BOTTOM_TAB_BAR_HEIGHT*2.)], effect: 0 }, + + // Entities + // 3, + // 2, + Vertex { color: SECONDARY_COLOR, pos: [1., -1.], effect: 0 }, + Vertex { color: SECONDARY_COLOR, pos: [1., -1.+(BOTTOM_TAB_BAR_HEIGHT*2.)], effect: 0 } + ]; + let ids = [ + 0,1,2, + 2,3,0, + 3,2,4, + 4,5,3 + ]; + let i = vertices.len() as u32; + vertices.extend_from_slice(&vs); + indices.extend_from_slice(&ids.map(|id| id+i)); } }