From 5fb877ab5984dd1c4a3f3dcccf87103393da4e0c Mon Sep 17 00:00:00 2001 From: Jim Eckerlein Date: Sun, 24 Sep 2023 15:24:08 +0200 Subject: Compute vertex position for image shader --- wgpu/src/shader/image.wgsl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'wgpu/src/shader/image.wgsl') diff --git a/wgpu/src/shader/image.wgsl b/wgpu/src/shader/image.wgsl index 5e22cdf4..0c8b3bdb 100644 --- a/wgpu/src/shader/image.wgsl +++ b/wgpu/src/shader/image.wgsl @@ -7,7 +7,7 @@ struct Globals { @group(1) @binding(0) var u_texture: texture_2d_array; struct VertexInput { - @location(0) v_pos: vec2, + @builtin(vertex_index) vertex_index: u32, @location(1) pos: vec2, @location(2) scale: vec2, @location(3) atlas_pos: vec2, @@ -25,7 +25,9 @@ struct VertexOutput { fn vs_main(input: VertexInput) -> VertexOutput { var out: VertexOutput; - out.uv = vec2(input.v_pos * input.atlas_scale + input.atlas_pos); + let v_pos = vertex_position(input.vertex_index); + + out.uv = vec2(v_pos * input.atlas_scale + input.atlas_pos); out.layer = f32(input.layer); var transform: mat4x4 = mat4x4( @@ -35,7 +37,7 @@ fn vs_main(input: VertexInput) -> VertexOutput { vec4(input.pos, 0.0, 1.0) ); - out.position = globals.transform * transform * vec4(input.v_pos, 0.0, 1.0); + out.position = globals.transform * transform * vec4(v_pos, 0.0, 1.0); return out; } -- cgit From 41dec5bd203ff5b1574a33a17d5f7358ae1beea2 Mon Sep 17 00:00:00 2001 From: Jim Eckerlein Date: Sun, 24 Sep 2023 15:26:10 +0200 Subject: Reassign attribute locations for image shader --- wgpu/src/shader/image.wgsl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'wgpu/src/shader/image.wgsl') diff --git a/wgpu/src/shader/image.wgsl b/wgpu/src/shader/image.wgsl index 0c8b3bdb..7b2e5238 100644 --- a/wgpu/src/shader/image.wgsl +++ b/wgpu/src/shader/image.wgsl @@ -8,11 +8,11 @@ struct Globals { struct VertexInput { @builtin(vertex_index) vertex_index: u32, - @location(1) pos: vec2, - @location(2) scale: vec2, - @location(3) atlas_pos: vec2, - @location(4) atlas_scale: vec2, - @location(5) layer: i32, + @location(0) pos: vec2, + @location(1) scale: vec2, + @location(2) atlas_pos: vec2, + @location(3) atlas_scale: vec2, + @location(4) layer: i32, } struct VertexOutput { -- cgit