forestiles/src/shader.wgsl

45 lines
956 B
WebGPU Shading Language
Raw Normal View History

2024-08-22 17:21:34 +01:00
struct Uniforms {
2024-09-11 20:20:47 +01:00
camera: vec2f,
zooms: vec2f
2024-08-22 17:21:34 +01:00
}
@group(0) @binding(0) var<uniform> uniforms : Uniforms;
struct VertexOutput {
@location(0) color: vec4f,
@builtin(position) pos: vec4f
}
2024-08-18 18:21:17 +01:00
@vertex
2024-08-22 17:21:34 +01:00
fn vs_main(
2024-08-28 13:09:57 +01:00
@location(0) pos: vec2f,
2024-09-21 18:31:27 +01:00
@location(1) color: vec4f,
@location(2) effect: u32
2024-08-22 17:21:34 +01:00
) -> VertexOutput {
var out: VertexOutput;
2024-09-22 20:17:58 +01:00
switch effect {
case 1u, 3u: {
var v = (color.r*0.299) + (color.g*0.587) + (color.b*0.114);
out.color = vec4f(v, v, v, color.a);
}
case 0u, 2u: {
out.color = color;
}
default: {}
}
switch effect {
case 0u, 1u: {
out.pos = vec4f(pos, 0, 1);
}
case 2u, 3u: {
out.pos = vec4f((pos - uniforms.camera) * uniforms.zooms, 0, 1);
}
default: {}
}
2024-08-22 17:21:34 +01:00
return out;
2024-08-20 22:12:18 +01:00
}
@fragment
2024-08-22 17:21:34 +01:00
fn fs_main(v: VertexOutput) -> @location(0) vec4f {
return v.color;
2024-09-21 18:31:27 +01:00
}