• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# occluding back face

## Recommended Posts

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.

##### Share on other sites
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.

##### Share on other sites
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]

##### Share on other sites
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.

##### Share on other sites
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;	}}

Anybody any more ideas ?

Thanks,
Steve

As I get older, my mind becomes more cluttered.

##### Share on other sites
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

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
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

##### Share on other sites
I've included a link to the demo code for the terrain if you are interested ?

Camera controls are cursor keys, put num lock on to use keys 8 for up, 2 for down, 4 straif left, 6 straif right.

Same url : http://www.golfinabag.com

Kind regards,
Steve

As I get older, my mind becomes more cluttered.

[edited by - steg on May 9, 2003 7:08:10 AM]

##### Share on other sites
Thats looks fine to me.

##### Share on other sites
So, it worked ok ? It should be like that ?

Kind regards,
Steve

As I get older, my mind becomes more cluttered.

##### Share on other sites
yeah. basically, the triangles you see at the back are actually front-facing. ...All that rage, for nothing!

They are just masked by the triangles at the front when drawn with fill mode. In wireframe, all the renderer do is draw lines, and use the Zbuffer on the pixels of the line, not the triangle surface. to mask the polygon at the back in wireframe, you''d have to first render the terrain with totally black polygons, then render the wireframe on top of it with a glPolygonOffset(). And that''s if you have a black background.

If you want to cull the polygons at the back more efficiently, you''ll need more than backface culling. you''ll need occlusion culling.

Thanks oliii!

##### Share on other sites
actually im not so sure its all ok...
when you enable wire frame rendering, the scene is still rendered per triangle, and of each triangle, each edge is draw as a line. if you would enable backfaceculling, all backfaceculled tris would fall away and thus you should not see them.
i think the problem is in your triangle strips: try rendering your triangles shaded: probably your terrain shows a checkered pattern now: it looks like there is no backfaceculling cos every other tri is drawn, witch doesnt show up cos each edge is shared by two tris.. at least thats what has happended to me, using dx btw.
if this is the case, to overcome this, you should flip the normals of every other triangle strip.

• ### Forum Statistics

• Total Topics
627701
• Total Posts
2978705

• 21
• 14
• 12
• 10
• 12