src/shaders.wgsl
1@group(0) @binding(0) var<uniform> scale: vec2f;
2@group(0) @binding(1) var texture: texture_2d<f32>;
3
4struct VertexInput {
5 @location(0) position: vec2f,
6 @location(1) color: vec4f,
7 @location(2) uv: vec2f,
8};
9
10struct VertexOutput {
11 @builtin(position) position: vec4f,
12 // Passed to the fragment shader
13 @location(0) color: vec4f,
14 @location(1) uv: vec2f,
15};
16
17@vertex
18fn vertex_shader(in: VertexInput) -> VertexOutput {
19 var out: VertexOutput;
20 out.position = vec4f(
21 in.position.x / scale.x - 1,
22 1 - in.position.y / scale.y,
23 0, 1
24 );
25 out.color = in.color;
26 out.uv = in.uv;
27 return out;
28}
29
30@fragment
31fn fragment_shader(in: VertexOutput) -> @location(0) vec4f {
32 let texel_coords = vec2i(in.uv * vec2f(textureDimensions(texture)));
33 let texture_color = textureLoad(texture, texel_coords, 0).rgba;
34 if any(in.uv < vec2f(0, 0)) {
35 return in.color;
36 } else {
37 return texture_color;
38 }
39}