[[block]] struct Uniforms { u_scale : vec2; u_offset : vec2; }; [[binding(0), group(0)]] var uniforms : Uniforms; struct VertexOutputs { [[location(0)]] texcoords : vec2; [[builtin(position)]] position : vec4; }; [[stage(vertex)]] fn vs_main([[builtin(vertex_index)]] VertexIndex : u32) -> VertexOutputs { var texcoord = array, 3>(vec2(-0.5, 0.0), vec2(1.5, 0.0), vec2(0.5, 2.0)); var output : VertexOutputs; output.position = vec4(((texcoord[VertexIndex] * 2.0) - vec2(1.0, 1.0)), 0.0, 1.0); var flipY = (uniforms.u_scale.y < 0.0); if (flipY) { output.texcoords = ((((texcoord[VertexIndex] * uniforms.u_scale) + uniforms.u_offset) * vec2(1.0, -1.0)) + vec2(0.0, 1.0)); } else { output.texcoords = ((((texcoord[VertexIndex] * vec2(1.0, -1.0)) + vec2(0.0, 1.0)) * uniforms.u_scale) + uniforms.u_offset); } return output; } [[binding(1), group(0)]] var mySampler : sampler; [[binding(2), group(0)]] var myTexture : texture_2d; [[stage(fragment)]] fn fs_main([[location(0)]] texcoord : vec2) -> [[location(0)]] vec4 { var clampedTexcoord = clamp(texcoord, vec2(0.0, 0.0), vec2(1.0, 1.0)); if (!(all((clampedTexcoord == texcoord)))) { discard; } var srcColor = textureSample(myTexture, mySampler, texcoord); return srcColor; }