Jump to content
  • Advertisement
Sign in to follow this  

how to set material alpha blend?

This topic is 3427 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

Original post by sunrisefe
I want to use a rectangle with leaf texture to render a tree's leaf.
So how to set that in directx?

If you are using shaders, render a quad (2 triangles) and apply over them the leaf texture. (Remember to activate the AlphaBlending blendstate)

Share this post

Link to post
Share on other sites
Leaves are often done with AlphaTesting rather than AlphaBlending. Alphatest is a pure 100% on or off. When a pixel is discarded, the Z buffer is not affected, leaving proper holes in your Z buffer. This allows you to render without worrying about draw order.

Setting the following render states will make any alpha value over 128 draw.

For full blending, where you can get soft transparent edges, you need to set some different states, and render in a certain way. Blending typically is done after you've drawn everything that's solid, and you must render blended objects sorted back to front, to blend correctly with other overlapping blended objects.


You can mix blending and testing so large alpha values get blended, and small alpha values leave holes. Combining them is usually only used to get a performance boost on large transparent areas. Typically you'll have it discard very small alphas (like an ALPHAREF of 8) which wouldn't really contribute to the final image anyway.

Share this post

Link to post
Share on other sites
Thank you,Namethatnobodyelsetook and feal87.

I will check out how to do alpha test and alpha blending for leaf.

BTW,Personal DirectX Related Blog cannt open.

Share this post

Link to post
Share on other sites
I use alpha-blend to draw the leaf. Though through alpha-test will have performance inhance, I dont know how to do it. My alpha-blend code is as follows. BTW,how to get the texture's format(like r8g8b8) to know how large is the alhpa? Any tool or code?

// Create the texture and set filters.

Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);

Device->SetRenderState(D3DRS_LIGHTING, false);//close lighting

// Set alpha blending states.

//draw code
Device->SetTexture(0, Tex);
Device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);// turn on alpha-blend

Device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);

Device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);//turn off alpha-blend


Share this post

Link to post
Share on other sites
Namethatnobodyelsetook,thank you.
In directx sdk2008, the DirectX Texture Tool doesn't work. When click it, the error "unable to create direct3d device,please make sure your desktop color depth is 16 or 32 bit, and that d3dref.dll is installed.". However,my desktop color depth is 32bit and I download one d3dref.dll and put it in the C:\WINDOWS\system32. So how to mend this error? Thank you.

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!