Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Originally asked on StackOverflow, but it became tumbleweed.

I'm looking to create a glowing line effect in BlitzMax, something like a Star Wars lightsaber or laserbeam. Doesn't have to be realtime, but just to TImage objects and then maybe saved to PNG for later use in animation. I'm happy to use 3D features, but it will be for use in a 2D game.

Since it will be on black/space background, my strategy is to draw a series of white blurred lines with color and high transparency, then eventually central lines less blurred and more white. What I want to draw is actually bezier curved lines. Drawing curved lines is easy enough, but I can't use the technique above to create a good laser/neon effect because it comes out looking very segmented. So, I think it may be better to use a blur effect/shader on what does render well, which is a 1-pixel bezier curve.

The problems I've been having are:

  • Applying a shader to just a certain area of the screen where lines are drawn. If there's a way to do draw lines to a texture and then blur that texture and save the png, that would be great to hear about. There's got to be a way to do this, but I just haven't gotten the right elements working together yet. Any help from someone familiar with this stuff would be greatly appreciated.
  • Using just 2D calls could be advantageous, simpler to understand and re-use.
  • It would be very nice to know how to save a PNG that preserves the transparency/alpha stuff.

p.s. I've reviewed this post (and many many others on the Blitz site), have samples working, and even developed my own 5x5 frag shaders. But, it's 3D and a scene-wide thing that doesn't seem to convert to 2D or just a certain area very well. I'd rather understand how to apply shading to a 2D scene, especially using the specifics of BlitzMax.

share|improve this question
to clarify, I want something 2D like this 3D example from Nvidia –  zanlok Dec 3 '10 at 19:44
There is a lot of things going on in the picture. At first I thought I knew what you wanted, now I have really no idea. –  AttackingHobo Dec 3 '10 at 20:18
On a (moderately) related note; finding curves that are offset to arbitrary beziers is nontrivial. (At least for train-tracks style curves.) Do keep that in mind. –  Williham Totland Dec 4 '10 at 1:03

3 Answers 3

up vote 2 down vote accepted

Let's get the easy stuff sorted first, making and saving an alpha mapped png using BlitzMax:

pxm:TPixmap = CreatePixmap(x,y,PF_BGRA8888)

For a=0 To x-1
For b=0 To y-1

But you might not need this at all since the best glow effect is achieved using additive transparency. wkerslake gave you the answer you need as his V3, he just did a really poor job at explaining that this is the exact lightsaber look.

share|improve this answer
doesn't answer the hard part, but a partial answer is better than none.. thanks :) –  zanlok Feb 4 '11 at 22:10

Do you need to generate them? It seems like you want to generate them and store them in image files for use in the game.

I think it might be easier, faster, and better looking if you created the lasers in some kind of image editing software such as Photoshop, GIMP, or your favorite editor. Export the graphics as PNG and use it in your game.

It will have better performance than some kind of live shader effect and it will be easier to tweak.

share|improve this answer
The design of this game is predicated around a lot of uniqueness in line architecture that is created on the fly. I've done the type of blitting your talking about, and yes it is very fast. Which is why I'd like to take a spritebatch approach, but will want to precache the motion animation of lines that are glowing in the manner described. Also, I want to nail a technique for this on principle, as a learning exercise. –  zanlok Dec 3 '10 at 19:42

There are lots of ways to do this without going down the complicated shader route.

Version 1 - Fixed size

If the glowing objects are always the same size, like a Star Wars style laser gun blast then just bake the glow into the texture. Use PNG for full 8-bit transparency and be done with it.

Version 2 - Variable size

If the objects change in length, more like Star Trek phasers then you can still do this with a pre-baked texture that just tiles along the length of the laser. You can either have it end harshly, or have a texture cap that you apply to a quad at each end of the variable length beam.

Version 3 - Faked lighting

If you want the glow to affect the environment then consider making two texture. One that is the center of the beam that you draw normally so it always appears. The second texture is just the pre-baked glowing elements which you draw as additively transparent. This will make the glow appear to cast light on whatever is underneath it.

It's a low tech effect and isn't correct lighting, but for something moving fast enough in 2D it looks close enough to correct to fool you if it isn't too large an area.

share|improve this answer
the effect I'm looking for is a neon luminescence, not v3. I've reviewed techniques for what you cite as v1 and v2, and they aren't a match for what I'm trying to accomplish. See link in the first comment on the original question. –  zanlok Dec 3 '10 at 19:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.