2022-04-23 03:42:33 +00:00
|
|
|
struct CameraUniform {
|
2022-09-17 15:34:52 +00:00
|
|
|
eye: vec4<f32>,
|
|
|
|
vp: mat4x4<f32>,
|
2022-04-23 03:42:33 +00:00
|
|
|
};
|
|
|
|
|
2022-04-19 07:48:05 +00:00
|
|
|
struct VertexInput {
|
2022-09-17 15:34:52 +00:00
|
|
|
@location(0) position: vec3<f32>,
|
|
|
|
@location(1) tan_frame: u32,
|
2022-04-19 07:48:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct VertexOutput {
|
2022-09-17 15:34:52 +00:00
|
|
|
@builtin(position) clip_position: vec4<f32>,
|
|
|
|
@location(0) position: vec3<f32>,
|
|
|
|
@location(1) color: vec3<f32>,
|
2022-04-19 07:48:05 +00:00
|
|
|
};
|
|
|
|
|
2022-09-17 15:34:52 +00:00
|
|
|
@group(0) @binding(0)
|
2022-04-23 03:42:33 +00:00
|
|
|
var<uniform> camera: CameraUniform;
|
|
|
|
|
2022-06-30 15:53:02 +00:00
|
|
|
fn random(seed: u32, salt: f32) -> f32 {
|
|
|
|
return abs(sin((f32(seed & u32(0x11111)) * 0.7071 + salt) * 78.233));
|
|
|
|
}
|
|
|
|
|
2022-09-17 15:34:52 +00:00
|
|
|
@vertex
|
2022-04-19 07:48:05 +00:00
|
|
|
fn vs_main(
|
2022-09-17 15:34:52 +00:00
|
|
|
@builtin(instance_index) mesh_idx: u32,
|
|
|
|
@builtin(vertex_index) vertex_idx: u32,
|
2022-04-19 07:48:05 +00:00
|
|
|
vertex: VertexInput,
|
|
|
|
) -> VertexOutput {
|
2022-04-23 03:42:33 +00:00
|
|
|
let world_pos = vertex.position;
|
|
|
|
|
2022-04-19 07:48:05 +00:00
|
|
|
var out: VertexOutput;
|
2022-04-23 03:42:33 +00:00
|
|
|
out.clip_position = camera.vp * vec4<f32>(world_pos, 1.0);
|
|
|
|
out.position = world_pos;
|
2022-06-30 15:53:02 +00:00
|
|
|
out.color.r = random(vertex_idx, f32(1.0) + world_pos.x);
|
|
|
|
out.color.g = random(vertex_idx, f32(2.0) + world_pos.y);
|
|
|
|
out.color.b = random(vertex_idx, f32(3.0) + world_pos.z);
|
2022-04-19 07:48:05 +00:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2022-09-17 15:34:52 +00:00
|
|
|
@fragment
|
2022-04-19 07:48:05 +00:00
|
|
|
fn fs_main(
|
|
|
|
frag: VertexOutput,
|
2022-09-17 15:34:52 +00:00
|
|
|
) -> @location(0) vec4<f32> {
|
2022-06-30 15:53:02 +00:00
|
|
|
return vec4<f32>(frag.color, 1.0);
|
2022-04-19 07:48:05 +00:00
|
|
|
}
|