73 lines
1.6 KiB
Plaintext
73 lines
1.6 KiB
Plaintext
struct InstanceInput {
|
|
@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>,
|
|
@location(6) texture_index: u32,
|
|
};
|
|
|
|
struct VertexInput {
|
|
@location(0) position: vec3<f32>,
|
|
@location(1) texture_coords: vec2<f32>,
|
|
}
|
|
|
|
struct VertexOutput {
|
|
@builtin(position) position: vec4<f32>,
|
|
@location(0) texture_coords: vec2<f32>,
|
|
@location(1) texture_index: u32,
|
|
}
|
|
|
|
|
|
@group(1) @binding(0)
|
|
var<uniform> global: GlobalUniform;
|
|
struct GlobalUniform {
|
|
camera_position: vec2<f32>,
|
|
camera_zoom: vec2<f32>,
|
|
camera_zoom_limits: vec2<f32>,
|
|
window_size: vec2<f32>,
|
|
window_aspect: vec2<f32>,
|
|
starfield_texture: vec2<u32>,
|
|
starfield_tile_size: vec2<f32>,
|
|
starfield_size_limits: vec2<f32>,
|
|
current_time: vec2<f32>,
|
|
};
|
|
|
|
|
|
@group(0) @binding(0)
|
|
var texture_array: binding_array<texture_2d<f32>>;
|
|
@group(0) @binding(1)
|
|
var sampler_array: binding_array<sampler>;
|
|
|
|
|
|
|
|
|
|
@vertex
|
|
fn vertex_main(
|
|
vertex: VertexInput,
|
|
instance: InstanceInput,
|
|
) -> VertexOutput {
|
|
|
|
let transform = mat4x4<f32>(
|
|
instance.transform_matrix_0,
|
|
instance.transform_matrix_1,
|
|
instance.transform_matrix_2,
|
|
instance.transform_matrix_3,
|
|
);
|
|
|
|
var out: VertexOutput;
|
|
out.position = transform * vec4<f32>(vertex.position, 1.0);
|
|
out.texture_coords = vertex.texture_coords;
|
|
out.texture_index = instance.texture_index;
|
|
return out;
|
|
}
|
|
|
|
|
|
@fragment
|
|
fn fragment_main(in: VertexOutput) -> @location(0) vec4<f32> {
|
|
return textureSampleLevel(
|
|
texture_array[in.texture_index],
|
|
sampler_array[0],
|
|
in.texture_coords,
|
|
0.0
|
|
).rgba;
|
|
} |