59 lines
1.3 KiB
WebGPU Shading Language
59 lines
1.3 KiB
WebGPU Shading Language
struct Particle {
|
|
pos: vec3<f32>,
|
|
_pad0: f32, // matches _pad0 in C
|
|
vel: vec3<f32>,
|
|
_pad1: f32, // matches _pad1 in C
|
|
};
|
|
|
|
@group(0) @binding(0)
|
|
var<storage, read> particles: array<Particle>;
|
|
|
|
@group(0) @binding(1)
|
|
var<uniform> viewProjectionMatrix: mat4x4<f32>;
|
|
|
|
@group(0) @binding(2)
|
|
var<uniform> cameraRight: vec3<f32>;
|
|
|
|
@group(0) @binding(3)
|
|
var<uniform> cameraUp: vec3<f32>;
|
|
|
|
struct VertexOutput {
|
|
@builtin(position) Position: vec4<f32>,
|
|
@location(0) fragColor: vec4<f32>,
|
|
};
|
|
|
|
const quadVertexOffsets = array<vec2<f32>, 6>(
|
|
vec2<f32>(-1, -1),
|
|
vec2<f32>( 1, -1),
|
|
vec2<f32>(-1, 1),
|
|
vec2<f32>( 1, -1),
|
|
vec2<f32>( 1, 1),
|
|
vec2<f32>(-1, 1)
|
|
);
|
|
|
|
@vertex
|
|
fn vs_main(
|
|
@builtin(vertex_index) vertexIndex: u32,
|
|
@builtin(instance_index) instanceIndex: u32
|
|
) -> VertexOutput {
|
|
let particle = particles[instanceIndex];
|
|
|
|
|
|
let offset = quadVertexOffsets[vertexIndex];
|
|
|
|
let worldPosition = particle.pos * 150.0
|
|
+ offset.x * cameraRight
|
|
+ offset.y * cameraUp;
|
|
|
|
var output: VertexOutput;
|
|
output.Position = viewProjectionMatrix * vec4<f32>(worldPosition , 1.0);
|
|
output.fragColor = vec4<f32>(1.0, 1.0, 1.0, 1.0); // white color
|
|
|
|
return output;
|
|
}
|
|
|
|
@fragment
|
|
fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {
|
|
return input.fragColor;
|
|
}
|