struct VertexInput { @location(0) pos: vec3, @location(1) uvs: vec2 }; struct VertexOutput { @builtin(position) clip_position: vec4, @location(0) uvs: vec2, @location(1) col: vec4 // TODO: use normals for lighting somehow }; struct Instance { @location(2) model0: vec4, @location(3) model1: vec4, @location(4) model2: vec4, @location(5) model3: vec4, @location(6) col: vec4 }; // Vertex shader struct Uniforms { view_proj: mat4x4 }; @group(1) @binding(0) var u: Uniforms; @vertex fn vs_main( in: VertexInput, obj: Instance ) -> VertexOutput { let model = mat4x4(obj.model0, obj.model1, obj.model2, obj.model3); var out: VertexOutput; out.clip_position = u.view_proj * model * vec4(in.pos, 1.0); out.uvs = in.uvs; out.col = obj.col; return out; } // Fragment shader @group(0) @binding(0) var t_diffuse: texture_2d; @group(0) @binding(1) var s_diffuse: sampler; @fragment fn fs_main(in: VertexOutput) -> @location(0) vec4 { return textureSample(t_diffuse, s_diffuse, in.uvs) * in.col; }