particle: add colored particle fragment shader

This commit is contained in:
Zack Buhman 2025-11-10 18:27:46 -06:00
parent 872f0c31a8
commit 399cd6aaf9
9 changed files with 81 additions and 25 deletions

View File

@ -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);

View File

@ -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

View File

@ -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 ;

Binary file not shown.

View File

@ -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

Binary file not shown.

View File

@ -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 ;

Binary file not shown.