blob: b8ce42b3eef3d6f46424b9583c1d43fec0bfd4e5 (
plain)
struct VertexInput {
@location(0) position: vec2<f32>
}
struct InstanceInput {
@location(1) position: vec2<f32>,
@location(2) size: vec2<f32>,
@location(3) rotation: f32,
@location(4) z_layer: i32
}
struct VertexOutput {
@builtin(position) clip_position: vec4<f32>
}
@vertex
fn vs_main(model: VertexInput, instance: InstanceInput) -> VertexOutput {
var out: VertexOutput;
// rotate the sprite
let a = vec2<f32>(cos(instance.rotation), sin(instance.rotation));
let b = vec2<f32>(-a[1], a[0]);
let rotation = mat2x2<f32>(a, b);
let rotated = rotation * model.position;
// scale the sprite
let x = rotated[0] * instance.size[0];
let y = rotated[1] * instance.size[1];
// move the sprite
let position = vec2<f32>(x, y) + instance.position;
out.clip_position = vec4<f32>(position, f32(instance.z_layer), 1.0);
return out;
}
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(1.0, 1.0, 1.0, 0.0);
}
|