# Plasma arcs (lightning effects)

Does anyone know how to do those wondurful real-time arced plasma or lightning effects as seen in games such as Half-Life and that VIP2 demo in OpenGL?

I would partition the straight line from one end to the other with a number of points, and assign a jitter weight to the points that was inversely proportional to the distance a point was to its closest end of the line, i.e. midpoint would have maximum weight and endpoints 0 weight. For the actual jitter values, I’d likely use animated Perlin noise.

[This message has been edited by DFrey (edited 02-08-2001).]

I did a lightning effect a while back. Almost like DFrey said, except I calculated it recursively.

Take a line segment, find the midpoint, and move it in a random direction by a random amount that is scaled by the length of the segment. Repeat with the resulting two segments until you have enough detail.

For animation, just do the calculations every frame, no need to use perlin noise, just use a standard random number generator.

If you use additive blending, drawing multiple sparks looks really cool.

I don’t have any source, because I did it at school last year and didn’t bother to keep it.

j

The reason I suggest animated perlin noise is so that the arc partitions would morph over time rather than flicker from one position to another. Either method sounds good, depending upon on the final effect you want.

Thanks guys! So you’d just use GL_LINES? That’s easy enough. How about if you want the “core” of the bolt to be bright and the periphery of the bolt to fade down a bit? How would you achieve something like that? I’ve seen things like this in games where they shoot laser beams and stuff but I could never figure out how they did it. At first, I’d say to use a quad or something like that but ofcourse you have the problem of looking at it at the wrong angle and seeing that it’s a quad. But you can’t billboard it because it’s a line that you want to look 3D. I would imagine whatever technique is used to achieve this “laser” effect would also apply to the lightning effect I mentioned above (bright core, dim edge).

DFrey, how can I get information about “perlin noise”? This sounds like a good technique if you want the line to move more like a real plasma arc.

For Perlin noise info, just about any game development page should have something on the topic of Perlin noise. You should have no problem finding many good pages using a search engine. A couple pages I have bookmarked are http://www.noisemachine.com/ and http://freespace.virgin.net/hugo.elias/models/m_perlin.htm

I would use a quad to draw the line segments to get that penumbral effect. The trick is, you have to rotate each quad around its longest axis only so that it always faces the viewer. This looks fine until the view actually intersects the quad’s long axis.

[This message has been edited by DFrey (edited 02-08-2001).]

And I guess you probably don’t need to worry that much about it intersecting since that would be a rare case? What’s the best way to rotate the thing along it’s longest axis? Surely you don’t want to maintain a seperate matrix for each line segment! What’s a better way of doing it?

One method is to transform the points into view space, and then translate a copy of the set of points. You could then create a triangle strip from all these points. Problem with this method is determining which direction to translate the copy. I suppose the direction would be perpendicular to the line connecting the endpoints of the arc.

One method that would work in most all instances and view directions, but is extremely expensive is to literally trace the arc path with a billboard and blend the billboards. You would need at least two different billboards for this approach, one showing the profile of the arc, and another showing the cross section. You’d have to determine the angle between the line of sight and the long axis of the quad to gauge which billboard to use.

For the “morphing” effect using Perlin noise, are you thinking of using 4 dimensional perlin noise and using the 4th as time?

Correct. Or 3D noise (3rd being time) if you just want the jitter vectors perpendicular to the arc axis.

4D noise opens up the possibility for the arc to make loops (and maybe knots too?). 3D noise will not.

You might also toy around with the idea of attractors. An attractor with positive influence could be used to pull the partitions in a bit and a negative attractor could push it out a bit. If the influence of the attractor on a point of the arc was proportional to the square of the distance seperating the arc point (in normal position) and the attractor, this would allow the arc to have a equipotential axis (more realistic) rather than a straight line axis. But that might be a bit too much work.

[This message has been edited by DFrey (edited 02-08-2001).]

You’re right, I should have said 3D. Although you could possibly use 2D for such a thing couldn’t you? 1 dimension for positions that lay in a single plane and the 2nd dimension for time. I might give the attractor thing a try in a demo or something but in my game I think I’ll need something a bit more simple due to the fact I’ll already be doing a bunch of other calculations for other things. Thanks!