Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

RogalDorn

Partly Transparent textures

This topic is 5442 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 am writing a totally Shader driven engine. Today I tried to add tree textures to my landscape and encountered the following problem. In my tree texture I made all pixels I want to have completely transparent an alpha value of 0.0f. All other pixels got an alpha value of 1 (it's a tga texture with an alpha channel) How do I have to set up my directx device to make pixels with an alpha value of 0 totally transparent??? I tried these settings but had no luck.. m_pDirect3DDevice9->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE ); m_pDirect3DDevice9->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); m_pDirect3DDevice9->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); // Enable alpha testing (skips pixels with less than a certain alpha.) m_pDirect3DDevice9->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE ); m_pDirect3DDevice9->SetRenderState( D3DRS_ALPHAREF, 0x08 ); m_pDirect3DDevice9->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL ); I also tried to simply enable alpha blending but then everything went transparent. *eeek* // ENABLE ALPHA BLENDING // Set the source blend state. // m_pDirect3DDevice9->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); // Set the destination blend state. // m_pDirect3DDevice9->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_DESTCOLOR); Thanks a lot in advance Greetings Jan [edited by - RogalDorn on January 22, 2004 11:19:26 AM]

Share this post


Link to post
Share on other sites
Advertisement
Better than enabling alpha blending if you just want on and off is to use the alpha test.

Render the tree as normal, but set the render state for alpha testing to greater or equal, and set the alpha test ref to something like 1.

What alpha testing does is take the pixel it is about to draw to the back buffer, and compare it's value with the alpha test value. If the pixel passes the comparison, then it is drawn, otherwise it is discarded.

This can be a nicer way of doing things than true alpha since you don't need to sort anything. Of course you can't get semi-transparency from this method though.

You can see alpha testing in action in games like stalker where it renders loads of vegitation up-close using alpha testing so that there is no sorting necessary. That's also why the vegetation "grows" out of the ground rather than fading in.

So, in short. Turn blending off, turn alphatest on, and render!

[edited by - protopornopants on January 22, 2004 1:10:30 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!