Skip to main content
GameDev.net gamedev.net
🔒 Locked

A challenge! Optimize my particle system demo

Started by WitchLord Jun 29, 2000 at 2:20 PM 62 replies 3.3k views
Original Post
WitchLord
WitchLord
As some of you no doubt already know, I''m currently writing a tutorial on particle systems. I have already written a demo that I believe is pretty efficient, but I''m curious to see if it can be even more efficient so now I issue a challenge to you all: Optimize my demo so that it gets faster than it already is. Of course you also need to tell me how you did it, if you manage to increase the speed. This is not a competition and you will not receive any prices by doing this. However if you should manage to find an optimization that increases the framerate sufficiently and if it doesn''t involve writing unreadable code I will incorporate it into my demo and acknowledge you in my tutorial. I will file away all other optimizations in my personal knowledge base to bring up when I need them again . You can find the demo and source code at www.witchlord.com/tutorials/particles.asp - WitchLord
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
Jeranon
Jeranon
I''m not good enough to optimize it yet but here''s some stats...
At the default window size, and PC doing nothing else,
On my P2-400, 256MB RAM with Matrox G400 : 50-60FPS
On my P3-550, 128MB RAM with nVidia TNT : 14FPS +- 0.5 FPS
JeranonGame maker wannabe.
Shinkage
Shinkage
Heh, I''ll have to file that under my "innovative ways to ask for help category."
SHilbert
SHilbert
Aha! I found a way to change the FPS without even changing the code!!! --- change the size of the particle texture. I resized it down to 32x32 and the framerate shot up by over 60 (from 22 to 85) on my computer.
I can see it now... "And thanks to SHilbert for recommending small textures."

lntakitopi@aol.com / http://www.geocities.com/guanajam

Edited by - SHilbert on June 30, 2000 4:36:35 PM
WitchLord
WitchLord
(Update) I'm sorry SHilbert but your name will not make it into the tutorial after all. I rendered your optimization obselete by turning on mipmapping. I now get 160 fps with the original 128x128 texture. This is the call that should be made in CParticleApp::Initialize():

m_pD3DDev->SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTFP_POINT);

However, I still think there is room for optimizations in the code and it is those that I'm the most interested in.

- WitchLord

Edited by - WitchLord on June 30, 2000 6:09:33 PM
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
WitchLord
WitchLord
Hmm, I got an idea for an optimization if anyone care to try it out for me. Maybe if the particles are rendered as triangle strips it will be faster. You''ll have to connect the particles with degenerate triangles though so that you can draw them all in one call to Draw(Indexed)PrimitiveVB().

I could try this out myself, but I would rather spend my time writing the tutorial instead so I can finish it sometime.

- WitchLord
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
WitchLord
WitchLord
Damn you, Microsoft

I turned off the mouse cursor shadow in Win2000 and now I get a framerate of 250 fps.

(Oh, and SHilbert don't forget to re-read my post above about your optimization as I changed it)

- WitchLord

Edited by - WitchLord on June 30, 2000 6:25:11 PM
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
MENTAL
MENTAL
DX? NOOOOOOOOOOO! Do one in OpenGL so I can optimise the hell out of it (you might have gathered i like opengl). An easy way to get it going faster is to change the resolution (i have no idea what you''re using at the moment - i have 3 d/ls going at the moment ).

Make sure you have full hardware acceleration enabled too - when i was trying out DX before converting to GL, most of my demos ran at about 20fps - then i turned on hw acceleration... BOOM!

are you running it in full screen mode? change 24bit to 16bit if needed, use vertex pools (if required), ummm... well, i''m out.

MENTAL

PS: it''s funny, because a while ago i posted a topic with exactly the same title, but it was about calcutating vectors over a period of time. increased the frame rate by about 20% due to the replies .
Moe
Moe
I suppose you saw that tutorial at gamasutra (it was pretty good, I thougth). You could wait until you have 500-1000 dead particles (already faded and not visible), then destroy them. It saves time instead of killing several particles per frame.

celeron 466, 8mb vid card, 128mb ram: avg. 10fps (but pretty cool looking)

Shrapnel Games
WitchLord
WitchLord
Actually no particles are ever destroyed in my demo.

I did read that tutorial. It''s pretty good, but it doesn''t help me much with my tutorial as I''m only making a simple particle system where as that tutorial focuses on advanced particle systems.

I have updated the demo on my site, so if you try it once more you will hopefully notice a substantial increase of speed.

- WitchLord
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
Julio
Julio
hey Mental, too bad glDrawPixels sucks major ass. (sorry for profanity) I'm sure you already know this. just making sure.

JoeMont001@aol.com

Edited by - Julio on July 1, 2000 6:05:04 PM
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
WitchLord
WitchLord
MENTAL: Your suggestions doesn''t count as optimizations

But if you want you may try to make the code faster by using OpenGL. Remember, it must do the exact same thing otherwise we can''t compare them.

- WitchLord
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
Jrz
Jrz
Hi REAL WitchLord
I found a couple of things:

CParticleApp::UpdateScene
Instead of calling m_SceneTimer.GetFrameTime() 6 times, store the value in a float, and do the same with m_SceneTimer.GetDeltaTime()

CParticleApp::RenderScene
You don''t need to clear the Zbuffer, you don''t use one

CParticleSystem::Update
line 76:
if you do

if( pThis->Pos.y > m_fRadius )
pThis->Vel.y -= m_fGravity*fDeltaTime;
else if( pThis->Pos.y < m_fRadius )

it saves 1 if if I''m correct. (diff is ''else'')

line 136:
you could change
float fAlpha = 2 * 3.141592f * rand()/RAND_MAX;
into
#define MYALPHA 2 * 3.141592f / RAND_MAX
float fAlpha = MYALPHA * rand();
I''m not sure if this helps...

and the lines below that, you can cache cos(fBeta)

Also, you should use vertexarrays for the particles as they all have the same shape, and translate the array if you draw them.


My name is Joris Verschoor

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.