struct Globals { mvp_transform: mat4x4, sprite_size: vec2, }; var globals: Globals; struct Locals { position: vec2, velocity: vec2, color: u32, }; var locals: Locals; var sprite_texture: texture_2d; var sprite_sampler: sampler; struct VertexOutput { @builtin(position) position: vec4, @location(0) tex_coords: vec2, @location(1) color: vec4, } fn unpack_color(raw: u32) -> vec4 { //TODO: https://github.com/gfx-rs/naga/issues/2188 //return unpack4x8unorm(raw); return vec4((vec4(raw) >> vec4(0u, 8u, 16u, 24u)) & vec4(0xFFu)) / 255.0; } @vertex fn vs_main(@builtin(vertex_index) vi: u32) -> VertexOutput { let tc = vec2(f32(vi & 1u), 0.5 * f32(vi & 2u)); let offset = tc * globals.sprite_size; let pos = globals.mvp_transform * vec4(locals.position + offset, 0.0, 1.0); let color = unpack_color(locals.color); return VertexOutput(pos, tc, color); } @fragment fn fs_main(vertex: VertexOutput) -> @location(0) vec4 { return vertex.color * textureSampleLevel(sprite_texture, sprite_sampler, vertex.tex_coords, 0.0); }