@group(0) @binding(2) var dimensions: vec2; @group(2) @binding(0) var t_image: texture_2d; @group(2) @binding(1) var s_image: sampler; struct VertexInput { @location(0) position: vec3, } struct InstanceInput { @location(1) color: vec4, @location(2) model_matrix_0: vec4, @location(3) model_matrix_1: vec4, @location(4) model_matrix_2: vec4, @location(5) model_matrix_3: vec4, }; struct VertexOutput { @builtin(position) position: vec4, @location(0) text: vec2, } @vertex fn vs_main( model: VertexInput, instance: InstanceInput, ) -> VertexOutput { var out: VertexOutput; let model_matrix = mat4x4( instance.model_matrix_0, instance.model_matrix_1, instance.model_matrix_2, instance.model_matrix_3, ); out.position = model_matrix * vec4(model.position, 1.0); out.position.z = 0.9999; // To keep the aspect ratio let dims = vec2(dimensions); if dimensions.x < dimensions.y { out.position.x = out.position.x * dims.y / dims.x; } else { out.position.y = out.position.y * dims.x / dims.y; } if model.position.x == -1.0 { out.text.x = 0.0; } else if model.position.x == 1.0 { out.text.x = 1.0; } if model.position.y == -1.0 { out.text.y = 1.0; } else if model.position.y == 1.0 { out.text.y = 0.0; } return out; } @fragment fn fs_main(in: VertexOutput) -> @location(0) vec4 { return textureSample(t_image, s_image, in.text); }