| 1 | // Mipmap generation: each level is a bilinear 2×2 average of the one above. |
| 2 | |
| 3 | @group(0) @binding(0) var src: texture_2d<f32>; |
| 4 | @group(0) @binding(1) var samp: sampler; |
| 5 | |
| 6 | struct VOut { |
| 7 | @builtin(position) pos: vec4<f32>, |
| 8 | @location(0) uv: vec2<f32>, |
| 9 | }; |
| 10 | |
| 11 | @vertex |
| 12 | fn vs(@builtin(vertex_index) i: u32) -> VOut { |
| 13 | // One oversized triangle covering the target. |
| 14 | let uv = vec2(f32((i << 1u) & 2u), f32(i & 2u)); |
| 15 | var out: VOut; |
| 16 | out.pos = vec4(uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0, 0.0, 1.0); |
| 17 | out.uv = uv; |
| 18 | return out; |
| 19 | } |
| 20 | |
| 21 | @fragment |
| 22 | fn fs(in: VOut) -> @location(0) vec4<f32> { |
| 23 | return textureSample(src, samp, in.uv); |
| 24 | } |