• Skip to site navigation
  • Skip to blog entries
  • Skip to archive page
  • Skip to left sidebar
  • Skip to right sidebar

Particle System Rendering: Using Triangle Strips

Fork Particle Blog

Thursday, July 12. 2012

Particle System Rendering: Using Triangle Strips

Posted by
Noor Khawaja
in Particle System
Particle effects geometry quads may be rendered with Point Sprites, Triangles, Quads, and Tri-Strips render primitive types. Each primitive type can be indexed or non-indexed. There is a benefit to using indexed primitives for particle geometry quads – the vertex index buffer needs to be filled only once provided the index buffer is not destroy or recreated.

The Tri-Strips primitive method requires that each quad is disjointed after every quad. So after every four vertices, a degenerate triangle is inserted between two quads. The degenerate triangle is automatically dropped during rendering. Here is some DirectX source code snippet to setup the indices:


// Fill indices (index buffer)
WORD* pIndices = NULL;
int nNumVerts, i;
m_pIBDxQuad->Lock (0, nIBSize, (void**)&pIndices, D3DLOCK_NOOVERWRITE);
nNumVerts = 0;
for (i = 0; i < MAX_PS_PARTICLES; i++) {
*pIndices++ = nNumVerts;
*pIndices++ = nNumVerts++;
*pIndices++ = nNumVerts++;
*pIndices++ = nNumVerts++;
*pIndices++ = nNumVerts++;
*pIndices++ = nNumVerts-1;
}
m_pIBDxQuad->Unlock();

Filling particle geometry quad vertex data is reduced to 4 vertices per quad. Assuming the particle vertex is setup with position, diffuse, and texture coordinates, here is code snippet for filling the vertex data for a single particle quad:

// Fill vertex data (vertex buffer)
pVertex->Pos = (D3DXVECTOR3) V0;
pVertex->Color = DxColor;
pVertex->UV.x = pTextCoord1->x;
pVertex->UV.y = pTextCoord1->y;
pVertex++;

pVertex->Pos = (D3DXVECTOR3) V1;
pVertex->Color = DxColor;
pVertex->UV.x = pTextCoord1->x;
pVertex->UV.y = pTextCoord2->y;
pVertex++;

pVertex->Pos = (D3DXVECTOR3) V2;
pVertex->Color = DxColor;
pVertex->UV.x = pTextCoord2->x;
pVertex->UV.y = pTextCoord1->y;
pVertex++;

pVertex->Pos = (D3DXVECTOR3) V3;
pVertex->Color = DxColor;
pVertex->UV.x = pTextCoord2->x;
pVertex->UV.y = pTextCoord2->y;
pVertex++;

m_nNumIndices += 6;
m_nNumVerts += 4;

Note that index count is incremented by 6. The indices 1 through 4 make the displayed particle quad and index 4, 5, and 6 make up the degenerate triangle which is not displayed.
Trackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as (Linear | Threaded)
No comments
The author does not allow comments to this entry

Links

  • Blog Home
  • Main Website

Archives

  • May 2013
  • April 2013
  • March 2013
  • Recent...
  • Older...

Copyright 2011 Fork Particle, Inc. All Rights Reserved. All trademarks are the property of their rightful owners.

Based on the s9y Bulletproof template framework
Powered by s9y – Template by Bulletproof development team.