diff options
author | 2024-05-02 15:21:22 +0200 | |
---|---|---|
committer | 2024-05-02 17:28:28 +0200 | |
commit | a57313b23ecb9843856ca0ea08635b6121fcb2cb (patch) | |
tree | 42a88a4e42031ae99ae87aeb92fea85ab590b01e /wgpu/src/shader/image.wgsl | |
parent | 09a6bcfffc24f5abdc8709403bab7ae1e01563f1 (diff) | |
download | iced-a57313b23ecb9843856ca0ea08635b6121fcb2cb.tar.gz iced-a57313b23ecb9843856ca0ea08635b6121fcb2cb.tar.bz2 iced-a57313b23ecb9843856ca0ea08635b6121fcb2cb.zip |
Simplify image rotation API and its internals
Diffstat (limited to '')
-rw-r--r-- | wgpu/src/shader/image.wgsl | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/wgpu/src/shader/image.wgsl b/wgpu/src/shader/image.wgsl index de962098..71bf939c 100644 --- a/wgpu/src/shader/image.wgsl +++ b/wgpu/src/shader/image.wgsl @@ -10,12 +10,11 @@ struct VertexInput { @builtin(vertex_index) vertex_index: u32, @location(0) pos: vec2<f32>, @location(1) center: vec2<f32>, - @location(2) image_size: vec2<f32>, + @location(2) scale: vec2<f32>, @location(3) rotation: f32, - @location(4) scale: vec2<f32>, - @location(5) atlas_pos: vec2<f32>, - @location(6) atlas_scale: vec2<f32>, - @location(7) layer: i32, + @location(4) atlas_pos: vec2<f32>, + @location(5) atlas_scale: vec2<f32>, + @location(6) layer: i32, } struct VertexOutput { @@ -36,7 +35,7 @@ fn vs_main(input: VertexInput) -> VertexOutput { out.layer = f32(input.layer); // Calculate the vertex position and move the center to the origin - v_pos = input.pos + v_pos * input.image_size - 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); @@ -48,16 +47,8 @@ fn vs_main(input: VertexInput) -> VertexOutput { vec4<f32>(0.0, 0.0, 0.0, 1.0) ); - // Scale the image and then translate to the final position by moving the center to the position - let scale_translate = 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.center, 0.0, 1.0) - ); - // Calculate the final position of the vertex - out.position = globals.transform * scale_translate * rotate * vec4<f32>(v_pos, 0.0, 1.0); + out.position = globals.transform * (vec4<f32>(input.center, 0.0, 0.0) + rotate * vec4<f32>(v_pos, 0.0, 1.0)); return out; } |