diff options
author | 2024-08-04 03:28:43 +0200 | |
---|---|---|
committer | 2024-08-04 03:28:43 +0200 | |
commit | 0ceee1cf3ae49f5bd0e3f2b346a4b34076e4523a (patch) | |
tree | c44e036220ea40734a00bb8e05e4afa6a9504bea /wgpu/src/shader/image.wgsl | |
parent | 87a613edd186461f1a8d224394043527a372571c (diff) | |
download | iced-0ceee1cf3ae49f5bd0e3f2b346a4b34076e4523a.tar.gz iced-0ceee1cf3ae49f5bd0e3f2b346a4b34076e4523a.tar.bz2 iced-0ceee1cf3ae49f5bd0e3f2b346a4b34076e4523a.zip |
Implement image support for `canvas` widget
Diffstat (limited to '')
-rw-r--r-- | wgpu/src/shader/image.wgsl | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/wgpu/src/shader/image.wgsl b/wgpu/src/shader/image.wgsl index 0eeb100f..bc922838 100644 --- a/wgpu/src/shader/image.wgsl +++ b/wgpu/src/shader/image.wgsl @@ -1,5 +1,6 @@ struct Globals { transform: mat4x4<f32>, + scale_factor: f32, } @group(0) @binding(0) var<uniform> globals: Globals; @@ -16,6 +17,7 @@ struct VertexInput { @location(5) atlas_pos: vec2<f32>, @location(6) atlas_scale: vec2<f32>, @location(7) layer: i32, + @location(8) snap: u32, } struct VertexOutput { @@ -38,7 +40,7 @@ fn vs_main(input: VertexInput) -> VertexOutput { out.opacity = input.opacity; // Calculate the vertex position and move the center to the origin - v_pos = round(input.pos) + v_pos * input.scale - input.center; + v_pos = input.pos + v_pos * input.scale - input.center; // Apply the rotation around the center of the image let cos_rot = cos(input.rotation); @@ -51,7 +53,13 @@ fn vs_main(input: VertexInput) -> VertexOutput { ); // Calculate the final position of the vertex - out.position = globals.transform * (vec4<f32>(input.center, 0.0, 0.0) + rotate * vec4<f32>(v_pos, 0.0, 1.0)); + out.position = vec4(vec2(globals.scale_factor), 1.0, 1.0) * (vec4<f32>(input.center, 0.0, 0.0) + rotate * vec4<f32>(v_pos, 0.0, 1.0)); + + if bool(input.snap) { + out.position = round(out.position); + } + + out.position = globals.transform * out.position; return out; } |