Transparent textures again

Hi, I'm bringing the transparent issue once again to this forum, mainly because after of doing a lot of google searches, forum searches, etc, I still can't get transparency to work.

I've created a png file that has transparency. I know it is correct, because I've opened it with the D3d texture viewer, and I can see the alpha channel.

I've created a simple object and assigned the texture to it in 3ds max.

I've loaded the object but the transparency isn't working.

I'm already tried SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE).
I'm rendering with DrawSubset().

Any ideas
Thanks



Answer this question

Transparent textures again

  • RajeshPKumar

    I've already implemented the exception for transparent objects as I'm describing above.
    It is working perfectly! Well, almost perfectly. As expected, shadows will not be cast on this type of objects.
    No problem. After playing Tomb Raider 3 on the PS2, I think that my shadows are more then enough. What a lousy game. The worse I've seen in the PS2! So many bugs! I hate seeing such a good character being so mistreated.

    I got no performance impact with this. The game is currenly running at 80-100 fps and my computer is not that good.

  • Sarada

    SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE).

    This is one of the many things you need to set but not enough :-)

    This should help :

    pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
    pDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
    pDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);

    pDevice->SetTextureStageState(D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);
    pDevice->SetTextureStageState(D3DTSS_ALPHAARG1,D3DTA_DIFFUSE);

    If you later need to use the texture alpha as the source, set D3DTSS_ALPHAARG1 to D3DTA_TEXTURE. (this is more like your case)

    http://www.mvps.org/directx/faq/dx8gr_faq.htm

    When you load your texture make sure you use RGBA format so the alpha is there
    You may want to set this alpha value when you load instead of from another software










  • Yurik

    I've managed to get this to work thanks to you!
    I've followed the guidelines on the FAQ in the link u provided.
    I'm using D3DXCreateTextureFromFileEx() specifying the color key.

    Unfortunately this is bringing a lot more problems. I'm using shadows on my game, so I have to make 2 passes while rendering (using the stencil buffer).
    The transparency only works on the first pass, so the transparent area seems to be in the shadow.
    Another problem is that I'm sorting the objects from near to far (I read somewhere that this has better performance on the render, and I think this is possible).
    For transparency to work, transparent objects should be drawed last (correct ).
    For what I've understanded, the pixels are filtered, but the Z-buffer is filled anyway, is this correct

    What I think I have to do, is to open an exception for transparent objects, exclude them from the main render loop (the one that deals with shadows), and render them after the main render.

    I'l try this.
    Thanks

  • Transparent textures again