Tuesday, February 23, 2010

Starfield


The starfield effect is a popular effect, present in a lot of demos. It's easy to code and optimize.

A starfield effect consists of a lot of 3D points, that are animated and projected. The initial position of the stars is usually random. After projecting each point, you decrement the Z coordinate of the point. If the point goes off-screen, the point needs to be recreated.

To project a 3D point, use this formula:

projected x = x / z
projected y = y / z


Create an array of random points. After projecting each point, decrement its Z coordinate. If Z becomes a negative number, or the projected point goes offscreen, calculate another random point. You should scale/translate the projected point.

When you plot the point you can apply different effects, like antialiased particles, different velocities, motion blur, lines or circles instead of pixels...

No comments:

Post a Comment