pixels/shaders/scale.wgsl
Jay Oster c4df23f65d
Update to wgpu 0.9 (#179)
* Update to wgpu 0.9

* Fix validation error in WGSL shader

- This moves the hardcoded vertex positions and texture coordinates to
  the vertex buffer.
- Replaces the two-triangle quad to 1 full-screen triangle (fixes #180)
- Rewrites the custom shader example to fix a bug with large surface
  textures;
  - The input texture size was used for the output texture, causing the
    purple rectangle to appear very jumpy on large displays in full screen.
- The `ScalingRenderer` now exposes its clipping rectangle. The custom
  shader example uses this for its own clipping rectangle, but it can
  also be used for interacting with the border in general.

* Switch to `wgpu::include_wgsl!()`

- This is a nice little simplification.
- Thanks to @JMS55 for the suggestion!
2021-06-27 11:09:29 -07:00

33 lines
837 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 r_locals: Locals;
[[stage(vertex)]]
fn vs_main(
[[location(0)]] position: vec2<f32>,
[[location(1)]] tex_coord: vec2<f32>,
) -> VertexOutput {
var out: VertexOutput;
out.tex_coord = tex_coord;
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);
}