39 lines
875 B
WebGPU Shading Language
39 lines
875 B
WebGPU Shading Language
struct CameraUniform {
|
|
eye: vec4<f32>;
|
|
vp: mat4x4<f32>;
|
|
};
|
|
|
|
struct VertexInput {
|
|
[[location(0)]] position: vec3<f32>;
|
|
[[location(1)]] tan_frame: u32;
|
|
};
|
|
|
|
struct VertexOutput {
|
|
[[builtin(position)]] clip_position: vec4<f32>;
|
|
[[location(0)]] position: vec3<f32>;
|
|
};
|
|
|
|
[[group(0), binding(0)]]
|
|
var<uniform> camera: CameraUniform;
|
|
|
|
[[stage(vertex)]]
|
|
fn vs_main(
|
|
[[builtin(instance_index)]] mesh_idx: u32,
|
|
[[builtin(vertex_index)]] vertex_idx: u32,
|
|
vertex: VertexInput,
|
|
) -> VertexOutput {
|
|
let world_pos = vertex.position;
|
|
|
|
var out: VertexOutput;
|
|
out.clip_position = camera.vp * vec4<f32>(world_pos, 1.0);
|
|
out.position = world_pos;
|
|
return out;
|
|
}
|
|
|
|
[[stage(fragment)]]
|
|
fn fs_main(
|
|
frag: VertexOutput,
|
|
) -> [[location(0)]] vec4<f32> {
|
|
return vec4<f32>(sin(frag.position) * vec3<f32>(0.5) + vec3<f32>(0.5), 1.0);
|
|
}
|