Jump to content
  • Advertisement
Sign in to follow this  
limpacp

Transparency and Alpha channel!

This topic is 4613 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! I'm writting 2D game. I have a png image with alpha channel. My game has 3 states of blitting: normal, diffuse and additive. Right now i've added one more mode transparent: Using this states: m_pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); m_pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); m_pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); m_pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE); When i'm activating this mode alpha channel is lost! What's wrong ? I need to blend image with alpha channel, what states do i need to set! Please help! Thanks!

Share this post


Link to post
Share on other sites
Advertisement
A couple things.

Setting DESTBLEND is only part of setting up the blending mode. You should also set SRCBLEND, and possibly BLENDOP. Regular blending is:
SRCBLEND = SRCALPHA
DESTBLEND = INVSRCALPHA
BLENDOP = ADD.
ALPHABLENDENABLE = true

possibly also have D3D not waste time blending fully transparent parts.
ALPHATESTENABLE = true
ALPHAREF = 0
ALPHAFUNC = GREATER

Note that alphatest and alphablend are seperate. You can use testing to cut shapes without enabling blending. This is useful because alphatested holes aren't rendered to Z, stencil, or color buffers. This allows sprites to be non-square and use Z buffering at the same time.

Second thing, and this will be your main problem, is your state setup. It's incomplete, and you're specifically asking not to get the texture alpha, but just vertex or material alpha. A complete state setup should set not just the operations, but the arguments as well. You ask for alpha to come from DIFFUSE which is the result of the lighting system. You want the alpha to be from the texture.

0, D3DTSS_COLOROP, D3DTOP_SELECTARG1
0, D3DTSS_COLORARG1, D3DTA_TEXTURE
0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1
0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE
1, D3DTSS_COLOROP, D3DTOP_DISABLE
1, D3DTSS_ALPHAOP, D3DTOP_DISABLE

You can mix vertex/material alpha with texture alpha like so
0, D3DTSS_COLOROP, D3DTOP_SELECTARG1
0, D3DTSS_COLORARG1, D3DTA_TEXTURE
0, D3DTSS_ALPHAOP, D3DTOP_MODULATE
0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE
0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE
1, D3DTSS_COLOROP, D3DTOP_DISABLE
1, D3DTSS_ALPHAOP, D3DTOP_DISABLE

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!