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.
Thursday, July 12. 2012
Particle System Rendering: Using Triangle Strips
Trackbacks
Trackback specific URI for this entry
No Trackbacks