Advertisement

Terrain engine test

Started by February 10, 2002 07:47 PM
12 comments, last by Eber Kain 23 years ago
Ive been working on a terrain engine, Now that its all working, I want to see what I can do to optimize it. Right now Im useing Triangle strips to draw 2 polys at a time, so I can bind a different texture to every tile that is drawn. I get these rates 1200 polys 115 fps 4800 polys 45 fps 10800 polys 23 fps Keep in mind that I have a 550 mhz system with a VooDoo 3 card. Do you think these rates sound reasonable? If some of you would download it to see what kinds of rates you get it would help me. use the arrows to move around, pgup and pgdown zoom in/out home.earthlink.net/~eberkain/files/tertest.zip if you get an error about unknown dll''s download this to get them home.earthlink.net/~eberkain/files/devil.zip
www.EberKain.comThere it is, Television, Look Listen Kneel Pray.

Hi,

''Fraid I''m at work so I can''t download your demo, but your numbers sound in the ball park. I get a very similar set of poly counts for my terrain engine, and I''m using ROAM (heavy on the CPU) with immediate mode rendering.

Are you sorting your tiles by texture type? A useful optimisation is to minimise the number of texture binds by sorting the triangles by terrain type (ie use a bucket sort , then render all the tris of the same terrain type in order, minimising texture binds).

Cheers

Keef



-----------------------
glDisable(WORK);
glEnable(GL_CODING);
-----------------------Current Project: The Chromatic Game Engine
Advertisement
I do want to do that, but the system im useing to do the textures has prevented me from comeing up with a fast way of doing that. As it is it will render all the polys on the screen from left to right then bottom to top. Unless the last texture was the same as the one thats currently needed it will rebind them every 2 polys.
www.EberKain.comThere it is, Television, Look Listen Kneel Pray.

That will seriously slow your fame rate down!

What is your ''system'' for the textures? It should be possible to use a bucket sort to quickly sort your polygons into the correct draw order.

Keef

-----------------------
glDisable(WORK);
glEnable(GL_CODING);
-----------------------Current Project: The Chromatic Game Engine
Those numbers seem rather low. My terrain renderer does around 20,000 triangles per frame at 200fps. That includes mouse & keyboard input, collision detection, etc, and hasnt even been optimized yet.

With your engine I only get 150fps at 1200 trianlges. Its definately far lower than it should be.
-----------------------"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else's drivers, I assume it is their fault" - John Carmack
P4-2ghz geforce3 Ti 500

I get 39 fps zoomed all the way out. Thats 10440 polys IIRC. Thats pretty slow for what its doing.

Are you calling glVertex and glTexCoord for each tristrip? If so thats a sure way to get poor performance. If so, figure out a way to stuff the verts and texture coords into vertex arrays and render them using calls to glDrawElements. Might wanna check out CVA''s for more performance as well. Not sure if voodoo3''s support them.

Also share vertices as much as possible. Given that it looks like you''ve randomly textured the terrian, im assuming your not. For this low of a polycount im not sure it will make a huge difference here. Try to avoid doing the random texture thing and generate a map that might be more like what youre going to have in the end and then share verts that have the same texture coord values. (to do this you have to use texture coords with values greater than 1.0 and resort to some type of planar texture mapping.)

When using vertex arrays, keep the index array type set to short, this will limit the number of vertices in the vertex array to 65536 but will also save on memory bandwith when uploading the index list to the card. (Or so I''ve been told)

If you plan on growing the size of your maps, look into using something like a quad tree to partition your map out so that you can cull out polygons that arent in the frustum. No point in drawing what you cant see =)

Just as Keef said, sort by texture wherever possible.

I would expect that properly designed to take advantage of the above techniques that reaching 300+ fps on a system like mine would be possible, and likewise you would see an nice increase as well.

Hope this helps.

-=[ Megahertz ]=-
-=[Megahertz]=-
Advertisement
thanks for the input guys.

I do perform culling, only the polys on the screen are drawn.

My draw code is the problem, this function draws a poly, and it gets called one time for every 2 polys. so if your count was 10880 its calling this 5440 times per frame, thats where my problem is.

void draws::TerrainTri(short x, short y) {	//check for valid values	if((x >= 0 && x < TER_MAP_SIZE) && (y >= 0 && y < TER_MAP_SIZE ) ) {		terrainpolys+=2;		game.BindTerTex(x,y);		glBegin(GL_TRIANGLE_STRIP);			glTexCoord2i(0,1); glVertex3f(x,y+1,*ter.GetHeight(x,y+1));			glTexCoord2i(0,0); glVertex3f(x,y,*ter.GetHeight(x,y));			glTexCoord2i(1,1); glVertex3f(x+1,y+1,*ter.GetHeight(x+1,y+1));			glTexCoord2i(1,0); glVertex3f(x+1,y,*ter.GetHeight(x+1,y));   		glEnd();	}}  


The call to game.BindTerTex binds a new texture unless the current one is good for this poly too, I have it set up to draw triangle strips as wide as the screen, but theres no way to do my texturing like that. So im going to have to do it with vertex arrays.

the map that comes up with the program is purely random. I havent put any work into the generator yet. And ive not decided on a file format for terrain yet either.

As for how im doing my textures, its based on the vertices, each vert has an index number associated with it that references a texture, and I use a 4d array to figure out what texture to bind to what poly.

glBindTexture(GL_TEXTURE_2D, texture[*a][*b][*c][*d]);

Its set up so that ANY texture will work with it.

it you consider a maximum of 10 different textures and 4 vertices per poly, that is a whole hell of alot of combinations. I dont know how I could sort through them and make it faster than it is.

I was thinking about looping through all the polys one time, and building an index list based on texture, then I could loop through all the polys and draw only the ones with the current index and increment the index every time, thats still going to result in alot of wasted looping.

right now the map size is defined as 200x200, It will probably be from 500x500 to 1000x1000 when i finish the game. It depends on how the in game objects scale.

Edited by - Eber Kain on February 10, 2002 12:35:21 AM
www.EberKain.comThere it is, Television, Look Listen Kneel Pray.

You are almost there with the looping idea for your textures. What you could do is this:

Set up a linked list of polys

Set up an array of these linked lists, with an element of the array for each different texture index.

Loop through your polys. Add each poly to the end of the linked list that corresponds to the correct texture type.

Loop through the array of linked lists. For each array element
a) bind the texture
b) draw all the polys in the list
c) reset the list.

This all happens in linear time, so you can achieve this at the cost of one extra pass through your polys.

(this is a bucket sort algorithm btw)

Keef





-----------------------
glDisable(WORK);
glEnable(GL_CODING);
-----------------------Current Project: The Chromatic Game Engine
P4 2Ghz Geforce 3 - 39fps???

Someone else that tried it on an Athlon 1800 Geforce 3 got 312fps

perhaps you should check your drivers?
www.EberKain.comThere it is, Television, Look Listen Kneel Pray.
Hrmm, i ran it again, zoomed all the way out and got 150fps or so. Im on win98 with the latest Detonator drivers from nVidia. Which really sux cause the 12.41 drivers are faster for win98 than their latest drivers. Unfortunately the 12.41 ones dont work with GF3.


-=[ Megahertz ]=-
-=[Megahertz]=-

This topic is closed to new replies.

Advertisement