occluding back face

Started by
14 comments, last by steg 20 years, 11 months ago
Hi, When rendering my terrain engine in wireframe, you can see the back faces of the terrain, is this correct ? I''m sure you shouldn''t be able, do I need to create a normal for each face ? Kind regards, Steve As I get older, my mind becomes more cluttered.

If it isn't working, take a bath, have a think and try again...

Advertisement
I''ve noticed that no culling happens when rendering more than one row ? I''m using indexed buffers, maybe winding order is wrong or something ?

Any ideas ?

Steve



As I get older, my mind becomes more cluttered.

If it isn't working, take a bath, have a think and try again...

Hardware culling works on vertices order ClockWise or CounterClockWise.

I suppose hardware have a simple form of normal computation internally, since it's the order from which you take points change the side the normal is.

Use glCullMode in OpenGL.

Forgot to mention that in wireframe you don't render triangles but lines, so I think backface culling is automatically disabled. Not 100% sure.

-* So many things to do, so little time to spend. *-


[edited by - Ingenu on May 8, 2003 12:10:36 PM]
-* So many things to do, so little time to spend. *-
In wireframe you are still drawing triangles, or at least, you are still sending triangles to the GPU. The GPU will perform backface culling before they are rasterised (ie, filled, textured, or drawn using lines), so they will still be backface culled.
For some reason, they are still not culled ? I''m sure they are rendered clockwise. Here is my code that creates the quads :


  HRESULT CTerrain::CreateTerrainVertexBuffer(){	int indicesSize = (m_xDim+1) * (m_zDim+1);	m_pTestQuad = new TERRAINVERTEX[indicesSize];	int index = 0;	float x = 0, y = 0, z = 0;	for (int amount = 0; amount < m_zDim+1; amount++)	{		for(int i = 0; i < m_xDim+1; i++)		{			m_pTestQuad[i+index].x = x;			m_pTestQuad[i+index].y = y;			m_pTestQuad[i+index].z = z;			m_pTestQuad[i+index].DiffuseColor = RGB(i<<2,255,0);			y = rand() % 2 + amount;			x+=2;  // width of quad		}		x = 0;		z -= 2;    // depth of quad		y = 0;		index += m_xDim + 1;   // next quad	}	HRESULT r = m_pDevice->CreateVertexBuffer(sizeof(TERRAINVERTEX)*indicesSize,0,CUSTOM_ZENVERTEX,D3DPOOL_DEFAULT,&m_pVB,NULL);	if(FAILED(r))	{		return E_FAIL;	}	VOID* pVertices = 0;	r = m_pVB->Lock(0,0,(void**)&pVertices,0);	CopyMemory(pVertices,m_pTestQuad,indicesSize*sizeof(TERRAINVERTEX));	if(FAILED(r))	{		return E_FAIL;	}	m_pVB->Unlock();	return S_OK;}void CTerrain::CreateIndices(){	int index = 0;	int offset = 0;	m_pIndices = new WORD[m_xDim*m_zDim*6];   	// same as above, but looks neater.....	int x = m_xDim + 1;	for(int row=0; row<=m_zDim-1; row++)	{		for(int col=0; col < m_xDim; col++)		{			m_pIndices[index] = col + x + offset;     			m_pIndices[index+1] = col + offset;       			m_pIndices[index+2] = col + (x +1) + offset;    			m_pIndices[index+3] = col + 1 + offset;    			m_pIndices[index+4] = col + (x +1) + offset;    			m_pIndices[index+5] = col + offset;        			index += 6;		}		offset += m_xDim + 1;	}}  


This is driving me mad!

Anybody any more ideas ?

Thanks,
Steve



As I get older, my mind becomes more cluttered.

If it isn't working, take a bath, have a think and try again...

Why would you expect a wireframe to cull backfaces? I think it''s operating normally by not drawing faces at all.

Checkout some wireframe screen shots of other peoples work and I think you''ll notice they are ''see through''.

Cheers,
Will
------------------http://www.nentari.com
Thanks Will,

I will do that, maybe you are correct in what you are saying ? Although for example, I have seen say a cube rendered as wireframe but this is not ''see through'' ?

Regards,
Steve


As I get older, my mind becomes more cluttered.

If it isn't working, take a bath, have a think and try again...

Okay, I took a couple of screenshots of the app I''m working on to prove my point.

www.geocities.com/treething/cull_none.JPG
www.geocities.com/treething/cull_ccw.JPG

There you see it, backface culling in wireframe mode. Maybe its different in OGL, but I doubt it.

The reason that in most apps you dont see backface culling in wireframe mode is a design decision. Wireframe mode is usually used for clarity, and backface culling seems unintuitive.
Thanks,

Could you check out my images at : http://www.golfinabag.com

Sorry about the url name, I use to have a golf site, just registered another domain name today (3dgamecoding.co.uk) not active yet though!

Kind regards,
Steve

If it isn't working, take a bath, have a think and try again...

Those screenshots arent really conclusive. In wireframe mode you should indeed be able to see through the triangles. If you have two front-facing triangles, one behind the other, then you still see them both. If back-face culling is enabled through then you shouldnt see any back-facing triangles.

Try taking a look from underneath the terrain. The trouble with the screenshots is that the large majority of triangles seem to be front-facing. If youre underneath the terrain, looking upwards, then most of the triangles will be back-facing and shouldnt be visible if back-face culling is enabled.

HTH,
Chris

This topic is closed to new replies.

Advertisement