Rendering Particles

The Untold Engine provides a Particle System which allows you to develop 3D particles as shown below:

image

The Untold Engine represents a Particle System as a U4DEngine::U4DParticleSystem object. And it requires two sets of data to create Particles:

  • Particle Attributes
  • Particle Behavior

Particle Attributes

The Particle System creates 3D particles. Therefore, it requires vertices and UV texture data to be able to render a particle. Usually, you would create the shape and provide a texture to the particle using Blender and then export the attributes using the Digital Asset Exporter.

However, by default, the Untold Engine provides a default Particle model, which is shown below:

The default particle is a simple Ico-Sphere with a name of particle:

image

And a texture called particle.png:

image

The properties of the particles were exported using the DAE and are found in the particlesystemattributes.u4d file (Resource Folder).

Particle Behavior

The second set of data the Particle System requires is the particle’s behavior, such as the particle’s speed, the angle of emission, position, system emitter, etc. The particle’s behavior is stored in a U4DEngine::PARTICLESYSTEMDATA structure.

For example, the snippet below shows the behavior of a particle:

// Particle System structure
U4DEngine::PARTICLESYSTEMDATA particleData;
    
particleData.particleStartColor=U4DVector3n(0.0,0.0,1.0); //Provide the start color of the particle
particleData.particleStartColorVariance=U4DVector3n(0.1,0.1,0.1); //color variance of the particle as it goes from the Start Color to the End Color
particleData.particleEndColor=U4DVector3n(1.0,0.0,0.0); //Provide the end color of the particle
particleData.particleSpeed=0.5; //Particle's desired speed
particleData.particleLife=3.0; //Particle's life span
particleData.emitContinuously=false; //Should the Particle System emit these particles forever or not
particleData.numberOfParticlesPerEmission=200.0; //Number of particles to emit per emission
particleData.emissionRate=0.1; //Particle's emission rate
particleData.maxNumberOfParticles=200; //Maximum number of particles to create 
particleData.gravity=U4DVector3n(0.0,0.0,0.0); //Gravity effect on the particle.
particleData.particleSystemType=SPHERICALEMITTER; //Emitter type= Speherical
particleData.enableNoise=false; //disable noise
particleData.enableAdditiveRendering=true; //Enable Additive rendering. i.e., color blending
particleData.sphereRadius=5.0; //Size of the sphere emitted by the Spherical Emitter

Creating Particles

To create Particles, you need to instantiate a U4DEngine::U4DParticleSystem() object. And then provide the information stated above by calling the method U4DEngine::U4DParticleSystem::loadParticleSystem. To start the rendering of the particles, you call the U4DEngine::U4DParticleSystem::play method.

The snippet below shows an example of how to create a Particle System:

//Create a Particle System instance
U4DEngine::U4DParticleSystem *particleSystem=new U4DEngine::U4DParticleSystem();

//Load the particle's attributes and particle system data into the Particle System entity
if(particleSystem->loadParticleSystem("particle","particlesystemattributes.u4d",particleData)){
    
    //load the attributes into the GPU
    particleSystem->loadRenderingInformation();

    //add the particle system to the scenegraph
    addChild(particleSystem);

    //initiate the particle's emission
    particleSystem->play();
    
}

Since, the Particle’s System Data stated the emitter to be Spherical, the Particle System will emit the particles in a spherical fashion as shown below:

image

Particle Systems with different Emitters

Torus

image

Code Snippet

// Particle System structure
U4DEngine::PARTICLESYSTEMDATA particleData;

particleData.particleStartColor=U4DVector3n(1.0,0.0,0.0); //Provide the start color of the particle
particleData.particleEndColor=U4DVector3n(0.0,1.0,1.0); //Provide the end color of the particle

particleData.particleSpeed=0.2;  //Particle's desired speed
particleData.particleLife=3.5; //Particle's life span
particleData.emitContinuously=false; //Do not emit continusously
particleData.numberOfParticlesPerEmission=200.0; //Number of particles to emit per emission
particleData.emissionRate=0.1; //Particle's emission rate
particleData.maxNumberOfParticles=200; //Maximum number of particles to create 
particleData.gravity=U4DVector3n(0.0,0.0,0.0); //Gravity effect on the particle.
particleData.particleSystemType=TORUSEMITTER; //Emitter type= Torus shape
particleData.enableNoise=false; //disable noise
particleData.enableAdditiveRendering=true;  //Enable Additive rendering. i.e., color blending
particleData.torusMajorRadius=15.0; //Torus major radius
particleData.torusMinorRadius=5.0; //Torus minor radius

//Create a Particle System instance
U4DEngine::U4DParticleSystem *particleSystem=new U4DEngine::U4DParticleSystem();

//Load the particle's attributes and particle system data into the Particle System entity
if(particleSystem->loadParticleSystem("particle","particlesystemattributes.u4d",particleData)){
    
    //load the attributes into the GPU
    particleSystem->loadRenderingInformation();
    
    //rotate the particle system about the x axis
    rotateBy(90.0,0.0,0.0);
    
    //add the particle system to the scenegraph
    addChild(particleSystem);

    //initiate the particle's emission
    particleSystem->play();
    
}

Linear

image

Code Snippet

// Particle System structure
U4DEngine::PARTICLESYSTEMDATA particleData;

particleData.particleStartColor=U4DVector3n(0.2,0.2,0.2); //Provide the start color of the particle
particleData.particleStartColorVariance=U4DVector3n(0.1,0.1,0.1); //color variance of the particle as it goes from the Start Color to the End Color
particleData.particleEndColor=U4DVector3n(0.0,0.0,1.0); //Provide the end color of the particle

particleData.particleEmitAngle=U4DVector3n(90.0,0.0,90.0); //Emit angle
particleData.particleEmitAngleVariance=U4DVector3n(40.0,0.0,30.0); //Emit variance angle

particleData.particleSpeed=4.0; //Particle's speed
particleData.particleLife=2.0; //life span
particleData.emitContinuously=true; //emit continuously
particleData.numberOfParticlesPerEmission=10.0; //emit 10 particles per emission
particleData.emissionRate=0.1; //emission rate
particleData.maxNumberOfParticles=200; //maximum number of particles
particleData.gravity=U4DVector3n(0.0,-5.0,0.0); //effect of gravity
particleData.particleSystemType=LINEAREMITTER; //emitter type=Linear
particleData.enableAdditiveRendering=true; //enable blending
particleData.enableNoise=false; //disable noise

//Create a Particle System instance
U4DEngine::U4DParticleSystem *particleSystem=new U4DEngine::U4DParticleSystem();

//Load the particle's attributes and particle system data into the Particle System entity
if(particleSystem->loadParticleSystem("particle","particlesystemattributes.u4d",particleData)){
    
    //load the attributes into the GPU
    particleSystem->loadRenderingInformation();

    //add the particle system to the scenegraph
    addChild(particleSystem);
    
    //initiate the particle's emission
    particleSystem->play();
    
}