gjm
04-01-2006, 04:01 AM
I was hoping someone might be able to clarify for me why my code to produce an effect with 3 texture stages is not working. Having successfully ported the classic MS causting effect (causts being texture stage 0), mixed with an ocean texture (texture stage 1) into my very slowly evolving engine, I want to now take the result of the previous effect and mask it was a shore sand texture, basically where my ocean and beech meet (i.e. have a smooth shore rather then a flat transition between textures). The result of this I intended to happen as texture stage 3.
The 3 texture setups look like:
g_pd3dDevice->SetTexture( 0, caustTexture[caustValue] );
g_pd3dDevice->SetTexture( 1, oceanTexture );
g_pd3dDevice->SetTexture( 2, sandTexture );
The causts and ocean as an effect alone work fine. That effect I simply accomplish with:
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_ADDSIGNED );
Without causting, I can mask the ocean with my sand texture (which is a DDS alpha texture). That looks like (assuming ocean is stage 0 and sand mask is stage 1):
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA );
So far so good! But I want the causts to go right up to where the sand mask starts to occlude. So I tried this (assuming caust is stage 0, ocean is stage 1 and sand mask is stage 2):
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_ADDSIGNED );
g_pd3dDevice->SetTextureStageState( 2, D3DTSS_COLORARG2, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 2, D3DTSS_COLORARG1, D3DTA_CURRENT );
g_pd3dDevice->SetTextureStageState( 2, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 2, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA );
The result is simply the caust and ocean textures - no sand masking of this resulting texture occurs. I have confirmed that I have three vertices in the custom vertex structure, that I use D3DFVF_TEX3 and that the vertices are all allocated coordinates.
Something is wrong with the state settings I think. The two effects work fine seperated - would just be cool if they could all work as one (and in one pass!). Fail to see why merging the causts with the ocean and then masking that result with a sand alpha is so difficult. Overall this is all happening on a simple tile geometry, nothing complicated.
If anyone has the low down on texture ops and arguments please feel free to comment. I am sure I'm not the only person to have experienced trouble with the DX9 docs for this topic!
Glen
(also are there any good modern game programming texts that cover advanced topics on dx9?)
The 3 texture setups look like:
g_pd3dDevice->SetTexture( 0, caustTexture[caustValue] );
g_pd3dDevice->SetTexture( 1, oceanTexture );
g_pd3dDevice->SetTexture( 2, sandTexture );
The causts and ocean as an effect alone work fine. That effect I simply accomplish with:
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_ADDSIGNED );
Without causting, I can mask the ocean with my sand texture (which is a DDS alpha texture). That looks like (assuming ocean is stage 0 and sand mask is stage 1):
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA );
So far so good! But I want the causts to go right up to where the sand mask starts to occlude. So I tried this (assuming caust is stage 0, ocean is stage 1 and sand mask is stage 2):
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_ADDSIGNED );
g_pd3dDevice->SetTextureStageState( 2, D3DTSS_COLORARG2, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 2, D3DTSS_COLORARG1, D3DTA_CURRENT );
g_pd3dDevice->SetTextureStageState( 2, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 2, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA );
The result is simply the caust and ocean textures - no sand masking of this resulting texture occurs. I have confirmed that I have three vertices in the custom vertex structure, that I use D3DFVF_TEX3 and that the vertices are all allocated coordinates.
Something is wrong with the state settings I think. The two effects work fine seperated - would just be cool if they could all work as one (and in one pass!). Fail to see why merging the causts with the ocean and then masking that result with a sand alpha is so difficult. Overall this is all happening on a simple tile geometry, nothing complicated.
If anyone has the low down on texture ops and arguments please feel free to comment. I am sure I'm not the only person to have experienced trouble with the DX9 docs for this topic!
Glen
(also are there any good modern game programming texts that cover advanced topics on dx9?)