Jump to content
  • Advertisement
Sign in to follow this  
Larry91

Alpha channel

This topic is 2999 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 everybody!
I have a problem with an alpha channel! The mesh that has a texture on the alpha channel is rendered without translucence!

I wanna render a mesh water with an alpha texture!

Here's my code:


// Enable alpha testing
m_pD3DDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
m_pD3DDevice->SetRenderState( D3DRS_ALPHAREF, (DWORD)0x000000A0 );
m_pD3DDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );

m_pD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
//m_pD3DDevice->SetRenderState( D3DRS_ALPHATESTENABLE, false );

m_pD3DDevice->SetRenderState( D3DRS_SRCBLEND , D3DBLEND_SRCALPHA );
m_pD3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );

m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

m_pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );

// Set up sampler states.
m_pD3DDevice->SetSamplerState( 0, D3DSAMP_MINFILTER , m_MinFilter );
m_pD3DDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER , m_MagFilter );
m_pD3DDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER , m_MipFilter );
m_pD3DDevice->SetSamplerState( 0, D3DSAMP_MAXANISOTROPY, m_Anisotropy );

// Set texture / addressing / color ops
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP , D3DTOP_MODULATE );
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 );

Share this post


Link to post
Share on other sites
Advertisement
m_pD3DDevice->SetRenderState( D3DRS_ALPHAREF, (DWORD)0x000000A0 );

0xA0 seems very high. Have you tried using a smaller value?

Also, have you tried disabling alpha testing completely?

Share this post


Link to post
Share on other sites
I believe that I solved this pseudo problem!
The true problem consist in alpha sorting, and I don't know how can I get details about meshes for discover if a mesh has alpha!

LE1: How can I get alpha value from a texture?
For materials I tested if diffuse.a is less than 1!

LE2: I solved! 10x a lot guys! I forgot to set my texture format to ARGB! :P

[Edited by - Larry91 on July 5, 2010 6:37:16 AM]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!