Best method to render particles in gl?

Started by
1 comment, last by Ranger_One 22 years, 10 months ago
Hi, I was just looking over some demo src for a simple particle engine in gl and was wondering if this is the most eff. method. Every time a particle is rendered, the code calls glPushMatrix(), then glPopMatrix() too restore the identity values. However, it would seem to me that you could simply reverse the calls, like this:
  
glRotate( .. pos vec ..);
glTranslate( .. pos vec .. );

// draw it here


glTranlaste ( .. neg vec .. );
glRotate ( .. neg vec .. );
  
Would this be faster or slower than the above method? or should I just test it and see... ? Thanks, Jason
Advertisement
well, you''d have to send the data over the BUS again... with pushing and popping you don''t pass any parameters (popping) and i guess it''s pretty much optimised in the drivers so it shouldn''t be to slow :o)

cya,
Phil


Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states
Visit Rarebyte! and no!, there are NO kangaroos in Austria (I got this question a few times over in the states ;) )
I found a much better method on http://nate.scuzzy.net/. Basically, you take the camera matrix, extract the "up" and "right" vectors from it, and then ue those to draw each particle, so say you have a particle at P, of size 2 * s. You draw it like this:

  Vector a( P + (up * s) + (right * s) );Vector b( P - (up * s) + (right * s) );Vector c( P - (up * s) - (right * s) );Vector d( P + (up * s) - (right * s) );// now render the quad a,b,c,d with the normal modelview matrix and everything  


You don''t need to change any matrices at all. It does require you to read the camera matrix, but you only do that once, and then you can render all 10,000 particles like that.

Technically, it''s not quite right, because all the particles will be on a plane, and not on a sphere around the camera, but I found that it''s really not noticable... unless you''ve got an unusually high field of view.

War Worlds - A 3D Real-Time Strategy game in development.

This topic is closed to new replies.

Advertisement