   how to set material alpha blend?
  I want to use a rectangle with leaf texture to render a tree's leaf.So how to set that in directx?   
Quote:Original post by sunrisefeI 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)   ;  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.D3DRS_ALPHATESTENABLE, trueD3DRS_ALPHAFUNC, D3DCMP_GREATEREQUALD3DRS_ALPHAREF, 128For 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.D3DRS_ALPHABLENDENABLE, trueD3DRS_SRCBLEND, D3DBLEND_SRCALPHAD3DRS_DESTBLEND, D3DBLEND_INVSRCALPHAD3DRS_BLENDOP, D3DBLENDOP_ADDYou 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.;  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.   ;  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.D3DXCreateTextureFromFile(Device,"leaf.png",&Tex);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.Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);   //draw code   Device->SetTexture(0, Tex);Device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);// turn on alpha-blendDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);Device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);//turn off alpha-blend  [\source];  You can get the format via:D3DSURFACE_DESC desc;pTexture->GetLevelDesc(0, &desc);;  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.   