   texture alpha blend
  Hi, i'm trying to blend textures in a terrain editor, i'm using a kind of brush in order to texture the terrain. I'm using a base texture and when I add a second texture everything blends correctly, but when I try to add a third (or more) different texture I can't get the last to stages in order to blend the last two with the third one.I'm using stage textures, the problem is that i dont know how many different textures a piece of the terrain is gonna end with, so i can't define the number of stages. Is there any way i can do this "concurrent texture alpha blend"?Any help will be highly appreciated!!!!Thank you[Edited by - alberto_snv on June 17, 2006 10:59:09 AM]
  The maximum number of unique textures you can blend using multitexture blending in a single pass is dependent on the capabilities of your graphics card.Check out the D3DCAPS9.MaxSimultaneousTextures device cap to determine this maximum for your particular card.For older generation graphics cards, the maximum is usually 2.The only real solution to that hardware limitation is to use multiple passes (i.e. render the first 2 blended textures in the first pass, and then render again with the second 2 blended textures in a second pass). You can use framebuffer [alpha] blending to control how the two passes blend together.   ;  Thank you very much!!I think multipass render is the only solution. I'm new in directx, so please forgive me for any silly quote or questionI'm trying to do the multipass render as you said. I'm using the diffuse color alpha component in each vertex in order to blend the first two textures as follows (is this the "framebuffer [alpha] blending" you talk about?):g_dDevice->SetTexture(0,g_dTexture);g_dDevice->SetTexture(1,g_dTexture);g_dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE); g_dDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);g_dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_DIFFUSE);g_dDevice->SetTextureStageState(1,D3DTSS_RESULTARG,D3DTA_CURRENT);g_dDevice->SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_BLENDDIFFUSEALPHA);Everything works fine, but now i can't "recover" that last blend in order to be blended again with another texture. I'm trying ///Change texture coordinates and alpha values/////cycle for all other texturesg_dDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_BLENDDIFFUSEALPHA);g_dDevice->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTOP_CURRENT);g_dDevice->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTOP_TEXTURE);g_dDevice->SetTextureStageState(1,D3DTSS_ALPHAOP,D3DTOP_DISABLE);g_dDevice->SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_DISABLE);////////////////////////////////////Probably i'm not using properly the D3DTSS_RESULTARG or i'm totally lost. How can i achieve the desired result?. Thank you!![Edited by - alberto_snv on June 17, 2006 12:43:12 PM];  On the second pass, you want to blend what's already on the screen, with what you're currently drawing. Since the data is already on the screen, it isn't actually available in the Texture Stage part of the pipeline.The way you blend your current pass with the previous pass is a method called Alpha Blending. Since this is performed after the Texture Stage part of the pipeline, you won't have the previous color yet, so you'll need to only blend the two textures you are currently using. This is fine, because after blending these two together, they'll get blended in with the previous 2 passes.I think you'll be best off reading some more on alphablending. IIRC, the SDK documentation has some good info on how it works exactly :).Hope this helps.   ;  Thank you very much!!, now everything is working fine, i just needed to change the second pass to:g_dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);g_dDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCCOLOR);g_dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCCOLOR);g_dDevice->SetTexture(1,NULL);jeje, thank you!   