Well, try this ( sorry in advance if it doesn't work ) :
Assuming :
- Your tree texture has a diffuse color component and is color keyed ( using an alpha texture, where useless/transparent pixels have an alpha of 0 ):
- You're using D3DBLEND_SRCALPHA for D3DRS_SRCBLEND, and D3DBLEND_INVSRCALPHA for D3DRS_DESTBLEND
- The diffuse color component is set to the degree of blackness you want ( i.e. how dark the shadow is going to look like )
Code:
SetTextureStageState( Stage,D3DTSS_COLORARG1, D3DTA_DIFFUSE )
SetTextureStageState( Stage,D3DTSS_COLOROP,D3DTOP_MODULATE );
SetTextureStageState( Stage,D3DTSS_COLORARG2,D3DTA_TEXTURE );
SetTextureStageState( Stage,D3DTSS_ALPHAARG1,D3DTA_TEXTURE );
SetTextureStageState( Stage,D3DTSS_ALPHAOP,D3DTOP_MODULATE );
SetTextureStageState( Stage,D3DTSS_ALPHAARG2,D3DTA_DIFFUSE );
This tells Direct3D to :
- Modulate ( multiply ) the diffuse component ( degree of blackness ) by the texture color component ( thus resulting in the shadow )
- Modulate the alpha value in the texture & the diffuse component.
Thus, if a transparent pixel ( on the texture ) is being processed, the result is 0. i.e. When alpha blending, the original pixel in the back buffer remains as is.
If, however, a non-transparent ( a data ) pixel is being taken from the tree texture, its alpha value ( typically 1 ) is to be multipled by the alpha in the diffuse ( 0.5 is good ) resulting in 0.5, which means the final pixel in the back buffer is going to be :
FinalPixel = ( 1 - 0.5 ) * OriginalPixel + 0.5 * TreeTexturePixel
Note that : TreeTexturePixel = TreeTextureDiffuseComponent * TreeTexturePixelAtUV
I know there are possibly millions of bugs here. I hope you get the idea I wanted to present. Test it, and if it runs tell me