Skip to main content
GameDev.net gamedev.net
🔒 Locked

Z buffer weirdness

Started by TheUmpteenth Jun 26, 2007 at 3:01 PM 3 replies 800+ views
Original Post
TheUmpteenth
TheUmpteenth
I've just enabled AutoDepthStencilBuffer, as I've been trying to fix a problem with my heightmap. The problem is that the farthest part of my terrain is rendering over the closest part. seemed to me that the z-order was off, but when I enable any z functions (ZFUNC) I get holes in my terrain (or no terrain at all). also tried changing the CULLMODE to D3DCULL_CW, but I lose more geometry that way. I can really figure it out, I was wondering if it was something to do with raw file loaded terrain, or if there's something I'm missing. Just in case you wondered, I'm testing the Buffer Format's compatibility, and it's D3DFMT_D24X8.
jollyjeffers
jollyjeffers
What values are you using when constructing your projection matrix? Combinations of Znear and Zfar can cause this sort of artifact. Extreme ranges (e.g. trying to represent millions of units) or setting the near plane to be too close to the camera...

What sort of size (post-transform) is your geometry? What sort of values are you storing in the depth buffer?

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
TheUmpteenth
TheUmpteenth
thanks FTQR jollyjeffers

Best say this first, but all other questions are answered below

I don't really know what im putting in the depth buffer. I want to be representing the distance from the camera to the pixel (as you would guess)


D3DXMatrixPerspectiveFovLH(&m_Projection, D3DX_PI/4, 25/25, 2, 1000);


I guess that's 2 for Z-near and 1000 for Z-far

struct TEXTURED_VERTEX3D{	float x,y,z,u,v;};


64*64 verts per buffer, 9 buffers.

that would make one VB 128*128 in size (not sure what unit you would use, but imagine D3DXVECTOR3 (0,0,0) to D3DXVECTOR3 (128,128,128))

for easier understanding, ill include some of my Heightmap code, you'll only be able to tell the size from it tho.
//just so you know, its part of a loadRawFile() method// Here we load the .raw file into our pMapSection data array.	for (int x=0;x< Width;x++)	{		for (int y=0; y< Length;y++)		{			pMapSection[y*Width + x]=f_DataFile.get()/5;		}	}

LPDIRECT3DVERTEXBUFFER9 cMapSection::FillVertices(HWND WinHandle, LPDIRECT3DDEVICE9 pDxDevHandle){	TEXTURED_VERTEX3D* cv_Vertices;	LPDIRECT3DVERTEXBUFFER9 p_dx_VertexBuffer;	cv_Vertices=new TEXTURED_VERTEX3D[Width*Length];	for (int x=0;x< Width;x++)	{		for (int y=0; y< Length;y++)		{			cv_Vertices[y*Width + x].x = (float)(-x*StepSize);			cv_Vertices[y*Width + x].z = (float)(y*StepSize);			cv_Vertices[y*Width + x].y = (float)(Height(x,y));						if (x!=0)			{				cv_Vertices[y*Width + x].v = (float)(x/(Width-1.0f));			}else{				cv_Vertices[y*Width + x].v = 0;			}						if (y!=0)			{				cv_Vertices[y*Width + x].u = (float)(y/(Length-1.0f));			}else{				cv_Vertices[y*Width + x].u = 0;			}					}	}	if (FAILED(pDxDevHandle->CreateVertexBuffer(Width*Length*sizeof(TEXTURED_VERTEX3D), 0,		CUSTOM_FVF_TEXTURED, D3DPOOL_DEFAULT, &p_dx_VertexBuffer, NULL ) ) )	{		MessageBox(WinHandle,"Error while creating VertexBuffer",			"FATAL ERROR!",MB_OK|MB_ICONEXCLAMATION);	}	VOID* p_Vertices;	if (FAILED(p_dx_VertexBuffer->Lock(0, Width*Length*sizeof(TEXTURED_VERTEX3D), (void**)&p_Vertices, 0)))	{		MessageBox(WinHandle,"Error trying to lock",			"FATAL ERROR!",MB_OK|MB_ICONEXCLAMATION);	}else{		memcpy(p_Vertices, cv_Vertices, Width*Length*sizeof(TEXTURED_VERTEX3D));		p_dx_VertexBuffer->Unlock();	}	return p_dx_VertexBuffer;}
Namethatnobodyelsetook
Namethatnobodyelsetook
Z defaults to off. SetRenderState(D3DRS_ZENABLE, true) should enable it. You will also need to pass D3DCLEAR_ZBUFFER to your clear call, and give it a Z value to clear to, which is usually 1.0f.
TheUmpteenth
TheUmpteenth
the CLEAR_ZBUFFER call worked, along with ZFUNC, D3DCMP_LESS.

Thanks. (boy do I feel sheepish)

Topic Locked

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

Sign in to reply to this topic.