34 lines
646 B
WebGPU Shading Language
34 lines
646 B
WebGPU Shading Language
struct LookParams {
|
|
m: mat4x4f,
|
|
}
|
|
|
|
struct Vertex {
|
|
@location(0) pos: vec3f,
|
|
@location(1) color: vec3f,
|
|
}
|
|
|
|
struct Varying {
|
|
@builtin(position) screen: vec4f,
|
|
@location(0) color: vec4f,
|
|
}
|
|
|
|
@group(0) @binding(0) var<uniform> look: LookParams;
|
|
|
|
fn colormap(light: vec3f) -> vec3f {
|
|
let avg = dot(light, vec3f(1. / 3.));
|
|
let scale = 1. / (1. + avg);
|
|
return scale * light;
|
|
}
|
|
|
|
@vertex
|
|
fn on_vertex(in: Vertex) -> Varying {
|
|
let pos = look.m * vec4f(in.pos, 1.0);
|
|
let color = vec4f(in.color, 1.0);
|
|
return Varying(pos, color);
|
|
}
|
|
|
|
@fragment
|
|
fn on_fragment(in: Varying) -> @location(0) vec4f {
|
|
return vec4f(colormap(in.color.rgb), in.color.a);
|
|
}
|