Sunday, September 1, 2013

Pulse Lasers

Finally I have implemented the Pulse Laser onboard system.  This was an exciting build, as it leverages a number of features I've been wanting to play with.


Ship System
Each Pulse Laser attached to the ship is a ship system, and has a power capacitor which draws energy from the main power unit.  When you fire, it fires continuously until the capacitor runs out of juice.  After that, the rate of fire for the lasers is limited to the capacitor's recharge rate.  What this means is if you let the lasers fully charge, you get an initial ultra-burst of pulse laser fire, followed by a slower volley that can be sustained indefinitely.

Rendering

It's important to batch objects.  A GPU can draw 1000s of lasers in the blink of an eye, as long as you submit it with 1 or 2 draw calls.  If you draw each laser individually, you'd easily use up your 33 msec or more.

In Pegwars, a python pulse laser fire event writes a pulse laser into a single dyanmic vertex buffer.  The initial position and velocity is written into the vertices, and all of the animation is done in shaders afterwards.  This buffer is circular, and as such depending on the head/tail indices, it requires at a maximum just two draw calls to render 1000's of laser beams.


Lasers are bound to both the additive render channel and the bloom render channel to give a nice glowing-hot look.

Also, every laser beam also generates a screen-space light that looks great when shooting over the top of space stations or planets.

Here's a collage of the pulse laser lighting work-in-progress, from the very first blob of light, to attenuation work, debug shaders and finally the results - firing lasers through a set of buildings on a space-station :)


1 comment: