This commit is contained in:
Arkitu 2024-09-22 21:17:58 +02:00
parent 303e39bd12
commit d5cc4a3330
3 changed files with 44 additions and 8 deletions

View File

@ -17,7 +17,7 @@ impl Vertex {
const DESC: VertexBufferLayout<'static> = VertexBufferLayout { const DESC: VertexBufferLayout<'static> = VertexBufferLayout {
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress, array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex, 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],
}; };
} }

View File

@ -16,8 +16,25 @@ fn vs_main(
@location(2) effect: u32 @location(2) effect: u32
) -> VertexOutput { ) -> VertexOutput {
var out: VertexOutput; var out: VertexOutput;
out.color = color; switch effect {
out.pos = vec4f((pos - uniforms.camera) * uniforms.zooms, 0, 1); 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; return out;
} }

View File

@ -1,8 +1,8 @@
use winit::event::{Touch, TouchPhase, WindowEvent}; use winit::event::{Touch, TouchPhase, WindowEvent};
use crate::graphics::Vertex; use crate::graphics::Vertex;
const BOTTOM_TAB_BAR_HEIGHT: f32 = 0.1; const BOTTOM_TAB_BAR_HEIGHT: f32 = 0.2;
const SECONDARY_COLOR: [f32; 4] = [255./84., 255./33., 255./32., 1.]; const SECONDARY_COLOR: [f32; 4] = [84./255., 33./255., 32./255., 1.];
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Kind { pub enum Kind {
@ -65,8 +65,27 @@ impl UI {
} }
} }
pub fn render(&self, vertices: &mut Vec<Vertex>, indices: &mut Vec<u32>) { pub fn render(&self, vertices: &mut Vec<Vertex>, indices: &mut Vec<u32>) {
//let vs = [ let vs = [
// Vertex { color: SECONDARY_COLOR, pos: [] } // 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));
} }
} }