Hi folks,
I’m working on a particle library that you can see in action at http://www.in-poculis.com/partykewl/partykewlEditor.jnlp
It uses 32 bytes per particles and memory is not fragmented because a large FloatBuffer is allocated at the initialization.
Here is how particles are managed:
/*
- Dead particles:
-
2 Bytes indicating the position of the next dead particle. 0xffff -> end of list.
- Alive particles:
- [][] 2 bytes indicating the position of the next alive particle. 0xffff -> end of list.
- [] 1 bit used to know if this particle is in world space or not
-
1 bit to know if this particle has already collide with something
-
1 bit unused
-
5 bit for the index of the emitter in the parent generator( to retrieve bases for life, velocity...)
- [] 1 byte for the last update frame. This is a 255 modulo and it just serves for debugging purposes.
- [][][][] 4 bytes for particle life. This value is updated on each rendering pass.
- [][][][] 4 bytes seed to regenerate parameters
- [][][][] 4 bytes for creation position X // Updated on collision
- [][][][] 4 bytes for creation position Y // Updated on collision
- [][][][] 4 bytes for creation position Z // Updated on collision
- [][][][] 4 bytes for compressed direction X, Y, Z // Updated on collision
- [][] 2 bytes for velocity coefficient // Updated on collision
- [][] 2 byte for delta life. We have to add this value to the particle life to know
-
the full elapsed time since the creation of the particle because collision affectors reset
-
the life of particles when they update the particule position and direction.
*/
Where are the UV, the color… ?
A seed is stored within each particle. When particles are renderered, we use a home made java random number generator to retrieve values in the range [-1, 1] for each parameter !
Yes, if you know that the first variable is the color, then using the random number generator with the same seed will always return the same value in the range [-1, 1] for your random color. You then use this value in the range [-1, 1] as the seed for a new call to the random number generator to get a new value ( used for the UV this time )…
The method:
public static float nextNormalizedRandom( float p_seed ) {
// Create a random integer with p_seed as a integer.
int l_value=214013*Float.floatToIntBits(p_seed)+2531011;
// Consider l_value as a float and
// keep only the mantissa (IEEE 754)
l_value&=0x007fffff;
// Make the number in the range [2.F, 4.F[ (IEEE 754)
l_value|=0x40000000;
// Consider the bits of l_value as representing a float
// then return an adjusted float in the range [-1.F, 1.F[
return Float.intBitsToFloat(l_value)-3.f;
}
You can do a interesting benchmark: call this method 100 millions times in a C++ for loop ( use a direct cast for Float.floatToIntBits ). VC++ 2005 is 10% slower than java on my computer in release !
More explanations ?
http://www.in-poculis.com/ParticlesPaper_LERAT_STEVENS_2007.doc
Why is the editor so beautiful ?
Because it uses the dev.java.net project: Substance !
Performances ?
10 000 particles per frame at 75hz on an Athlon 64@3.2GHz + GeForce 6600 + 512MB + 17"
By the way, you can add your own affectors and an abstract renderer is present to allow you to use it with another renderer.
My questions:
What do you think of the editor ?
I would like to publish the source as GPL, so is there a best place to publish such a library ?
Cheers,
Bernard.
Advice: The best Sokoban on this earth (Indyo) was registered only one time in 2007 ! Result: the graphist left the team. If you could lend yours to me… or register dozen of copies, maybe that he’ll be back. Thx, http://www.in-poculis.com