WebGPU Voxel Game
at main 1.2 kB view raw
1// Vertex shader 2 3// TODO CITE 4// Somewhat referenced from: 5// https://github.com/gfx-rs/wgpu/blob/trunk/examples/features/src/shadow/shader.wgsl 6 7struct InstanceInput { 8 @location(5) model_matrix_0: vec4<f32>, 9 @location(6) model_matrix_1: vec4<f32>, 10 @location(7) model_matrix_2: vec4<f32>, 11 @location(8) model_matrix_3: vec4<f32>, 12 13 @location(9) normal_matrix_0: vec3<f32>, 14 @location(10) normal_matrix_1: vec3<f32>, 15 @location(11) normal_matrix_2: vec3<f32>, 16}; 17 18struct Camera { 19 view_pos: vec4<f32>, 20 view_proj: mat4x4<f32>, 21} 22@group(0) @binding(0) 23var<uniform> camera: Camera; 24 25@group(0) @binding(1) 26var<uniform> light: Camera; 27 28struct VertexInput { 29 @location(0) position: vec3<f32>, 30 @location(1) tex_coords: vec2<f32>, 31 @location(2) normal: vec3<f32>, 32} 33 34@vertex 35fn vs_main( 36 model: VertexInput, 37 instance: InstanceInput, 38) -> @builtin(position) vec4<f32> { 39 40 let model_matrix = mat4x4<f32> ( 41 instance.model_matrix_0, 42 instance.model_matrix_1, 43 instance.model_matrix_2, 44 instance.model_matrix_3, 45 ); 46 47 let world_position: vec4<f32> = model_matrix * vec4<f32>(model.position, 1.0); 48 49 return light.view_proj * world_position; 50}