Not logged in, Join Here! or Log In Below:  
News Articles Search    

 Home / 3D Theory & Graphics / Rendering particles fast in opengl Account Manager
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

March 19, 2005, 09:31 PM

I've run into a problem with a project Im working on. here are the specs in a nutshell.

I need to be able to render 50000+ particles in real time, the more the merrier but 50000 is plenty if I can get that to work.

So I've been trying to find a fast way to do this, rendering a particle as a textured quad or a textured triangle is just too slow, basically that will involve 50000 glbegin and end calls.. which is not a feasible amount.

So the method I originally came up with was to represent every particle as a spot in a vertex array, updating its position in that array and then with one call to glDrawArrays I can have all my particles rendered at once. Using this method I was able to get more than 115000 particles at > 80 fps, which was more than enough, and I thought I had a solution.

but now that I have the ability to move the camera around, I see that my billboarding matrix billboards the entire vertex array, so you cant rotate around a particle cloud, it will always be "facing" you, and therefore all the particles will always be the same distance from the camera... so this doesnt look like its the correct way to handle particles either.

Has anyone run into problems like this? and know a nice way to overcome it? I've been fooling around with it for a few days straight now, and I need to get it working in a couple weeks, so I'm now seeking help :D

Thanks to anyone who can help even a bit.


March 19, 2005, 10:29 PM

Use a vertex shader to orient the billboards.

You might also look into the point sprite extension, though I understand it's fairly limited in features.


March 19, 2005, 10:53 PM

I was affraid it would come down to vertex shaders. The computer that is going to be running this demo isnt terribly fast and needs to use most of that gpu power rendering the actual triangles...

Im experimenting now with the "center +- up +- right" calculations for billboarding without a matrix, but it seems I cant get the right up and right vectors out of the glMatrix or something, it should be:

double mat[16];
glGetDoublev(GL_MODELVIEW, mat);

then up would be mat[0], [4], [8], and right would be mat[1], [5], [9]... but these arent giving me normalized vectors... (Im not doing any scaling).


March 19, 2005, 11:38 PM

you could use a dynamic vertex array and update each particle in the array every frame. When you update the position of the particle, you can also update it's orientation. It is usually faster to rewrite whole array which is in AGP/VRAM than just update it partly. Using a fresh buffer/lock with discard avoids the gpu to stall.



March 20, 2005, 12:25 AM

something like this. in the real world use the particles propably need more properties than just a position.

  2. std::vector<Particle> particles; //list of particles
  4. float3 hx= invertedView.GetX()*(size/2.0f);
  5. float3 hy= invertedView.GetY()*(size/2.0f);
  7. Vertex* vertices = locked vertex array;
  9. for (size_t i=0; i< particles.size(); ++i) {
  10.    vertices[i*4+0].Position=particles[i].Position-hx-hy;
  11.    vertices[i*4+1].position=particles[i].position+hx-hy;
  12.    vertices[i*4+2].position=particles[i].position+hx+hy;
  13.    vertices[i*4+3].position=particles[i].position-hx+hy;
  14. }

now you can render the vertex array using quads or using triangles with an index buffer.



March 20, 2005, 03:03 AM

hey thanks for the replied guys :) Im basically doing what juhani posted, my framerate was really low not because of particles but because my matrix getting method was flawed and drawing TONS of degenerate very large polygons... thats been fixed now, and its good to see someone agrees with the way I've been doing it, so it can't be all too bad... time for some more particle effects :P thanks again

This thread contains 6 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.