Still no success on the texture mask, but I think I'm beginning to understand the texturestages & ops.
This is what I have so far, and I don't really understand why it doesn't work, maybe my textures are causing additional problems. Anyway, here goes:
// Enable alpha
m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
// Set the 2 textures, first is image, second is alpha
m_pd3dDevice->SetTexture( 0, m_pAlpha1Texture );
m_pd3dDevice->SetTexture( 1, m_pAlpha2Texture );
// Set the first texture stage to just return texture1 unmodified
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
// Set the second texture stage to just keep the texture information calculated in stage 0
m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_CURRENT );
// Use the alpha from stage 1 as output alpha
m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
m_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
Alternatively, it should also work by modulating the two alphachannels as dankydoo suggested (replace the last two lines above with the ones below).
// modulate the output from stage 0 (D3DTA_CURRENT) with the alpha from this
// texture (D3DTA_TEXTURE)
m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE );
m_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG2, D3DTA_CURRENT );
Anyone care to look this over and check for obvious mistakes? Or even better, try it with some of your own textures and see if you can get it to work.