Simple particle system:
Movie of particle system
Program built on a MacBook Pro running OS X Leopard with an NVidia card:
wget http://cs.unm.edu/~jbowles/cs513/assign4-jbowles.tar.bz2
tar jxf assign4-jbowles.tar.bz2
cd assign4-jbowles/ps
make
./ps
You can move the view around by holding down the left button and dragging. Shaders can be reloaded by pressing 'r'. You can quit with 'Q' or escape.
This particle system models particles being launched out of a gravity well at just over escape velocity. The particles make a couple of passes past the gravity well and then escape.
Once they've reached a reasonable distance away, the particle is reinitialized and the process starts over.
The particles are modeled as point sprites and passed to the GPU in a vertex buffer object.
The vertex shader does the usual: it tranforms the model coordinates into world space and leaves the texture coordinates alone. The vertex shader also calculate a luminance value based on the distance of the particle from the gravity well. This value is passed on TEXCOORD1 to the pipeline.
The fragment shader uses an exponential function to determine the alpha component of the fragment. The input to the exponential is the distance of the fragment from the center of the point sprite.
The color (not the alpha) of the fragment is determined by the distance of the point sprite from the gravity well. As the sprite gets farther from the well, it "cools off" and the red component goes to zero.
It is interesting to see how ordering has an effect on the alpha blending of the particles. Since these particles are not ordered, the blending is not always correct. I'm looking forward to putting the particles onto the GPU and sorting them there.
On my MacBook Pro, this ran at about 60 FPS when using 1, 20, 2000, or 100000 particles. I suspect that this is because I'm using synchronized swap buffers. When I remove this constraint, FPS goes up to 600 with 200 particles. If I use 20000 particles, the frame rate is about 100 without synchronized buffers.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment