Rendering lots of particles...

Started by
6 comments, last by Pirosan 19 years, 11 months ago
Hello all! A while ago, I made a class called particle in my engine that allows me to make a particle, set its texture, and render it. Now that i have been working with many more particles and large scenes, i thought it would be a good idea to create a class that includes a lot of particles, so i can send them all to render at once, cutting my render time down conciderably. Unfortunatly, i cant just change my code around a little bit, because the way i render each particle is to chance a matrix so it is facing me, now that i want to render hundreds at once, this would not work, so i am seeking a different approach. I was wondering if anyone knew a good equasion to manually change the vertex locations of each corner of the particle so it faces the camera. if i have an array of verticies that includes locations for each particle, at render time could i just create 2 polygons for each particle and change the vertices manually by using some equation so that they are facing the camera? Any tips would be very helpful! Chris
Bow before me... for i am l33t!
Advertisement
i dont know if direct x has a built in function for doing something like this. Im thinking of doing it completely mathmatically, but that may slow down the speed a lot if im doing this to 1000s of particles. How do other games do this kind of thing, and what would be some good techniques that would make this kind of thing easier?
Bow before me... for i am l33t!
Take a looky here

I usually just apply a billboard matrix to the entire particle effect if they''re not really spread out, it''s so much faster. If however, they''re going to be on different sides of the screen because of high velocity, then just use sin/cos to rotate the actual 4 vertices against the angle of the camera''s view matrix each frame. Don''t forget how you plot the coordinates to begin with, since an angle of zero (in default left hand cartesian) is looking down the positive z axis, straight ahead.

With dynamic vertex buffers, it''s a good idea to lock for 500 particles at a time max, update, render, and then do another 500 or however many depends on how much data is going to be sent, not doing all at once.. that could stall the program and wouldn''t be very efficient either.
Are you working with D3D ?
If thats the case, D3D has point sprite primitives. It''s one
of simplest methods to render particles, altough it''s not
supported by some very old cards ! It''s simple, efficient and
there''s no need to make the particle face the camera !

Check the sdk for point sprites.

There is no problem, only solutions...
thanks a lot for the suggestions, ill try them out and tell you how they go!
Bow before me... for i am l33t!
Some modern day cards also don''t support point sprites, so be careful. For instance, laptops sometimes have "Special Editions" of video cards and leave a lot of the good stuff off. A lot of people like to play games on laptops though. Just make sure you have multiple ways to perform the render. Use D3DXEffectFile for that.

Chris
Chris ByersMicrosoft DirectX MVP - 2005
This reference from GDC 2004 may be of use:

Building a Million Particle System (Part 1)

Building a Million Particle System (Part 2)

It kinda deals with programmable shaders, though. Still, interesting reading.

Graham Rhodes
Principal Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net

This topic is closed to new replies.

Advertisement