Archived

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

Triangles, how many is too many?

This topic is 6341 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hey there, I''ve hacked up a very simple terrain loading program in OpenGL. It just takes a 257x257 grid and forces triangles onto the points and shades the triangles according to the height of each of the 3 vertices. Okay, so I get like 3.5 FPS here, and I am running with about 132,098 triangles (yeah, 132K). So, I take it that I am getting bad performance because I am outputting so many triangles, or is it because I am not outputting the triangles in a very friendly manney (I just run through the points, and draw triangles, 2 loops, nothing fancy). I bet I could get it to like 6 FPS with just better coding, but is it mostly due to the enormous amount of triangles? PS - How many triangles are displayed in an average frame in popular games now? Is there a way to see this? Thanks!

Share on other sites
Are you transforming and rendering all the triangles in the world, or just the ones in the view frustrum?

Domini
Rastagon 2 Engine

Share on other sites
Your numbers suggest a setup rate of ~460k triangles per second ( 132ktpf * 3.5fps ). This may not be the answer you are looking for but here is some data that might interest you. I can render 129x129 grid heightfields w/o textures or lights ( ie. testing my LOD setup approach ) and I can get about 9.5 million triangles per second at 640x480 @ 32BPP 60HZ ( w/o VSYNC ) on a PIII 666 and a GeForce 256 SDR running DirectX 7 on Win98se. That equates to ~150k triangles / frame at 60 fps. I have a few suggestions that could vastly improve your performance.

1) Use vertex buffers.
2) Use tri strips if possible. ( Best throughput )
3) Minimize number of API calls
4) Optimize for the HWs vertex cache.

Best of luck,
himh

Share on other sites
Neat, thanks. I''m gonna try some more stuff tonight, I think that I just did some really hackish coding... Seems like I should get better FPS even though 130k is a lot of triangles. I am currently just doing:

// Render the map as triangles, shaded based on height.	void renderTriangles()	{		int numTriangles = 0;		glColor3f(1.0, 1.0, 1.0);				int x = 0, z = 0;		while(z < TERRAIN_HEIGHT)		{			for(x = 0; x < TERRAIN_WIDTH; x++)			{				glBegin(GL_TRIANGLES);				float temp = (float) heightMap[z][x] / 255.0;				glColor3f(temp + 0.2, temp + 0.2, temp + 0.2);								glVertex3f(MAP_SCALE * x, HEIGHT_SCALE * heightMap[z][x], MAP_SCALE * z);				temp = (float) heightMap[z+1][x] / 255.0;				glColor3f(temp + 0.2, temp + 0.2, temp + 0.2);								glVertex3f(MAP_SCALE * x, HEIGHT_SCALE * heightMap[z+1][x], MAP_SCALE * (z+1));								temp = (float) heightMap[z][x+1] / 255.0;				glColor3f(temp + 0.2, temp + 0.2, temp + 0.2);								glVertex3f(MAP_SCALE * (x+1), HEIGHT_SCALE * heightMap[z][x+1], MAP_SCALE * z);				glEnd();				numTriangles++;				glBegin(GL_TRIANGLES);				temp = (float) heightMap[z][x+1] / 255.0;				glColor3f(temp + 0.2, temp + 0.2, temp + 0.2);								glVertex3f(MAP_SCALE * (x+1), HEIGHT_SCALE * heightMap[z][x+1], MAP_SCALE * z);				temp = (float) heightMap[z+1][x] / 255.0;				glColor3f(temp + 0.2, temp + 0.2, temp + 0.2);								glVertex3f(MAP_SCALE * x, HEIGHT_SCALE * heightMap[z+1][x], MAP_SCALE * (z+1));				temp = (float) heightMap[z+1][x+1] / 255.0;				glColor3f(temp + 0.2, temp + 0.2, temp + 0.2);								glVertex3f(MAP_SCALE * (x+1), HEIGHT_SCALE * heightMap[z+1][x+1], MAP_SCALE * (z+1));				glEnd();				numTriangles++;			}			z++;		}		cout << endl;		cout << "Number of Triangles: " << numTriangles;	}

Share on other sites
OH! And before calling say, t.renderTriangles(), I was calling camera.use() which I defined as the following:

	// Use this Eye for viewing.	void use()	{		glRotatef(-pitch, 1.0, 0.0, 0.0);		glRotatef(heading + 180, 0.0, 1.0, 0.0);		glTranslatef(-x, -y, -z);				reportEye();	}

That is done with no culling at all, and I suppose it would end up transformind all 130K triangles... Thanks guys, I really appreciate the help. Any more pointers would be gr8!

Share on other sites
"PS - How many triangles are displayed in an average frame in popular games now? Is there a way to see this?"

quake3/UT do about 10000 a frame

hints
cull triangles from your scene (quadtree or octree)
- speedup of 2-10x
use tri strips
- speedup of 2x

u prolly want to precalulate all this beforehand
(MAP_SCALE * (x+1), HEIGHT_SCALE * heightMap[z][x+1], MAP_SCALE * z);
-speedup bugger all

http://members.xoom.com/myBollux

• 28
• 15
• 23
• 10
• 19