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