Skip to main content
gamedev.net
🔒 Locked

Problems with Z-Buffer

Started by kandemor Nov 19, 2004 at 4:08 AM 9 replies 1.5k views
Original Post
kandemor
kandemor
Hello, I think I have problems with Z-Buffer. In the image below I render a skydome and geometry: In other parts of the map I alse have textures that disappear. This is the code I use to create the device:


if( FAILED( g_pD3D->CheckDeviceType( D3DADAPTER_DEFAULT,
                                         D3DDEVTYPE_HAL,
                                         D3DFMT_X8R8G8B8,
                                         D3DFMT_X8R8G8B8,
                                         FALSE ) ) )
    {
        return;
    }

    if( FAILED( g_pD3D->CheckDeviceFormat( D3DADAPTER_DEFAULT,
                                           D3DDEVTYPE_HAL,
                                           D3DFMT_X8R8G8B8,
                                           D3DUSAGE_DEPTHSTENCIL,
                                           D3DRTYPE_SURFACE,
                                           D3DFMT_D16 ) ) )
    {
        return;
    }

    D3DPRESENT_PARAMETERS d3dpp;
    memset(&d3dpp, 0, sizeof(d3dpp));

    d3dpp.Windowed               = TRUE;
    d3dpp.EnableAutoDepthStencil = TRUE;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
    d3dpp.SwapEffect             = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferWidth        = width;
    d3dpp.BackBufferHeight       = height;
    d3dpp.BackBufferFormat       = D3DFMT_X8R8G8B8;
    d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;

	if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT,
                                          D3DDEVTYPE_HAL, 
                                          hwnd,
                                          dwBehaviorFlags, 
                                          d3dpp,
                                          &g_pd3dDevice ) ) )
	{
	     return;
	}


What I'm doing wrong? I use a znear value of 1 and zfar value of 3000. ( with opengl I don't have problems with this values). Thank you very much. VinCenT
sirob
sirob
are you disabling ZWrite before drawing the skybox?

If you're drawing it first, you can also disable the zBuffer completely.
Sirob Yes.» - status: Work-O-Rama.
kandemor
kandemor
Yes, I have disabled it.
kandemor
kandemor
sorry, I changed the code in the right place and now the skydome is right. Thank you very much!

Any idea for the textures that disappear?



Thank you!

VinCenT.
lack o comments
lack o comments
Looks like z-fighting to me. I could be wrong though.

If it is z-fighting, it's the result of rendering coplanar polygons. You need to set the "D3DRS_DEPTHBIAS" render state before drawing them to make one appear in fron of the other, or just make sure the polygons aren't coplanar.
Moe
Moe
...or you could just try to use a 32 bit Z buffer. It looks to me like z-fighting because of a lack of precision in the Depth buffer. Give 32 bits a shot.

(Feel free not to flame me if I am wrong either).
kandemor
kandemor
Hello,

I also think that is z-fighting, because there aren't coplanar polygons. The problem is that I can't set a 32bit Z buffer. I don't understand why. I have a nVidia GeForce 4 Ti 4400.

If I use the following code:

     d3dpp.Windowed               = TRUE;    d3dpp.EnableAutoDepthStencil = TRUE;    d3dpp.AutoDepthStencilFormat = D3DFMT_D32;    d3dpp.SwapEffect             = D3DSWAPEFFECT_DISCARD;    d3dpp.BackBufferWidth        = width;    d3dpp.BackBufferHeight       = height;    d3dpp.BackBufferFormat       = D3DFMT_X8R8G8B8;    d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;    if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT,                                      D3DDEVTYPE_HAL,                                       hwnd,                                      dwBehaviorFlags,                                       d3dpp,                                      &g_pd3dDevice ) ) )    {	return;    }


The call don't fail, but the device is not created ( = NULL ).

What can I do?

Thank you very much.
lack o comments
lack o comments
Quote:

Try setting a 24-bit depth buffer.

Yeah, there are still a lot of cards that don't support anything but 16-bit z-buffers, and maybe 24-bit.


Quote:

Also play with the near and far planes of your projection matrix.. set the near plane as FAR away as possible to maximize z-buffer resolution.

If the z-fighting isn't the result of coplanar polygons, then it is the result of uneven distribution of data on the z-buffer. If changing the n/f planes doesn't work, try changing your sort algorithm, to create more "overdraw". i.e. Draw polygons from closest to farthest. NOTE: this may cause problems with transparent polygons.
kandemor
kandemor
Oh perfect!

With 24 bits looks great! Thank you very much!

VinCenT.
Pipo DeClown
Pipo DeClown
Quote:
Original post by lack o comments
Looks like z-fighting to me. I could be wrong though.

If it is z-fighting, it's the result of rendering coplanar polygons. You need to set the "D3DRS_DEPTHBIAS" render state before drawing them to make one appear in fron of the other, or just make sure the polygons aren't coplanar.


Listen to him!!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.