33 lines
652 B
WebGPU Shading Language
33 lines
652 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: f32) -> vec3f {
|
|
let brightness = 3. * (1. - 1. / (1. + light));
|
|
return vec3(brightness, brightness - 1., brightness - 2.);
|
|
}
|
|
|
|
@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.x), 1.0);
|
|
}
|