From 399cd6aaf94e9298517be96245f0b13d424b0089 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Mon, 10 Nov 2025 18:27:46 -0600 Subject: [PATCH] particle: add colored particle fragment shader --- ...iented_animated_quad_vbuf_pixel_shader.cpp | 19 ++++---- ...article_particle_animated_quad_vbuf.vs.asm | 20 ++++---- ...article_particle_animated_quad_vbuf.vs.bin | Bin 176 -> 176 bytes src/particle_particle_colored.fs.asm | 43 ++++++++++++++++++ src/particle_particle_colored.fs.bin | Bin 0 -> 216 bytes src/particle_physics.fs.asm | 22 ++++++--- src/particle_physics.fs.bin | Bin 336 -> 360 bytes src/vertex_buffer_copy.vs.asm | 2 +- src/vertex_buffer_copy.vs.bin | Bin 32 -> 32 bytes 9 files changed, 81 insertions(+), 25 deletions(-) create mode 100644 src/particle_particle_colored.fs.asm create mode 100644 src/particle_particle_colored.fs.bin diff --git a/src/particle_oriented_animated_quad_vbuf_pixel_shader.cpp b/src/particle_oriented_animated_quad_vbuf_pixel_shader.cpp index f2d812f..cc3030e 100644 --- a/src/particle_oriented_animated_quad_vbuf_pixel_shader.cpp +++ b/src/particle_oriented_animated_quad_vbuf_pixel_shader.cpp @@ -49,7 +49,7 @@ const int vertex_shader_paths_length = (sizeof (vertex_shader_paths)) / (sizeof const char * fragment_shader_paths[] = { "clear.fs.bin", "particle_plane.fs.bin", - "particle_particle.fs.bin", + "particle_particle_colored.fs.bin", "texture_tile.fs.bin", "particle_physics.fs.bin", "vertex_buffer_copy.fs.bin", @@ -965,7 +965,7 @@ void init_particles2(void * position_ptr, float vx = xorshift32f(state) * 2.0f - 1.0f; float vz = xorshift32f(state) * 2.0f - 1.0f; - float new_age = max_age * sinf(fi * rl * 2) * 0.5f + 0.5f; + float new_age = max_age * sinf(fi * rl * 2.0f) * 0.5f + 0.5f; vec3 new_position = vec3(sx, sy, sz); vec3 new_velocity = normalize(vec3(vx * 0.5f, 0.0f, vz * 0.5f)); @@ -1304,6 +1304,7 @@ int main() // colorbuffer colorbuffer_handle[0] = create_buffer(fd, colorbuffer_size, &colorbuffer_ptr[0]); colorbuffer_handle[1] = create_buffer(fd, colorbuffer_size, &colorbuffer_ptr[1]); + zbuffer_handle = create_buffer(fd, colorbuffer_size, &zbuffer_ptr); //flush_handle = create_flush_buffer(fd); texturebuffer_handle = load_textures(fd, textures, textures_length); @@ -1315,7 +1316,7 @@ int main() int colorbuffer_ix = 0; float theta = PI * 0.5; - const int floatbuffer_width = 512; + const int floatbuffer_width = 256; const int floatbuffer_height = 256; floatbuffer_state state = create_floatbuffers(fd, floatbuffer_width * floatbuffer_height); @@ -1374,11 +1375,13 @@ int main() break; - struct timespec duration = { - .tv_sec = 0, - .tv_nsec = 18000000, - }; - nanosleep(&duration, NULL); + if (0) { + struct timespec duration = { + .tv_sec = 0, + .tv_nsec = 17000000, + }; + nanosleep(&duration, NULL); + } } primary_surface_address(rmmio, colorbuffer_ix); diff --git a/src/particle_particle_animated_quad_vbuf.vs.asm b/src/particle_particle_animated_quad_vbuf.vs.asm index 2c08251..26c6464 100644 --- a/src/particle_particle_animated_quad_vbuf.vs.asm +++ b/src/particle_particle_animated_quad_vbuf.vs.asm @@ -21,18 +21,18 @@ temp[2].xy = VE_MAD input[1].yx__ const[7].xx__ input[1].11__ ; temp[0].xyz = VE_ADD input[0].xyz_ input[0].000_ ; -- ppos = position.xxx * dx + ppos -temp[0].xyz = VE_MAD temp[2].xxx_ const[4].xyz_ temp[0].xyz_ ; +temp[0].xyz = VE_MAD temp[2].xxx_ const[4].xyz_ temp[0].xyz_ ; -- ppos = position.yyy * dy + ppos -temp[0].xyz = VE_MAD temp[2].yyy_ const[5].xyz_ temp[0].xyz_ ; +temp[0].xyz = VE_MAD temp[2].yyy_ const[5].xyz_ temp[0].xyz_ ; --- ppos *= scale -temp[0].xyzw = VE_MUL temp[0].xyz1 const[6].www1 ; +-- ppos = vec4(ppos.xyz * scale.xyz, age) +temp[0].xyzw = VE_MAD temp[0].xyz0 const[6].www0 input[0].000w ; -- ppos = transform_matrix * ppos -temp[1].x = VE_DOT const[0].xyzw temp[0].xyzw ; -temp[1].y = VE_DOT const[1].xyzw temp[0].xyzw ; -temp[1].z = VE_DOT const[2].xyzw temp[0].xyzw ; -temp[1].w = VE_DOT const[3].xyzw temp[0].xyzw ; +temp[1].x = VE_DOT const[0].xyzw temp[0].xyz1 ; +temp[1].y = VE_DOT const[1].xyzw temp[0].xyz1 ; +temp[1].z = VE_DOT const[2].xyzw temp[0].xyz1 ; +temp[1].w = VE_DOT const[3].xyzw temp[0].xyz1 ; -out[0].xyzw = VE_MAD temp[1].xyzw temp[1].1111 temp[1].0000 ; -out[1].xyzw = VE_MAX input[1].xy00 input[1].xy00 ; +out[0].xyzw = VE_ADD temp[1].xyzw temp[1].0000 ; +out[1].xyzw = VE_ADD input[1].xy00 temp[0].00zw ; -- age diff --git a/src/particle_particle_animated_quad_vbuf.vs.bin b/src/particle_particle_animated_quad_vbuf.vs.bin index 450568fbb0be8258addc01b9f68623ff8aee7df7..efef34efd7670c48a9b1b244d4f315d6f3b6de98 100644 GIT binary patch delta 119 zcmdnMxPftkLjeoJ2L=WPLB>M~(u|A^PZ$^#1Q?hYE&{~@85th@XJk}RU{FHgJ1{t* n@EaJCkoe3@9~cyXe1!%TMg^dLW~C1diVTX33=LNpK;{7en~5FE delta 119 zcmdnMxPftkLje=R2L=X)K*mD}(Ts;4{AXlT5MW?pxCj&jVlZEUK?#NLz~F?!Z(vA5 g;R diff --git a/src/particle_particle_colored.fs.asm b/src/particle_particle_colored.fs.asm new file mode 100644 index 0000000..92323ae --- /dev/null +++ b/src/particle_particle_colored.fs.asm @@ -0,0 +1,43 @@ +-- temp[0].xy: texture coordinate +-- temp[0].a : age + +TEX TEX_SEM_WAIT TEX_SEM_ACQUIRE + temp[2].rgb = LD tex[0].rgba temp[0].rgaa ; + +-- i = vec3(0.25, 0.40625, 0.5625); +src0.a = float(40) , -- 0.25 +src1.a = float(45) , -- 0.40625 +src2.rgb = float(49) : -- 0.5625 + temp[1].rgb = MAD src0.a10 src1.1a0 src2.00r ; + +-- t = i + vec3(td) +src0.a = temp[0] , +src0.rgb = temp[1] , +src1.rgb = temp[0] : + temp[1].rgb = MAD src1.bbb src0.aaa src0.rgb ; + +-- j = fract(t) +src0.rgb = temp[1] : + temp[1].rgb = FRC src0.rgb ; + +-- k = cos(j * 2π) +src0.rgb = temp[1] : + COS src0.r , + temp[1].r = SOP ; +src0.rgb = temp[1] : + COS src0.g , + temp[1].g = SOP ; +src0.rgb = temp[1] : + COS src0.b , + temp[1].b = SOP ; + +-- l = k * vec3(0.5, 0.5, 0.5) + vec3(0.5, 0.5, 0.5) +src0.rgb = temp[1] , +src1.rgb = float(48) : -- 0.5 + temp[1].rgb = MAD src0.rgb src1.rrr src1.rrr ; + +OUT TEX_SEM_WAIT +src0.rgb = temp[2] , +src1.rgb = temp[1] : + out[0].a = MAX src0.1 src0.1 , + out[0].rgb = MAD src0.rgb src1.rgb src0.000 ; diff --git a/src/particle_particle_colored.fs.bin b/src/particle_particle_colored.fs.bin new file mode 100644 index 0000000000000000000000000000000000000000..3eb152423edb372677f2a1f98fe9f1ca87a1e121 GIT binary patch literal 216 zcmZR#U;qLKCWbFePe3d<0E#y-2yw62!o+b#r5`LTpuow%02F6rVBlb2VB+v>%7utC zC_%-UI2wTB3QQ1FBtaBVB_mJ_Bo5;80UDC5Zh0KjGuUH||9 literal 0 HcmV?d00001 diff --git a/src/particle_physics.fs.asm b/src/particle_physics.fs.asm index c570f3f..660098f 100644 --- a/src/particle_physics.fs.asm +++ b/src/particle_physics.fs.asm @@ -75,8 +75,9 @@ src0.rgb = temp[1] : -- velocity 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 ; +src0.rgb = temp[1] , -- velocity +src1.a = temp[1] : -- delta + temp[2].rgb = MAD src0.r0b src0.a0a src1.0a0 ; -- age = age + max_age -- reset__position = reset__position * 20 @@ -88,10 +89,19 @@ src0.rgb = temp[2] : -- reset__position 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 ; +-- (p.velocity.x * 0.5 + 0.5) +-- velocity.xz = velocity.xz +src0.rgb = temp[1] , -- velocity.x +src1.a = float(48) : -- 0.5 + temp[3].a = MAD src0.r src1.a src1.a , + temp[3].rgb = MAX src0.r0b src0.r0b ; + +-- reset__velocity +-- velocity.y = (temp[3].a * delta + 2.0) +src0.a = temp[1] , -- delta +src1.a = float(56) , -- 1.0 +src2.a = temp[3] : -- + temp[3].g = MAD src2.0a0 src0.0a0 src1.0a0 ; OUT src0.a = temp[4] , -- update__age diff --git a/src/particle_physics.fs.bin b/src/particle_physics.fs.bin index 279fc2b1f7cade91fddd1f75a9dc518e0bc544af..f2565a95e79c428a1627c888846000a14e754dfc 100644 GIT binary patch delta 75 zcmcb>^nz)^Lp~M;j)tZ}1`tpXaG&^IO0R-}fsuiUqu~G$GX*dhFk~>8GB8Ln2rw`- X0L2*}7%>#F^nrC42)Iv{XEX!=gU}9~ delta 51 zcmaFCbb)EYLp}y3j)tZ}1`tqS@SONwO3Z?Rfe|Rm$iU2zpmZKAV<6x;*__c305#YN A_W%F@ diff --git a/src/vertex_buffer_copy.vs.asm b/src/vertex_buffer_copy.vs.asm index eadd23e..75b82cf 100644 --- a/src/vertex_buffer_copy.vs.asm +++ b/src/vertex_buffer_copy.vs.asm @@ -1,2 +1,2 @@ out[0].xyzw = VE_ADD input[0].xyzw input[0].0000 ; -out[1].xyzw = VE_ADD input[0].xy00 const[0].xy00 ; +out[1].xyzw = VE_ADD input[0].xy00 input[0].0000 ; diff --git a/src/vertex_buffer_copy.vs.bin b/src/vertex_buffer_copy.vs.bin index b140eb3b6add8ff516998a914d40a24906ae9739..fc9a4c5910dcf69d51286de967c842afd07d0fa7 100644 GIT binary patch delta 13 UcmY#Tm>|Ky*r3A5_~1Vy027@9cmMzZ delta 13 UcmY#Tm>|Ky#GuH?^x!`u01y`f_W%F@