From 3ebdfda1966ac989bcf90b42627f533cf5643a57 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Sun, 9 Nov 2025 22:30:27 -0600 Subject: [PATCH] particle_oriented_animated_quad_vbuf_pixel_shader: implement particle reset --- ...iented_animated_quad_vbuf_pixel_shader.cpp | 12 +++-- src/particle_physics.fs.asm | 48 +++++++++++++++--- src/particle_physics.fs.bin | Bin 216 -> 336 bytes 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/particle_oriented_animated_quad_vbuf_pixel_shader.cpp b/src/particle_oriented_animated_quad_vbuf_pixel_shader.cpp index 564fb79..5676423 100644 --- a/src/particle_oriented_animated_quad_vbuf_pixel_shader.cpp +++ b/src/particle_oriented_animated_quad_vbuf_pixel_shader.cpp @@ -1158,15 +1158,17 @@ int _floatbuffer(const shaders& shaders, // fragment constants //const vec3 velocity_scale = vec3(0.003f, 0.01f, 0.003f); - const vec3 velocity_scale = vec3(0.09f, 0.50f, 0.09f); - const float delta_age = 0.01f; + const vec3 velocity_scale = vec3(0.9f, 5.0f, 0.9f); + const float delta_age = -0.01f; const float velocity_attenuation = -0.6f; // multiplied by velocity.y after bounce const float gravity = -0.04f; + const float max_age = 3.0f; + const float reset_radius = 20.0f; const float fragment_consts[] = { // 0: velocity_scale.x, velocity_scale.y, velocity_scale.z, delta_age, // 1: - velocity_attenuation, gravity, 0, 0, + velocity_attenuation, gravity, max_age, reset_radius, }; int fragment_consts_length = (sizeof (fragment_consts)) / (sizeof (fragment_consts[0])); ib_ga_consts(fragment_consts, fragment_consts_length, 0); @@ -1307,8 +1309,8 @@ int main() int colorbuffer_ix = 0; float theta = PI * 0.5; - const int floatbuffer_width = 8; - const int floatbuffer_height = 8; + const int floatbuffer_width = 64; + const int floatbuffer_height = 64; floatbuffer_state state = create_floatbuffers(fd, floatbuffer_width * floatbuffer_height); vertexbuffer_handle = init_particles_vertexbuffer(fd, state.length, &vertexbuffer_ptr); diff --git a/src/particle_physics.fs.asm b/src/particle_physics.fs.asm index 6f4cd4c..c570f3f 100644 --- a/src/particle_physics.fs.asm +++ b/src/particle_physics.fs.asm @@ -20,7 +20,7 @@ -- const[0] = { velocity_scale.rgb, delta_age } -- gravity = -0.05 -- velocity_attenuation = -0.7 --- const[1] = { velocity_attenuation, gravity, 0, 0 } +-- const[1] = { velocity_attenuation, gravity, max_age, 0 } -- out[0].rgb : position -- out[0].a : age @@ -64,14 +64,48 @@ src2.rgb = temp[4] : -- position src0.rgb = temp[4] : temp[4].g = MAX |src0.0g0| |src0.0g0| ; +-- +-- reset +-- + +-- normalize(vec3(velocity.x, 0, velocity.z)) +src0.rgb = temp[1] : -- velocity + DP3 src0.r0b src0.r0b , + temp[2].a = DP ; +src0.a = temp[2] : + temp[2].a = RSQ |src0.a| ; +src0.a = temp[2] , +src0.rgb = temp[1] : -- velocity + temp[2].rgb = MAD src0.r0b src0.a0a src0.000 ; + +-- age = age + max_age +-- reset__position = reset__position * 20 +src0.a = temp[0] , -- age +src1.rgb = const[1] , -- max_age +src2.a = const[1] , -- reset_radius +src0.rgb = temp[2] : -- reset__position + temp[2].a = MAD src0.a src0.1 src1.b , + temp[2].rgb = MAD src0.rgb src2.aaa src2.000 ; + +-- reset__velocity +src0.a = temp[1] , -- delta +src1.a = float(64) , -- 2.0 +src0.rgb = temp[1] : -- velocity + temp[3].rgb = MAD src0.rab src1.1a1 src1.000 ; + OUT src0.a = temp[4] , -- update__age -src0.rgb = temp[4] : -- update__position - out[0].a = MAX src0.a src0.a , - out[0].rgb = MAX src0.rgb src0.rgb ; +src1.a = temp[2] , -- reset__age +src2.a = temp[0] , -- age +src0.rgb = temp[4] , -- update__position +src1.rgb = temp[2] : -- reset__position + out[0].a = CMP src0.a src1.a src2.a , + out[0].rgb = CMP src0.rgb src1.rgb src2.aaa ; OUT TEX_SEM_WAIT src0.a = temp[1] , -- delta -src0.rgb = temp[5] : -- update__velocity - out[1].a = MAX src0.a src0.a , - out[1].rgb = MAX src0.rgb src0.rgb ; +src2.a = temp[0] , -- age +src0.rgb = temp[5] , -- update__velocity +src1.rgb = temp[3] : -- reset__velocity + out[1].a = MAX src0.a src0.a , -- constant + out[1].rgb = CMP src0.rgb src1.rgb src2.aaa ; diff --git a/src/particle_physics.fs.bin b/src/particle_physics.fs.bin index a85c47e6ff8809b42cedab2956f6337f021fb420..279fc2b1f7cade91fddd1f75a9dc518e0bc544af 100644 GIT binary patch delta 176 zcmcb?c!6ocih2eI1_nk3CXNOWW(r_XWB~Dj04NR;V*+9jSNi}9h+<%{fT#zFH#8N3 zg%lV(85k-U7?@aCfNF&V6b|JwC>%JzprGI>1XIt*z|4`LbRMkUK){oMv4Ncds9KW) lq(wo=g@Nrr1_Q?fGZ|K(1S<~%2hdRbc1oi3IoOlb_Ny(CJqo*U~*w#K9In`%D}+D3KVAriZMdO6@cOjAaMW-Y6rRi