minor changes, wip shader

This commit is contained in:
griffi-gh 2023-07-17 12:58:17 +02:00
parent 6064fe0b76
commit 1ac6861610
3 changed files with 31 additions and 9 deletions

View file

@ -1,19 +1,34 @@
//TODO migrate, this is just some filler code to make the game compile struct Uniform {
position_offset: vec3<f32>,
view_proj: mat4x4<f32>,
};
@group(1) @binding(0)
var<uniform> world: Uniform;
struct VertexInput {
@location(0) position: vec3<f32>,
@location(1) normal: vec3<f32>,
@location(2) uv: vec2<f32>,
@location(3) tex_index: vec2<u8>,
}
struct VertexOutput { struct VertexOutput {
@builtin(position) position: vec4<f32>, @builtin(position) clip_position: vec4<f32>,
}; @location(0) tex_coords: vec2<f32>,
}
@vertex @vertex
fn vs_main( fn vs_main(
@builtin(vertex_index) in_vertex_index: u32, model: VertexInput,
) -> VertexOutput { ) -> VertexOutput {
var out: VertexOutput; var out: VertexOutput;
out.position = vec4<f32>(0.0, 0.0, 0.0, 1.0); out.tex_coords = model.tex_coords;
out.clip_position = camera.view_proj * vec4<f32>(model.position, 1.0); // 2.
return out; return out;
} }
@fragment @fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> { fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(0.3, 0.2, 0.1, 1.0); return vec4(1.0, 0.0, 0.0, 0.0);
} }

View file

@ -4,7 +4,7 @@ use winit::{
window::{Window, WindowBuilder, Fullscreen}, window::{Window, WindowBuilder, Fullscreen},
dpi::PhysicalSize, dpi::PhysicalSize,
}; };
use glam::Vec3; use glam::{Vec3, Mat4};
use pollster::FutureExt as _; use pollster::FutureExt as _;
use crate::{events::WindowResizedEvent, settings::{GameSettings, FullscreenMode}}; use crate::{events::WindowResizedEvent, settings::{GameSettings, FullscreenMode}};
@ -17,6 +17,14 @@ pub mod world;
pub mod selection_box; pub mod selection_box;
pub mod entities; pub mod entities;
pub const OPENGL_TO_WGPU_MATRIX: Mat4 = Mat4::from_cols_array(&[
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 0.5, 0.0,
0.0, 0.0, 0.5, 1.0,
]);
#[derive(Unique)] #[derive(Unique)]
pub struct RenderTarget { pub struct RenderTarget {
pub output: wgpu::SurfaceTexture, pub output: wgpu::SurfaceTexture,

View file

@ -27,8 +27,7 @@ pub struct ChunkVertex {
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)] #[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
struct WorldUniform { struct WorldUniform {
position_offset: [f32; 3], position_offset: [f32; 3],
view: [[f32; 4]; 4], view_proj: [[f32; 4]; 4],
perspective: [[f32; 4]; 4],
} }
pub fn draw_world( pub fn draw_world(