[.net] Z-Buffer problem

Started by
0 comments, last by RipTorn 17 years, 7 months ago
Im having a bit of trouble when it comes to my z-buffer, i know that this is the problem because of similar topics and websites i have found. problem Any of the topics I have found are either c++ or open gl related, some of the commands are easy to translate to the C# and MDX but others are not and i was wondering if someone can help... -------------- from what i have found most topics seem to say its the renderstate.. z depth write on, z depth write on, source alpha test - render when 255 (opaque) z depth write off, z depth test on, source alpha test - render when < 255 other source... pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, true ); pd3dDevice->SetRenderState( D3DRS_ALPHAREF, 0x01 ); pd3dDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL ); -------------- this might be wrong but i translated the above c++ code into... device.RenderState.AlphaBlendEnable = true; device.RenderState.ZBufferFunction = Compare.GreaterEqual; but i cant find how to do the alpha ref, Any help would be excellent, -Dave [Edited by - REspawn on September 5, 2006 7:04:18 PM]
Advertisement
device.RenderState.ZBufferFunction = Compare.GreaterEqual;

Generally, Never change the z buffer function. It can cause all sorts of havok which is hard to explain. The default is greater equal, leave it that way :-)
If you want to turn off depth writing, set ZBufferWriteEnable to false.

0x01 is 1.

so...

device.RenderState.ReferenceAlpha = 1;

AlphaFunction = Less, etc.

enable Alpha testing with AlphaTestEnable.

Quote:
z depth write on, z depth write on, source alpha test - render when 255 (opaque)
z depth write off, z depth test on, source alpha test - render when < 255

sortof...

z depth write on, source alpha test - render when >= 225
z depth write off, blending on, source alpha test - render when < 225

is about right :-)

225 is probably about right alpha test. Otherwise you won't get much solid shrubbery. :-)

So for pass 1:

No blending,

device.RenderState.AlphaTestEnable = true;
device.RenderState.AlphaBlendEnable = false;
device.RenderState.AlphaFunction = Compare.GreaterEqual;
device.RenderState.ReferenceAlpha = 225;

This will render the majority of the bush as solid, with depth being written to occlude other geometry.

pass 2:
also set the blend mode to pre-modulated alpha (help stop those black edgse on the grass)

device.RenderState.AlphaTestEnable = true;
device.RenderState.AlphaBlendEnable = true;

device.RenderState.SourceBlend = Blend.One;
device.RenderState.DestinationBlend = Blend.InvSourceAlpha;

device.RenderState.AlphaFunction = Compare.Less;
device.RenderState.ReferenceAlpha = 225;


This will draw transparent geometry at the edges that does not write to z, so will not get the errors you are currently seeing.

This topic is closed to new replies.

Advertisement