mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-23 07:51:08 +01:00
33 lines
777 B
WebGPU Shading Language
33 lines
777 B
WebGPU Shading Language
struct VertexOutput {
|
|
[[builtin(position)]] position: vec4<f32>;
|
|
[[location(0)]] tex_coords: vec2<f32>;
|
|
};
|
|
|
|
[[stage(vertex)]]
|
|
fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput {
|
|
var out: VertexOutput;
|
|
let x = i32(vertex_index) / 2;
|
|
let y = i32(vertex_index) & 1;
|
|
let tc = vec2<f32>(
|
|
f32(x) * 2.0,
|
|
f32(y) * 2.0
|
|
);
|
|
out.position = vec4<f32>(
|
|
tc.x * 2.0 - 1.0,
|
|
1.0 - tc.y * 2.0,
|
|
0.0, 1.0
|
|
);
|
|
out.tex_coords = tc;
|
|
return out;
|
|
}
|
|
|
|
[[group(0), binding(0)]]
|
|
var r_color: texture_2d<f32>;
|
|
[[group(0), binding(1)]]
|
|
var r_sampler: sampler;
|
|
|
|
[[stage(fragment)]]
|
|
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
|
|
return textureSample(r_color, r_sampler, in.tex_coords);
|
|
}
|