   alpha blending - renderstates
  Dear community,I want to fade in/out a mesh and can't get it to work the way I want to. ;)I have a 3ds mesh (shockwave) which has his own texture without alpha (as it's a jpeg). I want to display this mesh using an additiv method combined with vertex alpha.The darker the texture is, it should be more transparent (black = complete transparent), which works great using an additiv method with the following renderstates:pID3DDevice->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_MODULATE);pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TEXTURE);pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);pID3DDevice->SetTextureStageState (0, D3DTSS_ALPHAOP,  D3DTOP_DISABLE);pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);material.ZWriteEnable = false;Please see this image:Ok, now I want to fade out this mesh, which (of course) does not work using this additiv thing. So I have to use vertex alpha with which I can fade it out.Please take a look:As you can see, the black color has the same priority as all the other colors, which is (of course again) ok for the used vertex alpha. ;)I use the following render- and texturestagestates for vertex alpha:pID3DDevice->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_MODULATE);pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TEXTURE);pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);pID3DDevice->SetTextureStageState (0, D3DTSS_ALPHAOP,  D3DTOP_SELECTARG1);pID3DDevice->SetTextureStageState (0, D3DTSS_ALPHAARG1,  D3DTA_DIFFUSE);pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);pID3DDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);material.ZWriteEnable = false;Please take a look again:Ok. Now blending works fine. But I would need a combination between adding colors and vertex alpha. Is this even possible?I use the following renderstates:pID3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );pID3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );pID3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );I know, I have to use some texturestagestates, something likepID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1,  D3DTA_TEXTURE );(which does not work) but I don't get the point. Do you have an idea?1. I don't want to use shaders.2. I don't want to use textures with alpha channel.In my mainloop I set the alpha of the vertices (which is not very performant). I guess I have to set the diffuseColor component and create my own material?I know it is possible, even Blitzbasic can do this, using a texture without an alpha channel, set something like ADD_COLOR and fade it in and out. ;)Thanks a lot, thanks for reading and best regards - Xaron   
  Hi thereIf you use additive blendingyou should not set vertex alpha but decrease vertex color from (1,1,1,1) to (0,0,0,0) this will fade out your meshEDIT: Welcome to gamedev.net :)   ;  Thank you Madhed! I will try it. :)And thanks for the welcome, too! :D As I'm a reader for several years now, this is really my first post...edit: Well that works like the mesh fade out I've described above (the 3rd image series). But I just want to have it look that way:Please notice, that there are no black borders. ;)I just want to set the transparency. If I do it using D3DBLEND_SRCALPHA and D3DBLEND_INVSRCALPHA it blends the black color, too...Regards - Xaron   ;  You could try using the TFactor as the second alpha argument on the texture stage and modulate between them. This way you can control the overall alpha of the mesh and still use the texture color as the base alpha value. Unfortunately I mainly work in C#, so I can't provide you with an accurate code snippet. Something like this should work though:[source lang=cpp]pID3DDevice->SetTextureStageState (0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);pID3DDevice->SetTextureStageState (0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR);pID3DDevice->SetTextureStageState (0, D3DTSS_ALPHAOP,  D3DTOP_MODULATE);pID3DDevice->SetRenderState(D3DRS_TEXTUREFACTOR, 0xffffffff); // change alpha as needed;  Hi Xaron, I don't know how you do it, but the method I described has always worked for me.pID3DDevice->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_MODULATE);pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TEXTURE);pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);//fully visiblevertex.color = D3DXCOLOR(1,1,1,1);//half transparentvertex.color = D3DXCOLOR(0.5,0.5,0.5,1);//invisiblevertex.color = D3DXCOLOR(0,0,0,1);You see? By setting colorarg1 and 2 to texture and diffuse and setting colorop ro modulate (multiply) you can set the vertex color and it will multiply with the texture's color.Then you supply D3DBLEND_ONE for source and destinationThe color will be added to the screen.   ;  Thanks for that! Finally I've found a solution based on that additiv method:pID3DDevice->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_MODULATE);pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TEXTURE);pID3DDevice->SetTextureStageState (0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);pID3DDevice->SetTextureStageState (0, D3DTSS_ALPHAOP,  D3DTOP_DISABLE);pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);material.ZWriteEnable = false;I just have to set the colors for all vertices instead of only setting the alpha values which is not very performant but it works. ;) I will look for a better solution (I should say that I use Irrlicht)...Thanks for all help! :)edit:Madhed, thanks for your solution, it works better than mine! :) Your image is quit much brighter in full visibility! Thanks! :)Please take a look to see the differences:Using additiv color material (from irrlicht):pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);Using your solution, Madhed:Thanks again!Regards - Xaron   ;  good to see that it works!By the way, both solutions are commutative (rendering order is not important)Thanks for the positive rating. ;)   