Jump to content
  • Advertisement
Sign in to follow this  
Andregolas

Z-Buffer Configuration - Managed DX

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

Hi @ all, I'm having trouble with the Z-Buffer, ehatever I do it doesn't work porperly :( Here's a bit of my code:
public void InitDevices()
    {
        /*** Direct3D ***/
        //PresentParameters
        pp.BackBufferFormat = Microsoft.DirectX.Direct3D.Manager.Adapters[0].CurrentDisplayMode.Format;
        pp.BackBufferCount = 1;
        pp.BackBufferWidth = Settings.Width;
        pp.BackBufferHeight = Settings.Height;

        pp.SwapEffect = SwapEffect.Discard;

        //Z-Buffer
        pp.EnableAutoDepthStencil = true;
        pp.AutoDepthStencilFormat = DepthFormat.D24S8;

        //Vertical - Sync
        pp.PresentationInterval = PresentInterval.Immediate;
        
        //AntiAliasing
        (...)
        
        //Device
        (...)

        //Z-Buffer
        D3D_Device.RenderState.ZBufferEnable = true;
        D3D_Device.RenderState.ZBufferWriteEnable = true;

        //Anti Aliasing
        D3D_Device.RenderState.MultiSampleAntiAlias = true;
}
I hope you can tell me if I have to add or delete something to get the Buffer working?

Share this post


Link to post
Share on other sites
Advertisement
A) How do you know it doesn't work?

B) What are the near and far planes set to in the Projection matrix creation?

Share this post


Link to post
Share on other sites
Thx for your answer,

A) If I deactiate culling, objects aren't drawed properly, some Vertices in the back are in the front of those in the front etc. If I activate culling (CounterClockwise) most objects are drawn properly, but some objects in front of others are in behind them and some objects are always in the front.

B)Code:

D3D_Device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, 1.0f, 0.0f, 250.0f);


I hope that will help.

Share this post


Link to post
Share on other sites
What Sirob was probably already getting at, your near clipping plane should be at a depth > 0. Setting it a small value like 0.1 will most likely fix the issues you're currently seeing. For more information about the zbuffer check out this page, it's worth a read.

Share this post


Link to post
Share on other sites
More specifically (and for future readers), a near-Z value of 0.0f causes a divide by 0, which causes all z-values to become invalid values. After that, whatever depth a fragment had is lost. Sounds like changing the near-Z to anything other than 0 (I'd go for something over 0.1f) should fix it right up.

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!