diff options
author | 2024-08-04 14:52:29 +0200 | |
---|---|---|
committer | 2024-08-04 14:52:29 +0200 | |
commit | 145c3dc8fc4f92c400fbc3f8202ed22e1d498663 (patch) | |
tree | fe48b8e7f0021100aa2a0c697437527212af3475 /wgpu/src/shader | |
parent | 9cccaebb04944f2295cadff716d9708f4caa5642 (diff) | |
parent | cc076903dda18f79dbd82238f7a8216bab8c679d (diff) | |
download | iced-145c3dc8fc4f92c400fbc3f8202ed22e1d498663.tar.gz iced-145c3dc8fc4f92c400fbc3f8202ed22e1d498663.tar.bz2 iced-145c3dc8fc4f92c400fbc3f8202ed22e1d498663.zip |
Merge pull request #2537 from iced-rs/feature/canvas-image-support
`image` and `svg` support for `canvas`
Diffstat (limited to 'wgpu/src/shader')
-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; } |