From 9a2c78c4059d2be37d10adda397fb6e64f38ac02 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Sun, 11 Apr 2021 18:55:57 -0700 Subject: Upgrade wgpu --- wgpu/src/shader/image.wgsl | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 wgpu/src/shader/image.wgsl (limited to 'wgpu/src/shader/image.wgsl') diff --git a/wgpu/src/shader/image.wgsl b/wgpu/src/shader/image.wgsl new file mode 100644 index 00000000..c623247e --- /dev/null +++ b/wgpu/src/shader/image.wgsl @@ -0,0 +1,45 @@ +[[block]] +struct Globals { + transform: mat4x4; +}; + +[[group(0), binding(0)]] var globals: Globals; +[[group(0), binding(1)]] var u_sampler: sampler; +[[group(0), binding(2)]] var u_texture: texture2d; + +struct VertexInput { + [[location(0)]] v_pos: vec2; + [[location(1)]] pos: vec2; + [[location(2)]] scale: vec2; + [[location(3)]] atlas_pos: vec2; + [[location(4)]] atlas_scale: vec2; + [[location(5)]] layer: u32; +}; + +struct VertexOutput { + [[builtin(position)]] position: vec4; + [[location(0)]] uv: vec3; +}; + +[[stage(vertex)]] +fn vs_main(input: VertexInput) -> VertexOutput { + var out: VertexOutput; + + out.uv = vec3(input.v_pos * input.atlas_scale + input.atlas_pos, input.layer); + + var transform: mat4x4 = mat4x4( + vec4(input.scale.x, 0.0, 0.0, 0.0), + vec4(0.0, scale.y, 0.0, 0.0), + vec4(0.0, 0.0, 1.0, 0.0), + vec4(input.pos, 0.0, 1.0) + ); + + out.position = globals.transform * transform * vec4(input.v_pos, 0.0, 1.0); + + return out; +} + +[[stage(fragment)]] +fn fs_main(input: VertexOutput) -> [[location(0)]] vec4 { + return textureSample(u_texture, u_sampler, input.uv); +} -- cgit From 0722d5e3ec307fd82a1cc76593d17d83cf828943 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Mon, 12 Apr 2021 23:07:58 -0700 Subject: add temporary fix for image wgsl --- wgpu/src/shader/image.wgsl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'wgpu/src/shader/image.wgsl') diff --git a/wgpu/src/shader/image.wgsl b/wgpu/src/shader/image.wgsl index c623247e..a63ee8f6 100644 --- a/wgpu/src/shader/image.wgsl +++ b/wgpu/src/shader/image.wgsl @@ -5,7 +5,7 @@ struct Globals { [[group(0), binding(0)]] var globals: Globals; [[group(0), binding(1)]] var u_sampler: sampler; -[[group(0), binding(2)]] var u_texture: texture2d; +[[group(1), binding(0)]] var u_texture: texture_2d_array; struct VertexInput { [[location(0)]] v_pos: vec2; @@ -13,23 +13,25 @@ struct VertexInput { [[location(2)]] scale: vec2; [[location(3)]] atlas_pos: vec2; [[location(4)]] atlas_scale: vec2; - [[location(5)]] layer: u32; + [[location(5)]] layer: i32; }; struct VertexOutput { [[builtin(position)]] position: vec4; - [[location(0)]] uv: vec3; + [[location(0)]] uv: vec2; + [[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 = vec3(input.v_pos * input.atlas_scale + input.atlas_pos, input.layer); + out.uv = vec2(input.v_pos * input.atlas_scale + input.atlas_pos); + out.layer = f32(input.layer); var transform: mat4x4 = mat4x4( vec4(input.scale.x, 0.0, 0.0, 0.0), - vec4(0.0, scale.y, 0.0, 0.0), + vec4(0.0, input.scale.y, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(input.pos, 0.0, 1.0) ); @@ -41,5 +43,5 @@ fn vs_main(input: VertexInput) -> VertexOutput { [[stage(fragment)]] fn fs_main(input: VertexOutput) -> [[location(0)]] vec4 { - return textureSample(u_texture, u_sampler, input.uv); + return textureSample(u_texture, u_sampler, input.uv, i32(input.layer)); } -- cgit