1[[block]] 2struct Uniforms { 3 u_scale : vec2<f32>; 4 u_offset : vec2<f32>; 5}; 6 7[[binding(0), group(0)]] var<uniform> uniforms : Uniforms; 8 9struct VertexOutputs { 10 [[location(0)]] 11 texcoords : vec2<f32>; 12 [[builtin(position)]] 13 position : vec4<f32>; 14}; 15 16[[stage(vertex)]] 17fn vs_main([[builtin(vertex_index)]] VertexIndex : u32) -> VertexOutputs { 18 var texcoord = array<vec2<f32>, 3>(vec2<f32>(-0.5, 0.0), vec2<f32>(1.5, 0.0), vec2<f32>(0.5, 2.0)); 19 var output : VertexOutputs; 20 output.position = vec4<f32>(((texcoord[VertexIndex] * 2.0) - vec2<f32>(1.0, 1.0)), 0.0, 1.0); 21 var flipY = (uniforms.u_scale.y < 0.0); 22 if (flipY) { 23 output.texcoords = ((((texcoord[VertexIndex] * uniforms.u_scale) + uniforms.u_offset) * vec2<f32>(1.0, -1.0)) + vec2<f32>(0.0, 1.0)); 24 } else { 25 output.texcoords = ((((texcoord[VertexIndex] * vec2<f32>(1.0, -1.0)) + vec2<f32>(0.0, 1.0)) * uniforms.u_scale) + uniforms.u_offset); 26 } 27 return output; 28} 29 30[[binding(1), group(0)]] var mySampler : sampler; 31 32[[binding(2), group(0)]] var myTexture : texture_2d<f32>; 33 34[[stage(fragment)]] 35fn fs_main([[location(0)]] texcoord : vec2<f32>) -> [[location(0)]] vec4<f32> { 36 var clampedTexcoord = clamp(texcoord, vec2<f32>(0.0, 0.0), vec2<f32>(1.0, 1.0)); 37 if (!(all((clampedTexcoord == texcoord)))) { 38 discard; 39 } 40 var srcColor = textureSample(myTexture, mySampler, texcoord); 41 return srcColor; 42} 43