PDA

View Full Version : Dont update Zbuffer if Alphatest fails?



snorga
01-12-2004, 06:14 PM
Is it posible to set any renderstate or something else, sA¥ that it dont write to the z-buffer if alphatest fails?

ie if I draw a rectangle with a texture that have transparency (a 2d sprite with a alpha channel).
then the zbuffer will draw a full rectangle,
but i dont want the zbuffer updated where the sprite is transparent..

:cry:

(Using Direct3D v.9c)
(and by transparent, i mean on/off.. no half transparent)

Clootie
01-12-2004, 06:53 PM
Alpha test is EXACTLY what you are looking for!

Stright from DirectX help file:

The most common use for alpha testing is to improve performance when rasterizing objects that are nearly transparent. If the color data being rasterized is more opaque than the color at a given pixel (D3DPCMPCAPS_GREATEREQUAL), then the pixel is written. Otherwise, the rasterizer ignores the pixel altogether, saving the processing required to blend the two colors. The following code example checks if a given comparison function is supported and, if so, it sets the comparison function parameters required to improve performance during rendering.
if (pCaps.AlphaCmpCaps and D3DPCMPCAPS_GREATEREQUAL) <> 0 then
begin
dev.SetRenderState(D3DRS_ALPHAREF, DWORD($00000001));
dev.SetRenderState(D3DRS_ALPHATESTENABLE, iTrue);
dev.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
end;

snorga
01-12-2004, 07:02 PM
Damn, i did get alphatest and alphablend mixed up..
*do'h* stupid me.. :roll:

Now it works just like I wanted it to do.

Thanks alot :D