ParticleSeed emitter,seed
Parameters
|
emitter - CPU or GPU particle emitter entity seed - new value for the emitter's random number generator |
Description
|
Sets the random seed an emitter uses for every particle it spawns. GPU emission is repeatable for the same seed, accepted births and operation sequence on a supported configuration. GPU and CPU random streams are different; bit-identical trajectories across devices or drivers are not promised. Rejected births do not consume the GPU accepted-birth ordinal. Reseeding does not reset stable birth identities used for sorting. Every random choice a particle makes comes from the emitter's own generator: where in the emitter shape it appears, its velocity variation, its lifetime, its size variation, its starting angle and spin, and its animation frame offset. Reseeding restarts that sequence, so an emitter given the same seed, the same settings and the same sequence of calls produces exactly the same effect every time. That determinism is worth having for a few practical jobs. Replays and demo recordings look identical on playback. Screenshots for a store page or a bug report can be reproduced exactly. And when you are comparing two versions of an effect, reseeding both to the same value means any difference you see is your change and not the dice. Each emitter has its own generator, so two emitters given the same seed run in step - handy for a matched pair of engine exhausts - and giving them different seeds keeps otherwise identical effects from looking cloned. Gotcha: this is completely separate from Blitz's global random stream, so particles never disturb your gameplay randomness and SeedRnd has no effect on them. Reseeding does not clear or restart the particles that are already alive - pair it with ClearParticles if you want a clean repeat. Emitters start from a fixed built-in seed, and a CopyEntity copy starts from that same fixed seed rather than from the original's current position in the sequence. Requires Extended mode. See also: ClearParticles, CreateParticleEmitter, ParticleVelocity, SeedRnd. |
Example
; ParticleSeed Example ; -------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() SeedRnd MilliSecs() camera=CreateCamera() PositionEntity camera,0,2,-6 CameraClsColor camera,8,12,24 floor=CreatePlane() EntityColor floor,30,34,44 ; A firework emitter - bursts only, so each pattern is easy to compare emitter=CreateParticleEmitter(1000) PositionEntity emitter,0,2,0 ParticleEmissionRate emitter,0 ParticleLifetime emitter,2,3 ParticleVelocity emitter,0,0,0,2.5,2.5,2.5 ParticleGravity emitter,0,-1,0 ParticleDrag emitter,1 ParticleColor emitter,150,220,255,1,255,120,220,0 ParticleSize emitter,0.1,0.02,0.3 EntityBlend emitter,3 seed=12345 ParticleSeed emitter,seed EmitParticles emitter,300 While Not KeyDown(1) ; R replays the SAME seed - the burst pattern repeats exactly If KeyHit(19) ParticleSeed emitter,seed ClearParticles emitter EmitParticles emitter,300 EndIf ; Space picks a new random seed - a brand new pattern If KeyHit(57) seed=Rand(1,99999) ParticleSeed emitter,seed ClearParticles emitter EmitParticles emitter,300 EndIf ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 ; UpdateWorld also advances the particle simulation UpdateWorld RenderWorld Text 0,0,"Arrow keys: move camera R: replay same seed Space: new seed Esc: exit" Text 0,20,"ParticleSeed emitter,"+seed+" (same seed = identical firework)" Flip Wend End
Index