GPU Particles

    Setting up your GPU particles involves first creating a particle system.

    1. var particleGroup = new h3d.parts.GpuParticles.GpuPartGroup(particles);

    When you are ready to see your particle group on screen you just need to add it to the system.

    1. //The shape at which the particles will be emitted each ar of type GPUEmitMode
    2. particleGroup.emitMode = Cone;
    3. //The angle which the paricles will be emitted
    4. particleGroup.emitAngle = 0.5;
    5. //The distance from the initial spawn location of each particle
    6. particleGroup.emitDist = 0;
    7. //Fade in and fade out time for each particle
    8. particleGroup.fadeIn = 0.8;
    9. particleGroup.fadeOut = 0.8;
    10. particleGroup.fadePower = 10;
    11. //How much the particles are effective by gravity
    12. //The initial size of each particle
    13. particleGroup.size = 0.1;
    14. //Random size offset of each particle
    15. particleGroup.sizeRand = 0.5;
    16. //How fast the particles will rotate
    17. particleGroup.rotSpeed = 10;
    18. //The speed of each particle
    19. particleGroup.speed = 2;
    20. //Random variation in speed for each particle
    21. particleGroup.speedRand = 0.5;
    22. //Random variance in lifespan
    23. particleGroup.lifeRand = 0.5;
    24. //The number of particles in a group - these all get uploaded to the GPU
    25. particleGroup.nparts = 10000;
    26. //You can assign a texture to the particle group
    27. //Every particle will have the texture appllied.
    28. particleGroup.texture = hxd.Res.hxlogo.toTexture();
    29. //Use Texture.fromColor to set the color of each particle.
    30. particleGroup.texture = h3d.mat.Texture.fromColor(0xEA8220);

    10000 textured particles running on the GPU

    Looping

    If your particle groups are not set to looping you can listen for a completion event to know when the particle system is done emitting. Note that

    1. particles.onEnd = function(){
    2. //If none of the groups in this particle system are set to looping
    3. //this method will fire once the system is done emitting particles