summaryrefslogtreecommitdiffstats
path: root/wgpu/src/shader/image.wgsl
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2021-05-24 20:26:56 +0700
committerLibravatar GitHub <noreply@github.com>2021-05-24 20:26:56 +0700
commitdf971ac99beedb41537763f95f7b14d8bf7475a8 (patch)
tree70bf9d7aac84ae05f841b51dca6eb66c1769de93 /wgpu/src/shader/image.wgsl
parent3918257883dba3cf260bd9764cb7b34101c435e6 (diff)
parent4cbc34524598756ce18cb25a664bc6f256d42851 (diff)
downloadiced-df971ac99beedb41537763f95f7b14d8bf7475a8.tar.gz
iced-df971ac99beedb41537763f95f7b14d8bf7475a8.tar.bz2
iced-df971ac99beedb41537763f95f7b14d8bf7475a8.zip
Merge pull request #830 from Dispersia/upgrade-wgpu
Upgrade wgpu
Diffstat (limited to '')
-rw-r--r--wgpu/src/shader/image.wgsl47
1 files changed, 47 insertions, 0 deletions
diff --git a/wgpu/src/shader/image.wgsl b/wgpu/src/shader/image.wgsl
new file mode 100644
index 00000000..a63ee8f6
--- /dev/null
+++ b/wgpu/src/shader/image.wgsl
@@ -0,0 +1,47 @@
+[[block]]
+struct Globals {
+ transform: mat4x4<f32>;
+};
+
+[[group(0), binding(0)]] var<uniform> globals: Globals;
+[[group(0), binding(1)]] var u_sampler: sampler;
+[[group(1), binding(0)]] var u_texture: texture_2d_array<f32>;
+
+struct VertexInput {
+ [[location(0)]] v_pos: vec2<f32>;
+ [[location(1)]] pos: vec2<f32>;
+ [[location(2)]] scale: vec2<f32>;
+ [[location(3)]] atlas_pos: vec2<f32>;
+ [[location(4)]] atlas_scale: vec2<f32>;
+ [[location(5)]] layer: i32;
+};
+
+struct VertexOutput {
+ [[builtin(position)]] position: vec4<f32>;
+ [[location(0)]] uv: vec2<f32>;
+ [[location(1)]] layer: f32; // this should be an i32, but naga currently reads that as requiring interpolation.
+};
+
+[[stage(vertex)]]
+fn vs_main(input: VertexInput) -> VertexOutput {
+ var out: VertexOutput;
+
+ out.uv = vec2<f32>(input.v_pos * input.atlas_scale + input.atlas_pos);
+ out.layer = f32(input.layer);
+
+ var transform: mat4x4<f32> = mat4x4<f32>(
+ vec4<f32>(input.scale.x, 0.0, 0.0, 0.0),
+ vec4<f32>(0.0, input.scale.y, 0.0, 0.0),
+ vec4<f32>(0.0, 0.0, 1.0, 0.0),
+ vec4<f32>(input.pos, 0.0, 1.0)
+ );
+
+ out.position = globals.transform * transform * vec4<f32>(input.v_pos, 0.0, 1.0);
+
+ return out;
+}
+
+[[stage(fragment)]]
+fn fs_main(input: VertexOutput) -> [[location(0)]] vec4<f32> {
+ return textureSample(u_texture, u_sampler, input.uv, i32(input.layer));
+}