In this IOTD we are using two particle systems, one for the twinkling stars in the front and one for the space travel stars in the background.
Our particle system consists of emitters and affectors that can be combined into a system. Emitters produce particles and affectors modify the particles’ properties over time, like for example gravity. Particles’ properties can also be manually animated by the timeline system that our software offers for animation. During the lifetime of a particle it may spawn new emitters which allows for more complex behavior.
On the technical rendering side, DirectX 9 is used for the rendering.
The particle system uses two stream sources and the stream source frequency functionality to instantiate the particle geometry in the vertex shader. The CPU only manages a list of particle positions and properties.
In DirectX 9 this is done like:
pDevice->GetD3DDevice()->SetStreamSource(0, m_pCornerDataVB, 0, sizeof(M_CORNERVERTEX) ); pDevice->GetD3DDevice()->SetStreamSourceFreq(0, D3DSTREAMSOURCE_INDEXEDDATA | m_particleCount); pDevice->GetD3DDevice()->SetStreamSource(1, m_pParticleDataVB, 0, sizeof(M_PARTICLEDATA) ); pDevice->GetD3DDevice()->SetStreamSourceFreq(1, D3DSTREAMSOURCE_INSTANCEDATA | 1); pDevice->GetD3DDevice()->SetIndices(m_pParticleIndices); pDevice->GetD3DDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2);
The first stream, pCornerDataVB, contains the definition of a single particle which is basically just the texture coordinates of a quad. The second stream, pParticleDataVB, contains the particles’ positions and properties.
Another functionality that also greatly increased the particle rendering speed was the use of texture packing. Particles in our system may use different textures, but we did not want to separate the rendering into multiple passes for different textures. The solution was to pack all individual textures into a new single texture at particle system initialization. The particle data passed to the vertex shader then contain texture offset and size information that is used to select the correct sub-texture.
If you want to play with the particle system yourself you can download the software at:
If you manage to create some really cool looking particle system, please send me a message with a screenshot or link to a youtube video. It would be really nice to see what can be done with it.
Click here to view the iotd