Sign in to follow this  

Backface culling, depth buffer

Recommended Posts

Hi! I wrote a litte test prg, rotate 30000 triangles with backface culling. I choose the camera location to see all the tris. One sec I see all the tris, in next sec I do not see any tris. But I do not see any performance gain. If I do not see any tris, the fps is not greater at all. How can it be? ------------------------- The same test prg: I draw a big triangle close to my camera location to hide all the 30000 tris behind. I draw big triangle first, then the 30000 tris. I thought that if I see only the big triangle, the fps is greater, because GPU does not have to render the 30000 tris, because of depth buffer. If I move the camera left-right, I see the 30000 tris and then not. But FPS is the same. How can it be? Thanks

Share this post

Link to post
Share on other sites
You could be limited by the CPU-to-GPU bottleneck. If the actual rendering takes an insignificant amount of time but sending all those triangles through DirectX or OpenGL to the graphics card takes a large amount of time, then speeding up rendering would have little or no effect upon the frame rate.

Maybe you should give us some more specifics. What graphics card? OpenGL or DirectX? How are you sending the triangles to the graphics card? Maybe a code snipit.

Also, I remember hearing that fragments still have their pixel shader run even if they are behind the previous pixel. This is because the pixel shader can change the depth of the fragment. Can anyone else confirm?

Share this post

Link to post
Share on other sites
Thanks for the answer!

This is a part of my code.
I understand, that it is probably limited by the CPU-to-GPU bottleneck.
If I use display lists, it will not be faster with backface-culling also.

I ran a sample prg, (found on this Forum) that shows: on my hardware display lists work better than Vertex Arrays, and ARBs.

Please tell me, what tools should I use to identify theese kind of bottlenecks?
How to analyze my program for bottlenecks? Profilers can tell this? What profiler? Is VC++2008 good to generate prgs that can use my GPU well?
I use winXP, ATI Radeon 9600 AGP 256MB, 3Ghz Intel processor, 1GB RAM, Visual c++ 2008 Express, Nehe sample prgs.

How should I modify this program to GET greater FPS with backface-culling?

void Draw( float timeInSecDelta,float timeInSec )

managerCamera.updateEyePos( timeInSecDelta,NULL );

glBindTexture( GL_TEXTURE_2D,imageTexture.texID );
DrawTriTestOrder( timeInSec );
glCallList( listNumberFelulet );
glBindTexture( GL_TEXTURE_2D,0 );


void DrawTriTestOrder( float timeInSec )
glColor3f( 1.0f,0.0f,0.0f );

DrawTri( 1,0,0,1 );

long now = (long)(timeInSec*20000);
float angle = (float)cos( (now%20000)/20000.0f*2*PI );
DrawTri( 2,0,0,angle );

glColor3f( 0.0f,1.0f,0.0f );
for ( int ic=0; ic<700; ic++ )
for ( int jc=0; jc<100; jc++ )
DrawTri( 100+ic,0,jc,angle );

void DrawTri( int px,int py,int pz,float angle )

glTexCoord2s( (short)0,(short)0 );
glVertex3f( px,py,pz );
glTexCoord2s( (short)1,(short)0 );
glVertex3f( px+0.1f,py,pz+angle );
glTexCoord2s( (short)0,(short)1 );
glVertex3f( px,py+1.0f,pz );


void UpdateAndDraw( double timeInSec )
float timeInSecDelta = Update( timeInSec );
Draw( timeInSecDelta,timeInSec );

Share this post

Link to post
Share on other sites
You're drawing one triangle at a time, which is where all your time is being spent. If you were drawing 30,000 triangles with a single draw call, you might see something different.

But you're still missing the big picture. Culling is done before any per-pixel operations, so if your pixel shader is complex and you removed the triangles, you're saving a lot of time. If your pixel shader does nothing but return the color, you may not see the benefits.

As for depth buffering, yes, it happens after the pixel shader, but depth buffering can still save large amounts of calculations if you utilize it using a z pre-pass or something similar. It's not always "Do 100% of calculations, then draw", it can be used to save on lighting calculations.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this