Game Design, Programming and running a one-man games business…

The complexities of drawing laser beams

laser beams are easy right? just a sprite yes? You work out where it goes on the screen, at what angle and what size (due to zoom) and you just blap it. Job done.


Not if you want them to look good. There are lots of concerns. Firstly, you probably want the turret that shoots the beam to have a seperate ‘blast’ graphic rather than just a straight beam squeezing out like toothpaste. So that’s two sprites. Then you probably want them to fade out slightly at the end so they aren’t too abrupt. Thats 3 sprites (and for efficiency you need to check they are all onscreen, often only the beam will be.) You also need a wobbly seeking effect for when the beam fires but misses.

Then you probably want your beam to fade in and out over a certain portion of the (variable) beam duration. Even if its a tenth of a second fade, it still makes things look better. Then you probably don’t want the beam to be static, a sort of ‘pulsing’ effect over time makes them look better. I use (as always) a sine wave calculated over time to vary the beam intensity. That means changing the colors of all three sprites.

Then…. you will find that the beam is pretty cool, but it’s very static, and doesn’t seem to indicate direction. You can do this in one pass or two, but you probably want a seperate layer drawn on top with some ‘inteference’ that scrolls along the path of the beam. That has to be in the right direction obviously, and it needs to smoothly wrap around.

Then…. if a single weapon has several beam ‘sources’ you need them to have different start values for the inteference, otherwise people spot the patterns.

I’ve got all this in, and working and looking fab, there is just one last thing: The inteference starts abruptly just where the ‘blast’ sprite ends and the beam sprite starts. If you zoom in, it looks really obvious. So what I need is to split the inteference sprite into a ‘beam’ and a ‘start’ section, and do a sort of reverse beam-tip thing for the start of the inteference. I also need to ensure its synched with the scrolling of the core beam inteference so it looks smooth.

Ideally I also need some level-of-detail stuff so I ignore the fiddly bits when really zoomed out on small beams, and need to hook it into a general graphics options setting for older machines.

I’ll get that finished tomorrow I reckon :D

6 thoughts on The complexities of drawing laser beams

  1. I absolutely *love* the instantaneous laser effects. A modicum of realism at last :-). The “shimmering” effect surrounding powerful laser beams IRL is light emission resulting from ionisation of particles, of which there are few in space — but if there’s debris, or even smoke, one would presume the laser would cause light to be emitted as it passed through those regions of space (plus e.g. smoke particles would reflect some of the original light towards the observer). Most of the time you wouldn’t see the beam at all though; you’d just see the glow released when the beam’s energy hit the target (ionisation again, this time of the ablated matter). This probably wouldn’t fly with most audiences, but it’d be cool if the effects were configurable …

    Unfortunately the smoke is hell of cheesy. (Why do the smoke sprites just “stop” in space once created? Why is smoke created far away from exploding craft, where there is not likely to be sufficient oxygen to sustain combustion?). Sound effects I can deal with by turning my speakers off :-D.

    Will this be released for Linux? If so, is is open for pre-order? If not, will there at least be a good chance of it running under Wine?

    Thanks for pressing ahead with a *true* strategy game!

  2. I wrote a game a while ago with a laser as its central theme. I used lots of particles to render the solid line of light. It had to work in 3D so I added equi-spaced alpha blob particles along a line which made it look like a light beam. Not as efficient as a few sprites but I could do some snazzy effects with it and it made getting the perspective laser shot to look ‘right’ much easier. I thought it turned out well (IMHO), you can see some screenshots at

    GSB looks very good so far, you’re not alone we’re watching ;)

Comments are currently closed.