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