summaryrefslogtreecommitdiffstats
path: root/wgpu/src/shader/image.wgsl
diff options
context:
space:
mode:
Diffstat (limited to 'wgpu/src/shader/image.wgsl')
-rw-r--r--wgpu/src/shader/image.wgsl21
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;
}