summaryrefslogtreecommitdiffstats
path: root/assets/shaders/canvas.wgsl
diff options
context:
space:
mode:
Diffstat (limited to 'assets/shaders/canvas.wgsl')
-rw-r--r--assets/shaders/canvas.wgsl51
1 files changed, 51 insertions, 0 deletions
diff --git a/assets/shaders/canvas.wgsl b/assets/shaders/canvas.wgsl
new file mode 100644
index 0000000..0aa61b1
--- /dev/null
+++ b/assets/shaders/canvas.wgsl
@@ -0,0 +1,51 @@
+struct VertexOutput {
+ @builtin(position) clip_position: vec4<f32>,
+ @location(0) uv: vec2<f32>
+}
+
+const QUAD_VERTICES = array<vec2<f32>,4>(
+ vec2<f32>(0.0, 0.0),
+ vec2<f32>(2.0, 0.0),
+ vec2<f32>(0.0, 2.0),
+ vec2<f32>(2.0, 2.0),
+);
+
+const QUAD_UVS = array<vec2<f32>,4>(
+ vec2<f32>(0.0, 1.0),
+ vec2<f32>(1.0, 1.0),
+ vec2<f32>(0.0, 0.0),
+ vec2<f32>(1.0, 0.0),
+);
+
+@group(0) @binding(0)
+var canvas_texture: texture_2d<f32>;
+@group(0) @binding(1)
+var canvas_sampler: sampler;
+
+@group(1) @binding(0)
+var<uniform> rect: vec4<f32>;
+
+@vertex
+fn vs_main(
+ @builtin(vertex_index) index: u32,
+) -> VertexOutput {
+ var out: VertexOutput;
+
+ let model = QUAD_VERTICES[index];
+
+ out.uv = QUAD_UVS[index];
+ out.clip_position = vec4<f32>(
+ -1.0 + (model.x * rect.z),
+ -1.0 + (model.y * rect.w),
+ 0.0,
+ 1.0);
+
+ return out;
+}
+
+@fragment
+fn fs_main(in: VertexOutput)
+-> @location(0) vec4<f32>
+{
+ return textureSample(canvas_texture, canvas_sampler, in.uv);
+}