PDA

View Full Version : billboards performance problems



hazelwood
11-06-2005, 07:15 AM
I'm looking for techniques to optimize the rendering of my billboards. I have a few thousand trees on a heightmap (the engine is 3D but fixed at an isometric angle and a very low FOV; the trees are sorted by depth for alpha-blending).

Here's my routine for drawing an object:

glPushMatrix();
glTranslatef(x,y,z);
glRotatef(-camera->pitch,0.0f,1.0f,0.0f); /* anti-tilt on y-axis */
glRotatef(-camera->yaw, 1.0f,0.0f,0.0f); /* anti-tilt on x-axis */
glScalef(sx,sy,0.0f);
glBegin(GL_TRIANGLE_FAN);
glTexCoord2f(0.0f,0.0f);
glVertex2f(0.0f,1.0f);
glTexCoord2f(1.0f,0.0f);
glVertex2f(1.0f,1.0f);
glTexCoord2f(1.0f,1.0f);
glVertex2f(1.0f,0.0f);
glTexCoord2f(0.0f,1.0f);
glVertex2f(0.0f,0.0f);
glEnd();
glPopMatrix();

So the first thing I did was stuffing the billboard graphics into as few textures as possible. This seemed to help a bit.
The next thing I tried was replacing the glBegin/glEnd part with an vertex array (I just learned how to do that)

glInterleavedArrays(GL_T2F_V3F,0,vb);
glDrawArrays(GL_TRIANGLE_FAN,0,4);

Though that turned out to be actually slower than the glBegin. Needless to say I'm not so proficient in OpenGL and now I'm stumped. How could I possibly speed this up?

hazelwood
11-06-2005, 09:24 AM
Also I wanted to state that most of the billboards are kinda small, say the sprites for vegetation such as grass patches and bushes are not more than 32x32 pixels in size.
So I would say it is not a fillrate problem but more the overhead of setting up every object. I see in modern games like Battlefield 2 there's a hell of a lot of grass on the terrain and in that game a patch of grass is even more complex geometry not just a simple sprite.

By the way I already do clip the objects against the screen but even if you zoom in on the terrain there's still a few hundred objects in total.

Hylke Donker
11-06-2005, 10:33 AM
For things such as grass, you could create a small 3D texture, and then repeat it alot.
This way you don't have to render every single blade of grass.
Hylke

hazelwood
11-06-2005, 10:59 PM
I will try that. Though I'd be interested in any other options considering that my billboards are used not only for vegetation but also for other (animated) game objects with more complex sprites.

I'm reading up on how to use point sprites but seeing it's not available on older cards I still should have a better fallback.

Hylke Donker
11-07-2005, 05:57 AM
if glRotate* and glScale* don't have to be called(in exampe, when the variable camera->pitch, camera->yaw are 0.0), then don't call them, because these things require some calculations that can seriously slow things down.