diff options
| author | Micha White <botahamec@outlook.com> | 2022-09-24 18:20:46 -0400 |
|---|---|---|
| committer | Micha White <botahamec@outlook.com> | 2022-09-24 18:20:46 -0400 |
| commit | c29555bddac1c0027bf6e15d91e219adaa088065 (patch) | |
| tree | 59e671e4ded20b58027987053e207e4fe6a51307 /shaders | |
| parent | 7f364d2642784fcffea730b1f168270ce907a27c (diff) | |
Implemented a camera
Diffstat (limited to 'shaders')
| -rw-r--r-- | shaders/sprite.wgsl | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/shaders/sprite.wgsl b/shaders/sprite.wgsl index b8ce42b..2358f43 100644 --- a/shaders/sprite.wgsl +++ b/shaders/sprite.wgsl @@ -1,4 +1,7 @@ +@group(0) @binding(0) +var<uniform> camera: mat4x4<f32>; + struct VertexInput { @location(0) position: vec2<f32> } @@ -7,7 +10,7 @@ struct InstanceInput { @location(1) position: vec2<f32>, @location(2) size: vec2<f32>, @location(3) rotation: f32, - @location(4) z_layer: i32 + @location(4) z_layer: u32 } struct VertexOutput { @@ -25,13 +28,16 @@ fn vs_main(model: VertexInput, instance: InstanceInput) -> VertexOutput { let rotated = rotation * model.position; // scale the sprite - let x = rotated[0] * instance.size[0]; - let y = rotated[1] * instance.size[1]; + let scaled = rotated * instance.size; // move the sprite - let position = vec2<f32>(x, y) + instance.position; + let position2d = scaled + instance.position; + + // camera stuff + let position4d = vec4<f32>(position2d, f32(instance.z_layer), 1.0); + out.clip_position = camera * position4d; + //out.clip_position = position4d; - out.clip_position = vec4<f32>(position, f32(instance.z_layer), 1.0); return out; } |
