?/TD>
Microsoft DirectX 9.0

Vertex Alpha


Alpha data can be supplied in the vertex data. To enable vertex alpha, set the D3DRENDERSTATE_DIFFUSEMATERIALSOURCE to D3DMCS_COLOR1 so that the Microsoft?Direct3D?runtime takes the diffuse value from the diffuse color rather than the material.

m_pd3dDevice->SetRenderState( D3DRENDERSTATE_DIFFUSEMATERIALSOURCE,  
                              D3DMCS_COLOR1 );

Then, provide alpha values in the diffuse color. The AddAlphaToASphere function, adds alpha to the vertices of a sphere. Here's an example of how to provide the alpha information to the function.

AddAlphaToASphere( m_pObstacleVertices, 12,  
           D3DRGBA(light.dcvDiffuse.r, light.dcvDiffuse.g, 
		           light.dcvDiffuse.b, vAlpha ));

This is what the function looks like.

 
void AddAlphaToASphere(D3DLVERTEX* pVertices, DWORD dwNumRings, D3DCOLOR lightcolor)
{
 WORD x, y;
 // rings around
    for( y=0; y < dwNumRings; y++ )
        for( x=0; x < (dwNumRings*2)+1; x++ )
            (pVertices++)->color = lightcolor;
 
 // top and bottom
    (pVertices++)->color = lightcolor;
    (pVertices++)->color = lightcolor;
}

AddAlphaToASphere simply modifies the color member of each vertex, which are of type D3DLVERTEX, to include the alpha information.

D3DLVERTEX looks like this.

 
// Lit vertex
typedef struct {
 D3DVALUE x, y, z;
 DWORD dwReserved;
 D3DCOLOR color, specular;
 D3DVALUE tu, tv;
} D3DLVERTEX, *LPD3DLVERTEX;

Drawing the sphere,

  // Draw the lit sphere
 m_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, D3DFVF_LVERTEX,
                              m_pObstacleVertices, m_dwNumObstacleVertices,
                              m_pObstacleIndices,  m_dwNumObstacleIndices, 0 );

results in a transparent sphere using vertex alpha.



© 2002 Microsoft Corporation. All rights reserved.