2023-12-22 16:51:21 -08:00
|
|
|
struct InstanceInput {
|
2023-12-26 22:33:00 -08:00
|
|
|
@location(2) transform_matrix_0: vec4<f32>,
|
|
|
|
@location(3) transform_matrix_1: vec4<f32>,
|
|
|
|
@location(4) transform_matrix_2: vec4<f32>,
|
|
|
|
@location(5) transform_matrix_3: vec4<f32>,
|
2024-01-02 10:12:10 -08:00
|
|
|
@location(6) color_transform: vec4<f32>,
|
|
|
|
@location(7) texture_idx: u32,
|
2023-12-22 16:51:21 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct VertexInput {
|
|
|
|
@location(0) position: vec3<f32>,
|
2023-12-23 11:01:27 -08:00
|
|
|
@location(1) texture_coords: vec2<f32>,
|
2023-12-22 16:51:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct VertexOutput {
|
2023-12-23 23:24:04 -08:00
|
|
|
@builtin(position) position: vec4<f32>,
|
2023-12-23 11:01:27 -08:00
|
|
|
@location(0) texture_coords: vec2<f32>,
|
2023-12-22 16:51:21 -08:00
|
|
|
@location(1) index: u32,
|
2024-01-02 10:12:10 -08:00
|
|
|
@location(2) color_transform: vec4<f32>,
|
2023-12-22 16:51:21 -08:00
|
|
|
}
|
|
|
|
|
2023-12-23 23:24:04 -08:00
|
|
|
|
|
|
|
@group(1) @binding(0)
|
|
|
|
var<uniform> global: GlobalUniform;
|
|
|
|
struct GlobalUniform {
|
|
|
|
camera_position: vec2<f32>,
|
2023-12-24 11:08:44 -08:00
|
|
|
camera_zoom: vec2<f32>,
|
2023-12-25 15:56:27 -08:00
|
|
|
camera_zoom_limits: vec2<f32>,
|
2023-12-24 11:08:44 -08:00
|
|
|
window_size: vec2<f32>,
|
|
|
|
window_aspect: vec2<f32>,
|
|
|
|
starfield_texture: vec2<u32>,
|
|
|
|
starfield_tile_size: vec2<f32>,
|
2023-12-25 15:56:27 -08:00
|
|
|
starfield_size_limits: vec2<f32>,
|
2023-12-23 23:24:04 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-12-25 11:17:08 -08:00
|
|
|
@group(0) @binding(0)
|
|
|
|
var texture_array: binding_array<texture_2d<f32>>;
|
|
|
|
@group(0) @binding(1)
|
|
|
|
var sampler_array: binding_array<sampler>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-12-22 16:51:21 -08:00
|
|
|
@vertex
|
2023-12-25 11:17:08 -08:00
|
|
|
fn vertex_main(
|
2023-12-23 23:24:04 -08:00
|
|
|
vertex: VertexInput,
|
2023-12-22 16:51:21 -08:00
|
|
|
instance: InstanceInput,
|
|
|
|
) -> VertexOutput {
|
2023-12-23 23:24:04 -08:00
|
|
|
|
2023-12-26 22:33:00 -08:00
|
|
|
let transform = mat4x4<f32>(
|
|
|
|
instance.transform_matrix_0,
|
|
|
|
instance.transform_matrix_1,
|
|
|
|
instance.transform_matrix_2,
|
|
|
|
instance.transform_matrix_3,
|
2023-12-22 16:51:21 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
var out: VertexOutput;
|
2023-12-26 22:33:00 -08:00
|
|
|
out.position = transform * vec4<f32>(vertex.position, 1.0);
|
2023-12-23 23:24:04 -08:00
|
|
|
out.texture_coords = vertex.texture_coords;
|
2023-12-22 16:51:21 -08:00
|
|
|
out.index = instance.texture_idx;
|
2024-01-02 10:12:10 -08:00
|
|
|
out.color_transform = instance.color_transform;
|
2023-12-22 16:51:21 -08:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@fragment
|
2023-12-25 11:17:08 -08:00
|
|
|
fn fragment_main(in: VertexOutput) -> @location(0) vec4<f32> {
|
2023-12-22 16:51:21 -08:00
|
|
|
return textureSampleLevel(
|
|
|
|
texture_array[in.index],
|
2023-12-25 18:24:55 -08:00
|
|
|
sampler_array[0],
|
2023-12-23 11:01:27 -08:00
|
|
|
in.texture_coords,
|
2023-12-22 16:51:21 -08:00
|
|
|
0.0
|
2024-01-02 10:12:10 -08:00
|
|
|
).rgba * in.color_transform;
|
2023-12-22 16:51:21 -08:00
|
|
|
}
|