game written and profiled : time to optimize
OK here is where I am at and what I would like to do.
I have a vertical scrolling shooter up and running (using 3d graphics, but only allowing movement in XY plane)
. It was written with easy read-a-bility and functional testing in mind.
Thus it is highly UN-optimzied. I have profiled the code and know the bottle-necks. Thus I am ready
to start optimizing away. =]
One point where I need to heavily optimize (and I knew I would) is the particle engine. I specifically
designed it for testing the interface of my particle system class. The interface allows the user (in game)
to specify the complexity and shape of the particles. Each particle is created using the shape drawing
functions in DirectX. Therefore the user can select the particles to be Spheres, Boxes, Cylinders, etc....
And where appropriate the user can select the level of complexity that the mesh is created with (for those
who have never used the shape drawing functions, many of them let u specify how complex you wish the shape
to be: for example a Sphere with a low complexity doesnt look anything like a sphere, more like a stick,
but the poly count is low. and a sphere with a high complexity looks near perfect but has high poly count)
This also has the effect of each particle being created with model coordinates centered around the origin.
Thus I used a standard idiom of D3DMatrixTranslations and D3dMatrixRotations on each sphere before calling
mesh->drawSubset(). Everything functionally works and looks fantastic but the performance is obviously lacking
due to drawing each particle individually. On my 2.4 GHZ p4 with a GeForce 4ti 4400 it looks super, but I have
tested it on a 800 Mhz Geforce 2 Mx and the frame rate is steady at about 24 to 26 FPS. I would like to get the
800 Mhz puter running this game at a steady 60 FPS minimum.
The particle engine is built like follows (a very simple description):
1. The main high level ParticleSystemManager has only one instance created.
2. You can create as many ParticleSystems as you like from the ParticleSystemManager interface.
3. Each ParticleSystem can contain as many ParticleSubSystems as needed.
4. The ParticleSubSystems contain the actual Particle objects.
5. All the particles in a ParticleSubSystem must have the same shape, complexity and texture.
6. For ease in devoloping relative motion each ParticleSystem, ParticleSubSystem, and Particle
have their own Position, Velocity, etc...
7. To draw all the particles you have created you simply call ParticleSystemManager->Draw();
Here is my take on what I believe would be a good optimization:
First, I need to eliminate the individual drawing of each particle. Here is my idea for doing so:
I would like to 'merge' all the vertex buffers and index buffers from all the meshes into one vertex buffer
and one index buffer. This essentially means that I need a function which can merge 2 meshes into 1 mesh.
Then, each ParticleSubSystem would perform this optimization after manually transforming the vertice in
each vertex buffer (as all particles will now be draw in one shot, I can no longer transform each one to
its correct location using D3DMatrixTranslations and D3dMatrixRotations on the world matrix).
So here are my questions:
1. Does anyone know of an existing and tested method, algorithm, or function which can merge 2 meshes
into 1 mesh
2. Does my idea on optimization sound plausible? (possible questions in my mind are : Will the cost of Manually
transferring all those vertices be worse than what I save by drawing everything at once.)
And to be a little more specific , when I profiled the code, thew worst function time was the function which
Draws all the particles and it was also the function which got called the most. YUCK!
Any ideas or comments or verbal thrashings are very welcome.
[edited by - jplocster on November 7, 2002 3:37:23 PM]
DO NOT Draw them as full 3D objects....you only need 1 quad for each one. Look into billboards, and point sprites.
here''s a few links that might help.
http://www.codesampler.com/dx8src.htm
http://www.mvps.org/directx/articles/view_oriented_billboards.htm
http://www.mvps.org/directx/articles/vcache.htm
here''s a few links that might help.
http://www.codesampler.com/dx8src.htm
http://www.mvps.org/directx/articles/view_oriented_billboards.htm
http://www.mvps.org/directx/articles/vcache.htm
I know that is how most particle effects are done, and have written serveral systems that way. For what I am doing, The 3d-shapes work wonderful and look much much better. Forget the fact that those are used in a particle system, it really has nothing to do with the problem of merging two meshes together, anyway billboards simply wont work for what I am doing. Thanks for your suggestion , and the vertex cache link looks like a good alternative to merging the meshes together.
[edited by - jplocster on November 8, 2002 10:56:46 AM]
[edited by - jplocster on November 8, 2002 12:16:42 PM]
[edited by - jplocster on November 8, 2002 10:56:46 AM]
[edited by - jplocster on November 8, 2002 12:16:42 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement