summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLizzy Fleckenstein <eliasfleckenstein@web.de>2023-04-10 19:08:30 +0200
committerLizzy Fleckenstein <eliasfleckenstein@web.de>2023-04-10 19:08:30 +0200
commit5bfa731a508492ac414a5b04bd453d528777bc1a (patch)
tree358709055e691dc0f0e40ba8c62cc8cd8ed87c60
parenta87186860ec602c19f0d11528bef2d5123bc7e48 (diff)
downloadmt_client-5bfa731a508492ac414a5b04bd453d528777bc1a.tar.xz
Param1 light and allfaces
-rw-r--r--assets/shaders/map.wgsl12
-rw-r--r--src/gfx/map.rs19
2 files changed, 26 insertions, 5 deletions
diff --git a/assets/shaders/map.wgsl b/assets/shaders/map.wgsl
index f6919a9..bb88a3f 100644
--- a/assets/shaders/map.wgsl
+++ b/assets/shaders/map.wgsl
@@ -3,11 +3,13 @@
struct VertexInput {
@location(0) pos: vec3<f32>,
@location(1) tex_coords: vec2<f32>,
+ @location(2) light: f32,
}
struct VertexOutput {
@builtin(position) pos: vec4<f32>,
@location(0) tex_coords: vec2<f32>,
+ @location(1) light: f32,
}
@group(1) @binding(0) var<uniform> view_proj: mat4x4<f32>;
@@ -20,6 +22,7 @@ fn vs_main(
var out: VertexOutput;
out.pos = view_proj * model * vec4<f32>(in.pos, 1.0);
out.tex_coords = in.tex_coords;
+ out.light = in.light;
return out;
}
@@ -30,5 +33,12 @@ fn vs_main(
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
- return textureSample(atlas_texture, atlas_sampler, in.tex_coords);
+ var color = textureSample(atlas_texture, atlas_sampler, in.tex_coords);
+
+ if color.a < 0.1 {
+ discard;
+ }
+
+ color = vec4<f32>(color.rgb * in.light, color.a);
+ return color;
}
diff --git a/src/gfx/map.rs b/src/gfx/map.rs
index d95a4d2..dbedb77 100644
--- a/src/gfx/map.rs
+++ b/src/gfx/map.rs
@@ -19,11 +19,12 @@ pub struct MapRender {
struct Vertex {
pos: [f32; 3],
tex_coords: [f32; 2],
+ light: f32,
}
impl Vertex {
- const ATTRIBS: [wgpu::VertexAttribute; 2] =
- wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x2];
+ const ATTRIBS: [wgpu::VertexAttribute; 3] =
+ wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x2, 2 => Float32];
fn desc<'a>() -> wgpu::VertexBufferLayout<'a> {
wgpu::VertexBufferLayout {
@@ -62,11 +63,20 @@ impl MapRender {
};
use lerp::Lerp;
- use mt_net::DrawType;
+ use mt_net::{DrawType, Param1Type};
use std::array::from_fn as array;
match def.draw_type {
- DrawType::Cube => {
+ DrawType::Cube | DrawType::AllFaces | DrawType::AllFacesOpt => {
+ let light = match def.param1_type {
+ Param1Type::Light => {
+ println!("{}", block.param_1[index]);
+
+ block.param_1[index] as f32 / 15.0
+ }
+ _ => 1.0,
+ };
+
let pos: [i16; 3] = array(|i| ((index >> (4 * i)) & 0xf) as i16);
for (f, face) in CUBE.iter().enumerate() {
let dir = FACE_DIR[f];
@@ -98,6 +108,7 @@ impl MapRender {
vertices.push(Vertex {
pos: array(|i| pos[i] as f32 - 8.5 + vertex.0[i]),
tex_coords: array(|i| rect[i].start.lerp(rect[i].end, vertex.1[i])),
+ light,
})
}
}