47 lines
965 B
WebGPU Shading Language
47 lines
965 B
WebGPU Shading Language
struct CameraUniform {
|
|
vp: mat4x4<f32>;
|
|
};
|
|
|
|
struct MeshInstance {
|
|
transform: mat4x4<f32>;
|
|
};
|
|
|
|
struct MeshData {
|
|
instances: array<MeshInstance>;
|
|
};
|
|
|
|
struct VertexInput {
|
|
[[location(0)]] position: vec3<f32>;
|
|
[[location(1)]] tex_coords: vec2<f32>;
|
|
};
|
|
|
|
struct VertexOutput {
|
|
[[builtin(position)]] clip_position: vec4<f32>;
|
|
[[location(0)]] color: vec3<f32>;
|
|
};
|
|
|
|
[[group(0), binding(0)]]
|
|
var<uniform> camera: CameraUniform;
|
|
|
|
[[group(1), binding(0)]]
|
|
var<storage,read> meshes: MeshData;
|
|
|
|
[[stage(vertex)]]
|
|
fn vs_main(
|
|
[[builtin(instance_index)]] mesh_idx: u32,
|
|
vertex: VertexInput,
|
|
) -> VertexOutput {
|
|
let transform = meshes.instances[mesh_idx].transform;
|
|
var out: VertexOutput;
|
|
out.clip_position = camera.vp * transform * vec4<f32>(vertex.position, 1.0);
|
|
out.color = vec3<f32>(vertex.tex_coords, 0.0);
|
|
return out;
|
|
}
|
|
|
|
[[stage(fragment)]]
|
|
fn fs_main(
|
|
frag: VertexOutput,
|
|
) -> [[location(0)]] vec4<f32> {
|
|
return vec4<f32>(frag.color, 1.0);
|
|
}
|