// WebGPU counterpart of the 2D image path (the WGSL port of // webgl_scene_vert/frag.glsl and the Vulkan scene shaders). // // Bind group 0: uniform { rect: vec4; }, the scene texture and a sampler. // WebGPU clip space is +Y up, matching GL, so the vertex flips Y the same way. struct SceneUniforms { rect: vec4, // xy = top-left (0..1), zw = size (0..1) }; @group(0) @binding(0) var u_scene: SceneUniforms; @group(0) @binding(1) var u_scene_tex: texture_2d; @group(0) @binding(2) var u_scene_samp: sampler; struct SceneOut { @builtin(position) position: vec4, @location(0) uv: vec2, }; @vertex fn vs_main(@builtin(vertex_index) vertex_index: u32) -> SceneOut { let p = vec2(f32((vertex_index << 1u) & 2u), f32(vertex_index & 2u)); var out: SceneOut; out.uv = (p - u_scene.rect.xy) / u_scene.rect.zw; out.position = vec4(p.x * 2.0 - 1.0, 1.0 - p.y * 2.0, 0.0, 1.0); return out; } @fragment fn fs_main(in: SceneOut) -> @location(0) vec4 { // Only the destination rect is drawn; outside it the previous contents stay. if (in.uv.x < 0.0 || in.uv.x > 1.0 || in.uv.y < 0.0 || in.uv.y > 1.0) { discard; } // The image is 0xAARRGGBB (BGRA in memory); swizzle it back. let c = textureSampleLevel(u_scene_tex, u_scene_samp, in.uv, 0.0); return vec4(c.b, c.g, c.r, c.a); }