Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
99 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

Point Sprites

Point sprites were introduced in DirectX 8.0. They offer a nice advantage over the normal method of rendering particles. Normally you would create a rectangle using four view-aligned vertices set to the appropriate texture coordinates. With point sprites you can simply use one vertex for every particle! Therefore they require less bandwidth, so you can render more particles using point sprites instead of using the old method, and you don't have to manually adjust the vertices to be aligned with the view vector.

However, some features of point sprites (e.g. scaling) are not supported on older video cards available. You can simply enumerate the features of the video card to see if certain things are supported.

Point sprites can be used in both 3D and 2D projections. For simplicity this tutorial will be all about 2D. In 2D particles can be used for smoke, rain, flames, wormhole like effects and many other things. Check out the source for some interesting particle demonstrations.

Starting with our simple particle engine

Well, it's time to write our particle engine. We are going to keep it extremely simple right now. I assume you have the basics of initializing DirectX all covered.

The method I commonly use for particle engines is to create one "Particle" class which will hold all the properties of a particle, like size, color, lifetime, etc. It will also have a few methods for resetting and updating particles. Then I wrap another class around the Particle class, like a collection (not a VB collection!), which will control all individual particles. For VB this might not be the fastest method (since we have to loop through every particle, every frame), but it is easy to setup and modify. It's always possible to port the class to an UDT "Particle" with the same properties, and then simply use an array to hold all particles. Arrays combined with UDT's can be quicker than the method used here.

First we are going to decide what (public) properties we will need in the Particle object.

  • Position;
  • Color, stored in R,G,B,A;
  • Horizontal and vertical speed;
  • Horizontal and vertical acceleration;
  • Alpha decay (basically lifetime).

I think that should be enough to get started with some fun particle effects.

Remember: The Particle object is one individual particle. The collection will control all the particles. So you can add more properties to the Particle object like: weight, lifetime, start color, end color, etc. You might have noticed "size" is missing. Size will be controlled in the render method. Unfortunately, this means you have no individual control over particle dimensions, but this method will be fast, and look great as well.

Now that the Particle object is ready, we will have to create our "wrapper" or collection as well, which will control all the particles. Right now the only thing we need are methods to update the particles and draw them on the screen.

What we need:

  • A method to initialize the starting point, create the point list, etc;
  • A method that will update the particles with new positions;
  • A method that will render the particles;
  • A method to reset an individual particle, when the particle is "dead".
  • A method to relocate the emitter.

I have called the methods Begin, Update, Render, Reset, Relocate respectively.

The particle collection also has a few properties of its own, such as the maximum number of particles to emit, position, etc.

Creating the code

  Point Sprites
  Creating the code

  Source code
  Printable version
  Discuss this article