iced-yoda/wgpu/src/shader/blit.wgsl

38 lines
924 B
WebGPU Shading Language
Raw Normal View History

var<private> uvs: array<vec2<f32>, 6> = array<vec2<f32>, 6>(
2021-04-11 18:55:57 -07:00
vec2<f32>(0.0, 0.0),
vec2<f32>(1.0, 0.0),
2021-04-11 18:55:57 -07:00
vec2<f32>(1.0, 1.0),
vec2<f32>(0.0, 0.0),
vec2<f32>(0.0, 1.0),
2021-04-11 18:55:57 -07:00
vec2<f32>(1.0, 1.0)
);
2022-07-02 15:39:42 +08:00
@group(0) @binding(0) var u_sampler: sampler;
@group(0) @binding(1) var<uniform> u_ratio: vec4<f32>;
2022-07-02 15:39:42 +08:00
@group(1) @binding(0) var u_texture: texture_2d<f32>;
2021-04-11 18:55:57 -07:00
struct VertexInput {
2022-07-02 15:39:42 +08:00
@builtin(vertex_index) vertex_index: u32,
2022-07-02 22:51:51 +08:00
}
2021-04-11 18:55:57 -07:00
struct VertexOutput {
2022-07-02 15:39:42 +08:00
@builtin(position) position: vec4<f32>,
@location(0) uv: vec2<f32>,
2022-07-02 22:51:51 +08:00
}
2021-04-11 18:55:57 -07:00
2022-07-02 15:39:42 +08:00
@vertex
2021-04-11 18:55:57 -07:00
fn vs_main(input: VertexInput) -> VertexOutput {
let uv = uvs[input.vertex_index];
2021-04-11 18:55:57 -07:00
var out: VertexOutput;
out.uv = uv * u_ratio.xy;
out.position = vec4<f32>(uv * vec2(2.0, -2.0) + vec2(-1.0, 1.0), 0.0, 1.0);
2021-04-11 18:55:57 -07:00
return out;
}
2022-07-02 15:39:42 +08:00
@fragment
fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {
2021-04-11 18:55:57 -07:00
return textureSample(u_texture, u_sampler, input.uv);
2021-04-12 23:07:58 -07:00
}