pixels/shaders/scale.wgsl
Jay Oster c2454b01ab
Simplify vertex attributes (#228)
- Vertex UVs can be computed from the positions, which saves a small amount of code and a small amount of bandwidth (both inconsequential).
- This is mostly for readability.
- Fixes vertically-flipped pixel buffer in the `custom-shader` example.
2021-11-20 14:06:23 -08:00

32 lines
832 B
WebGPU Shading Language

// Vertex shader bindings
struct VertexOutput {
[[location(0)]] tex_coord: vec2<f32>;
[[builtin(position)]] position: vec4<f32>;
};
[[block]] struct Locals {
transform: mat4x4<f32>;
};
[[group(0), binding(2)]] var<uniform> r_locals: Locals;
[[stage(vertex)]]
fn vs_main(
[[location(0)]] position: vec2<f32>,
) -> VertexOutput {
var out: VertexOutput;
out.tex_coord = position * vec2<f32>(0.5, -0.5) + 0.5;
out.position = r_locals.transform * vec4<f32>(position, 0.0, 1.0);
return out;
}
// Fragment shader bindings
[[group(0), binding(0)]] var r_tex_color: texture_2d<f32>;
[[group(0), binding(1)]] var r_tex_sampler: sampler;
[[stage(fragment)]]
fn fs_main([[location(0)]] tex_coord: vec2<f32>) -> [[location(0)]] vec4<f32> {
return textureSample(r_tex_color, r_tex_sampler, tex_coord);
}