Forum

How to roll particles using texture alpha values?

lets say i have a gpu particle system where a data texture provides the xyz position data for all particles. now i want to use the remaining a channel of the texture to perform a roll on single particles.
does someone know how this can be done?
i assume i need to do a matrix multiplication in the shader somehow. but dont know exactely how.

thanks

Typically I would do this with two render passes. I think this is how dottore’s gpu particle library does it.

Put a bunch of random positions/rolls into a dynamic texture.

->

Renderer1 (position update)
PS: Update xyz and roll based on some system (verlet, perlin, fluid, etc)

->

Create a dynamic mesh to hold indexed vertices for particles (see dottore library for an example of this patch.

Feed this and rendered output texture from into:

->

Renderer2 (drawing render)
VS: Transform vertices for each particle based on xyz and roll from the texture output by Renderer1 (by creating a rotation matrix from roll value and applying it to verts).
PS: Draw particle texture for your particles (and do any lighting necessary).

You will also want to feed the texture output from Renderer1 back into Renderer1 with some sort of queue. If you look at dottore’s examples and documentation (which are awesome!) this will all make more sense.
particlesgpu-shader-library

Hello tekcor,

When I studied dottore’s particlesgpu-shader-library, I tried to create a 3D version of his ParticlesGPU_2d_Dynamic behaviour.

Since he did most of it in one patch, I created some subpatches to order it in a more logical way (at least to me, I needed that in order to understand exactly what he was doing).

Anyway in the attached example, if you open ‘ParticlesGPU_3d_Dynamic help.v4p’, you will find that it contains 1 subpatch called ‘ParticlesGPU_3d_Dynamic’, which contains one shader ‘ParticlesGPU_3d_PositionVelocityCycle.fx’ (that I don’t think works totally as it should at this time), and another subpatch called ‘ParticlesGPU_DrawParticles.v4p’ (this is the one that could be of interest to you).

The shader is for calculating the particles’ positions and writing them into a texture. I hardcoded some code to rotate the particles in there.

‘ParticlesGPU_DrawParticles.v4p’ contains some code for creating a mesh and contains a shader that will draw the given texture at the positions and rotations given by the ‘data’ texture. The way I do the rotation is by calculating a new sample position based on rotation. This will make some pixels ‘fall off’ as you rotate, so it is best to take a square texture with some tranparency around, such that the whole particle will still be visible when rotated (the one I added is ok, use the ‘world map’ from girlpower as the texture if you want to see what I mean by pixels falling off).
I am using point sprites (only using 1 vertex per particle), whereas dottore’s original version needed 4 vertices per particles.

I hope this helps… The above post suggests that you should be able to apply a rotation matrix to the vertices, which would make the texture rotate? I don’t really know, so if anyone can show me how to edit the ParticlesGPU_3d_Dynamic_Constant.fx shader in order to have the sprites rotated by the vertex shader, that would be very cool.

ft’s ParticlesGPU_3d_Dynamic 02.zip (596.1 kB)

thank you both very much!

it actually works now. i took the yaw/pitch/roll function from the 3D_static_allocator patch from dottores lib.
its more then i need and i needed to build a extra datatexture instead of using the alpha channel from the first data texture. but the function is quite complex and i cant extract the roll easily.

actually i dont use any cycles in the patch. its more a particle system for building large geometry. im experimenting with segmented particles where one particle consist out of many slices which can be addressed seperately.

ft i saw that you do the rotation in pixel shader! also very interesting. i try to build a vertex rotation from this function the next days

heres the patch if you want to have a look and eventually have an idea how to write a roll only function.

tekcor static segment particles.rar (13.8 kB)

@tekcor: constant_2.0_filterpoint.fx seems to be missing…

@tekcor
a .fx file is missing in your .rar

haha im so slow

hehe allrigth this should work now.

static segment particles.rar (15.1 kB)

here is a update. fixed some problems and added polygons on both particle ends.
for now i decided to leave the rotate function as it is. the patch is more
flexible for different purpose as well.

it would be nice if you could test how far you can go with the particle count and yz slice count. because my vvvv sometime crashes when going over 10000 particles with 5 slices. my machine is not the newest and only has 2 gb ram which seems to get flooded when generating the mesh.
so i wonder if upgrading the ram could help me getting more particles out of my computer.

SlicedParticles 01.rar (12.9 kB)