blob: 2358f43adad2ef4d4b950fea351316179714790f (
plain)
@group(0) @binding(0)
var<uniform> camera: mat4x4<f32>;
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: u32
}
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 scaled = rotated * instance.size;
// move the sprite
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;
return out;
}
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(1.0, 1.0, 1.0, 0.0);
}
|