I'm writing particle system and should port previous functionality to it. The basic idea is to split particle system into parts such as particle (that stores current state of one particle), particle affector (has some influence to particles during simulation: add velocity etc.) and few other essences. I want to be able to add new affectors without adding new parameters to particle struct. Also, I'm trying to keep particle struct smaller, such as:
struct Particle
{
Vec3 position;
Vec3 velocity;
Color color;
Vec2 size;
};
The affector probably will look like:
class ParticleAffector
{
public:
virtual void affectParticles(ParticleContainer& particles) = 0;
};
Old particle system (which functionality I should keep in new one) had some effects that require particle to have some additional params like wiggler effect time offset (generated randomly from range for each particle on particle creation to keep randomness in particles movement). I'm looking for ability to port these effects without adding custom parameters to particles. One idea was to have parameter such as randomSeed
in each particle and to map this seed to required range on the fly for each particle in affector code. But implementing this idea as is can make visibly recognizable dependencies between different particle properties (orientation and speed, for example). The the extension of idea is to have random number generator that takes two numbers as seed (one from particle and one from affector, so there will be different restorable number sequences for different properties) and and gives i'th element of sequence by requested index in constant time, so it will be possible in affector to write something like m_randomNumberGenerator.makeRandomValue(particleSys->getOrientationSeed(), particle.randomSeed, 0)
to get first number of sequence and it will be exactly the same number that was used to generate particle's initial orientation. But this value restore should be fast enough to run for each particle on PC and mobile devices. Is there any suggestions for implementing this? I was already reading this question but wondering if it fast enough and how to make two random seeds. Probably, there is some better solutions for not adding custom parameters to particles?
Aucun commentaire:
Enregistrer un commentaire