// INCLUDE: global uniform header struct InstanceInput { @location(2) transform_matrix_0: vec4, @location(3) transform_matrix_1: vec4, @location(4) transform_matrix_2: vec4, @location(5) transform_matrix_3: vec4, @location(6) color_transform: vec4, @location(7) texture_index: u32, }; struct VertexInput { @location(0) position: vec3, @location(1) texture_coords: vec2, } struct VertexOutput { @builtin(position) position: vec4, @location(0) texture_coords: vec2, @location(1) texture_index: u32, @location(2) color_transform: vec4, } @group(0) @binding(0) var texture_array: binding_array>; @group(0) @binding(1) var sampler_array: binding_array; // INCLUDE: animate.wgsl @vertex fn vertex_main( vertex: VertexInput, instance: InstanceInput, ) -> VertexOutput { let transform = mat4x4( instance.transform_matrix_0, instance.transform_matrix_1, instance.transform_matrix_2, instance.transform_matrix_3, ); var out: VertexOutput; out.position = transform * vec4(vertex.position, 1.0); out.color_transform = instance.color_transform; // Pick texture frame let t = atlas.data[animate(instance, global.current_time.x)]; out.texture_index = u32(0); out.texture_coords = vec2(t.xpos, t.ypos); if vertex.texture_coords.x == 1.0 { out.texture_coords = vec2(out.texture_coords.x + t.width, out.texture_coords.y); } if vertex.texture_coords.y == 1.0 { out.texture_coords = vec2(out.texture_coords.x, out.texture_coords.y + t.height); } return out; } @fragment fn fragment_main(in: VertexOutput) -> @location(0) vec4 { return textureSampleLevel( texture_array[in.texture_index], sampler_array[0], in.texture_coords, 0.0 ).rgba * in.color_transform; }