From 5cd440b3a3b4a0625de72c1fdbfba2c92ae6b50e Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Sat, 19 Jul 2025 17:40:20 -0400 Subject: particles! --- Makefile | 2 +- shader/tri.frag | 12 +++++++++++- shader/tri.vert | 26 ++++++++++++++++++++++---- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index bf013d0..0689789 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ clean: rm -fv ${EXE} ${SPIRV} ${EXE}: *.c - ${CC} -Os -Wall -std=c23 $< -o $@ -lSDL3 -lm + ${CC} -Os -Wall -std=c23 $< -o $@ -lSDL3 -lm -fsanitize=undefined %.spv: % glslc -O -c "$<" -o "$@" diff --git a/shader/tri.frag b/shader/tri.frag index dea0868..f67a4e0 100644 --- a/shader/tri.frag +++ b/shader/tri.frag @@ -1,9 +1,19 @@ #version 450 layout(location = 0) in vec2 uv; +layout(location = 1) in vec4 in_color; +layout(location = 2) flat in int type; + layout(location = 0) out vec4 out_color; void main(void) { float n = 2 * length(uv - 0.5); - out_color = vec4(vec3(uv, 1) * (1.75 - n), float(n<1)); + switch (type) { + case 0: + out_color = vec4(in_color.rgb, in_color.a * float(n<1)); + break; + case 1: + out_color = vec4(in_color.rgb, in_color.a * (max(0.25 - n, 0) + max(1 - n, 0)) * 0.5); + break; + } } diff --git a/shader/tri.vert b/shader/tri.vert index 750b2a3..dc7389c 100644 --- a/shader/tri.vert +++ b/shader/tri.vert @@ -4,11 +4,29 @@ layout(set = 1, binding = 0) uniform UBO { mat4 camera; }; -layout(location = 0) in vec2 in_pos; -layout(location = 1) in vec2 in_uv; layout(location = 0) out vec2 out_uv; +layout(location = 1) out vec4 out_color; +layout(location = 2) flat out int out_type; + +struct Particle { + vec2 pos; + float radius, life; + vec3 color; + int type; +}; + +layout(binding = 0) buffer Particles { + Particle pts[]; +}; + +uint tri_idx[6] = { 0, 1, 2, 3, 2, 1 }; +vec2 tri_pos[4] = { {0,0}, {1,0}, {0,1}, {1,1} }; void main() { - gl_Position = camera * vec4(in_pos, 0.0, 1.0); - out_uv = in_uv; + Particle p = pts[gl_VertexIndex / 6]; + vec2 ofs = tri_pos[tri_idx[gl_VertexIndex % 6]]; + out_uv = ofs; + gl_Position = camera * vec4((ofs - 0.5) * p.radius * p.life + p.pos, 0.0, 1.0); + out_color = vec4(p.color,1); + out_type = p.type; } -- cgit 1.4.1-2-gfad0