Simple particle system.

Blitz3D Forums/Blitz3D Programming/Simple particle system.

JBR(Posted 2004) [#1]
Hello, a few questions.

I intend to use fixed sized arrays to hold different variables for a particular particle. e.g. P_X#(), P_Y#(), etc. Is this a good idea or should I use Banks?
I would just set up enough array space for a maximum of 1024 particles say.

I intend to set up a surface with 1024 quads; one for each particle. If the particle is not 'on' then I set the quad to big Z coord so it is not displayed. i.e. The graphics card will always try to plot 1024 particles. Is this a fair way to do this?

I'm sure i've tested arrays vs banks vs types in the past and found arrays to be the fastest but i'm not 100% sure.

Any advice
Marg


Trixx(Posted 2004) [#2]
Arrays are fastest in most situations - that's true. If you know that you'll never have more than 1024 particles, then it's ok to use arrays. But, setting up a surface with constant 1024 quads is wrong way to go !
Why don't you simply start from 0 and add quads to surface when you need more particles ?


JBR(Posted 2004) [#3]
Do you mean, set up a surface at the start and then do a ClearSurface and then rebuild the surface using 4*AddVertex and 2*AddTriangle and 1*VertexColor for each live particle? (assuming the quad is one color).

Seems more work than 4*VertexCoords and 1*VertexColor and put the strain on the graphics card.

Is it possible to do a ClearSurface and only delete the Vertices and leave the Triangles there? This would save the AddTriangles bit.

Marg


Trixx(Posted 2004) [#4]
1. No, I mean that you should build the surface with AddVertex+AddTriangle, but then use VertexCoords as you say to move particles.
2. Yes, it's possible to clear only vertices with ClearSurface and using AddTriangle only when quads are created, but that will still be slower than using VertexCoords and that will cause additional problems and limitations in handling of particles in your system.


Ross C(Posted 2004) [#5]
If your going to use a fixed size array, then do it like so...

global p_x=0
global p_y=1
global p_z=2
global p_index=3
global number_of_particles=256

dim particles(number_of_particles,3)

and access each part of the array like so...

particles(1,p_z)=5

so basically you have a 2d array, instead of 3 or 4 different arrays.

You need to vertexs to actually move the triangles, so you can't get rid of them. When you want to move the 'quad', you need to move each of the 4 vertexs in the same direction.

In regards to moving the particle away in the Z axis, why not just hide it, using vertexcolor r,g,b,alpha. Set all 4 co-ords to 0 alpha, when not in use.

It's also fair enough to create all the quads at once, if you want.


JBR(Posted 2004) [#6]
Thanks guys.

Trixx, I think you are talking about a more dynamic system but to be honest I think I'll find it easier to set a limit and create all at once.

Ross C, I never thought of a 2d array; much nicer.
Given x,y,z will be floats, should I use Dim particles#() ?
I'm assuming that I cannot mix ints & floats ?

Thanks
Marg


JBR(Posted 2004) [#7]
I did a test of VertexCoords vs VertexColor and found VertexColor to be 4 times slower than VertexCoords.

Anyone else noticed this?
Anyone know why?

Marg


Ross C(Posted 2004) [#8]
Hmmm, didn't notice that, no :)

Btw, it's cool to mix int's and floats in an array, as long as the array doesn't hold pointers to meshes, sounds or other media, as a float number, doesn't accuratly keep the same number, and can cause errors :)

As to the slow down, maybe your gfx card doesn't like drawing lots of alphaed particles ?


JBR(Posted 2004) [#9]
To mix int's & floats, do I set it up the array as an array of floats?

I wasn't talking about the graphics card slowdown but just using VertexCoords & VertexColor and timing for a for next loop. I'm using a Radeon 9800Pro and not much slows it down :-}

Marg