Galactica/src/render/shaders/starfield.wgsl

37 lines
945 B
WebGPU Shading Language
Raw Normal View History

2023-12-23 12:52:36 -08:00
// Vertex shader
2023-12-23 11:01:27 -08:00
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>,
};
struct VertexOutput {
@builtin(position) clip_position: vec4<f32>,
}
@vertex
fn vertex_shader_main(
instance: InstanceInput,
) -> VertexOutput {
let transform_matrix = mat4x4<f32>(
instance.transform_matrix_0,
instance.transform_matrix_1,
instance.transform_matrix_2,
instance.transform_matrix_3,
);
2023-12-23 12:52:36 -08:00
// Stars consist of only one vertex, so we don't need to pass a buffer into this shader.
// We need one instance per star, and that's it!
let pos = vec4<f32>(0.0, 0.0, 0.0, 1.0);
2023-12-23 11:01:27 -08:00
var out: VertexOutput;
2023-12-23 12:52:36 -08:00
out.clip_position = transform_matrix * pos;
2023-12-23 11:01:27 -08:00
return out;
}
2023-12-23 12:52:36 -08:00
// Fragment shader
2023-12-23 11:01:27 -08:00
@fragment
fn fragment_shader_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(1.0, 1.0, 1.0, 1.0);
}