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 {
|
2024-09-26 19:57:30 +01:00
|
|
|
@location(0) tex_pos: vec2f,
|
2024-09-25 18:13:50 +01:00
|
|
|
@location(1) color: vec4f,
|
2024-09-25 19:37:42 +01:00
|
|
|
@location(2) effect: u32,
|
2024-08-22 17:21:34 +01:00
|
|
|
@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-25 19:37:42 +01:00
|
|
|
@location(1) color: vec4f,
|
2024-09-26 19:57:30 +01:00
|
|
|
@location(2) tex_pos: vec2f,
|
2024-09-25 19:37:42 +01:00
|
|
|
@location(3) effect: u32
|
2024-08-22 17:21:34 +01:00
|
|
|
) -> VertexOutput {
|
2024-09-25 19:37:42 +01:00
|
|
|
var screen_pos: vec4f;
|
|
|
|
if (effect & 1) == 0 {
|
|
|
|
screen_pos = vec4f(pos, 0, 1);
|
|
|
|
} else {
|
|
|
|
screen_pos = vec4f((pos - uniforms.camera) * uniforms.zooms, 0, 1);
|
|
|
|
}
|
|
|
|
var out = VertexOutput(
|
2024-09-26 19:57:30 +01:00
|
|
|
tex_pos,
|
2024-09-25 19:37:42 +01:00
|
|
|
color,
|
|
|
|
effect,
|
|
|
|
screen_pos
|
|
|
|
);
|
2024-09-25 18:13:50 +01:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
@group(1) @binding(0)
|
|
|
|
var t_diffuse: texture_2d<f32>;
|
|
|
|
@group(1) @binding(1)
|
|
|
|
var s_diffuse: sampler;
|
|
|
|
|
|
|
|
@fragment
|
|
|
|
fn fs_main(in: VertexOutput) -> @location(0) vec4f {
|
2024-09-26 19:57:30 +01:00
|
|
|
var tex_col = textureSample(t_diffuse, s_diffuse, in.tex_pos);
|
2024-09-25 18:13:50 +01:00
|
|
|
var color = vec4f((tex_col.rgb * tex_col.a) + (in.color.rgb * in.color.a), tex_col.a + in.color.a);
|
2024-09-25 19:37:42 +01:00
|
|
|
// Grayscale
|
|
|
|
if (in.effect & 2) != 0 {
|
|
|
|
var v = (color.r*0.299) + (color.g*0.587) + (color.b*0.114);
|
|
|
|
color = vec4f(v, v, v, color.a);
|
2024-09-22 20:17:58 +01:00
|
|
|
}
|
2024-09-25 18:13:50 +01:00
|
|
|
return color;
|
2024-09-21 18:31:27 +01:00
|
|
|
}
|