?/TD>
Microsoft DirectX 9.0

Material Alpha


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

   m_pd3dDevice->SetRenderState( D3DRENDERSTATE_DIFFUSEMATERIALSOURCE,   D3DMCS_MATERIAL );

Initialize the material with an alpha value to generate transparency.

mAlpha = 0.5f;
D3DUtil_InitMaterial( m_mtrl, 
light.dcvDiffuse.r, light.dcvDiffuse.g, light.dcvDiffuse.b, mAlpha );

Then draw a transparent sphere using material alpha.

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


© 2002 Microsoft Corporation. All rights reserved.