2025-05-04 11:27:55 +02:00
|
|
|
struct VertexInput {
|
|
|
|
|
@location(0) position: vec3<f32>,
|
|
|
|
|
@location(1) color: vec3<f32>,
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-04 12:03:18 +02:00
|
|
|
struct InstanceInput {
|
|
|
|
|
@location(5) model_row0: vec4<f32>,
|
|
|
|
|
@location(6) model_row1: vec4<f32>,
|
|
|
|
|
@location(7) model_row2: vec4<f32>,
|
|
|
|
|
@location(8) model_row3: vec4<f32>,
|
2025-05-04 12:51:41 +02:00
|
|
|
@location(9) color: vec3<f32>,
|
2025-05-04 12:03:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct VSOutput {
|
|
|
|
|
@builtin(position) position: vec4<f32>,
|
2025-05-04 11:27:55 +02:00
|
|
|
@location(0) color: vec3<f32>,
|
2025-05-04 01:04:46 +02:00
|
|
|
};
|
|
|
|
|
|
2025-05-04 13:48:21 +02:00
|
|
|
struct Globals {
|
|
|
|
|
aspect_ratio: f32,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@group(0) @binding(0)
|
|
|
|
|
var<uniform> globals: Globals;
|
|
|
|
|
|
2025-05-04 01:04:46 +02:00
|
|
|
@vertex
|
2025-05-04 12:03:18 +02:00
|
|
|
fn vs_main(vertex: VertexInput, instance: InstanceInput) -> VSOutput {
|
|
|
|
|
var out: VSOutput;
|
|
|
|
|
let model = mat4x4<f32>(
|
|
|
|
|
instance.model_row0,
|
|
|
|
|
instance.model_row1,
|
|
|
|
|
instance.model_row2,
|
|
|
|
|
instance.model_row3
|
|
|
|
|
);
|
2025-05-04 13:48:21 +02:00
|
|
|
|
|
|
|
|
let projection = mat4x4<f32>(
|
|
|
|
|
vec4<f32>(1.0 / globals.aspect_ratio, 0.0, 0.0, 0.0),
|
|
|
|
|
vec4<f32>(0.0, 1.0, 0.0, 0.0),
|
|
|
|
|
vec4<f32>(0.0, 0.0, 1.0, 0.0),
|
|
|
|
|
vec4<f32>(0.0, 0.0, 0.0, 1.0),
|
|
|
|
|
);
|
|
|
|
|
out.position = projection * model * vec4<f32>(vertex.position, 1.0);
|
2025-05-04 12:51:41 +02:00
|
|
|
out.color = instance.color;
|
2025-05-04 01:37:26 +02:00
|
|
|
return out;
|
2025-05-04 01:04:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@fragment
|
2025-05-04 12:03:18 +02:00
|
|
|
fn fs_main(input: VSOutput) -> @location(0) vec4<f32> {
|
|
|
|
|
return vec4<f32>(input.color, 1.0);
|
2025-05-04 12:51:41 +02:00
|
|
|
}
|