Technology Demo

Particle Demo

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Spot for images

Intro

This demo will show the basics of how to set up a particle system.

Particle File

In order to create a particle system, you need to have a few files in your project.

  • Orb.particle
  • basequad.material
  • particle.material
  • basequad.cg

For orb.particle, create a new folder in the project name Particles. Then, right click on the folder and select New > File. Name the file orb.particle, and then enter the following code.

particle_system OrbDroplets
{
    material Spot
    particle_width 0.1
    particle_height 0.1
    cull_each false
    quota 1000
    billboard_type point

    // Area emitter
    emitter Point
    {
        angle 25
        emission_rate 60
        time_to_live 1
        direction 0 1 0
        velocity_min 1
        velocity_max 3
        colour 1 1 1 
    }

	affector Interpolation
    {
    	relative_size true
    	values 0 1 0.9 1 1 0
    }
	
	affector LinearForce
	{
	    force_vector 0 -10 0
	}
}

This sets up a particle system called OrbDroplets for us to start out with. It uses a material called spot, which will be put into the particle.material file. Create another file, this time a material, and make it your particle.material file.

Material Files

The material file will be used to determine the texture used to create the particles, and to set a few other attributes. Below is the code for particle.material.

material Spot
{
   technique
   {
      pass
      {
	  scene_blend add
	  depth_write off
	  //depth_check off
	  ambient 0.5 0.5 0.5
		
	  texture_unit
	  {
	     texture Textures/flare.png
	  }
      }
   }
}

Two more files that need to be put in are basequad.material and basequad.cg. These are used to determine the shader and define the shader, respectfully. The first listed here is basequad.material.

vertex_program BaseQuadVS cg
{
	source Shaders/basequad.cg
	entry_point main
	profiles vs_1_1 arbvp1 vp20
	default_params{
		param_named_auto worldViewProj worldviewproj_matrix
	}
}

This is basequad.cg.

void main(in float4 inPos : POSITION,
	      out float4 pos : POSITION,
    	  out float2 uv0 : TEXCOORD0,
    	  uniform float4x4 worldViewProj)
{
    pos = mul(worldViewProj, inPos);

    inPos.xy = sign(inPos.xy);
    uv0 = (float2(inPos.x, -inPos.y) + 1.0f) * 0.5f;
}

It is important to make sure that basequad.material is one of the first files loaded into your project. To do this, open up the Particle Systems.l3d.xml file, and at the very bottom of the page will be tabs saying "Attributes", "Resources", "Loading Order" and the name of the XML file. Select Loading Order.

Under Resource Files, select the basequad.material file and click "Up" until it's at the very top, if it isn't already.

Implementing a Particle System

Most of the work in creating a particle system in Luster comes in the set-up of the material files and particle files. To put your new particle system into the scene, all you need to do is open the Root.lua file and input the following code following the camera creation.

local system = luster.display.ParticleSystem("OrbDroplets")
self:addChild(system)
system.z = -3

Here, all we do is create a new ParticleSystem object which is part of the display, and give it the name of the particle system we wrote earlier. Then, we add it to the stage and move it away from the camera so we can see it.