Archived

This topic is now archived and is closed to further replies.

Lightning/electricity type effect, how to do it?

This topic is 5573 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve been looking EVERYWHERE for any type of article of making electricity like effects, but I can''t even find 1 (decent) article on it. Does anyone know of any good online resources? If not, can anyone explain how I might go about creating that effect? I have a particle engine set up already, if this effect were to require one. any help would be appreciated ps - i said lightning/electrical effect, but I really need an electricity type effect, I just figured they''re relatively similar ByteMe95::~ByteMe95() My S(h)ite

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Triangle-strip from point a to point b, add random values for irregularities, add forks/branches for lightning.

Share this post


Link to post
Share on other sites
quote:
Original post by ByteMe95
I need a clear cut answer or a good link if anyone has any

quote:
Original post by Anonymous Poster
I would use juxtaposed transitional frame relaying


well, that clears things up i''m sure...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
http://www.sulaco.co.za/opengl2.htm

have a look at the electric spheres demo, maybe that is what you''re looking for.

Share this post


Link to post
Share on other sites
I never tried but here''s what I would do first : Just have a function draw a gl line or whatever the equivalent in DX, with a variable lenght, width and orientation. All of that inside certain pre defined values, so that it doesnt look too weird. I''d try to draw 2 lines next to each other, one blue and one white.

Share this post


Link to post
Share on other sites
quote:
again, unfortunately i have no idea what fractal rivers are

I need a clear cut answer or a good link if anyone has any



Oh! In that case, here is where you''ll find all the information you''ll need

Share this post


Link to post
Share on other sites
omg, I cant STAND it when people point people who are looking for help to google.
I had a whole argument wtih someone on IRC today for that.
First of all, if u read my first post I said I searched teh etnrie web and found nothing useful.
Secondly, if you can''t say anything useful why say anything at all???
:@

ByteMe95::~ByteMe95()
My S(h)ite

Share this post


Link to post
Share on other sites
G''day,

I saw an article on this ages ago, but I have no idea where it was. But here are my thoughts on how to do it.

The only constant is where the lightening/electricity starts. From there you want to draw a line (preferably white, but as the article I read said you have to play with this based on the situation, perhaps grey or a mixture of colours would work best, but for now lets just say white). This line needs to be a random length and go out at a random angle. From the end of this line repeat the process until you hit something (wall, ground etc).

The example showed going from a random point in the sky to the ground. Depending on whether you want the electiricty to go to a certain point or have it randomly "zapping" you could simply let the computer figure out where the electricity zap will end up.

For each line segment you would need to do some bounds checking to make sure it doesn''t go through any walls or anything.

Another idea which is a lot more CPU intensive would be to model the electicty based on the room. This is how it would be in real life. Basically depending on the environment the electric "zap" would go to differnet parts of the room. For example lightening again....it always goes from the sky (positively charged) to the ground (negatively charged) but it does this in a random way, so no two lightening bolts are the same.

Anyways, i hope that helps a bit, it is all very theoretical though, sorry i can''t give you a "call this function then that function" but this should point you in the right direction I hope.

Doolwind

Share this post


Link to post
Share on other sites
Let''s examine some of the posts in this thread:
quote:
Triangle-strip from point a to point b, add random values for irregularities, add forks/branches for lightning.
Now, because of this information, you go back to google and search for:
Traingle-strip lightning

quote:
multitexturing with a procedural texture
While not particularly helpful, google for:
procedural texture lightning
procedural lightning

quote:
Be inspired by fractal rivers, but limit the iterations, and add branching. Note that I''ve never actually tried this idea, but I think it could probably work
Go back to google, and search for:
fractal rivers lightning
"fractal rivers"

I know you can find information on fractal rivers because that''s how I found out about them.

If you find someone who just talks about what you want, but uses different words to describe the effect, you search for those words instead.

You don''t google once and then demand someone hold your hand through the process. You solicit suggestions for how you might be able to generate this effect yourself. If some of those suggestions utilize concepts or terminology you don''t understand, you look for explanations of those concepts or terms. Demanding a more thorough explanation when someone has most likely given you enough information to find or figure out what you want is just a bit more rude than referring someone to google.

If you''ve googled for each of these things and you *still* can''t get it to work, detail your search, the results you obtained, the code you wrote to attempt to implement the concepts, the code''s effects, and why those effects are insufficient. If you''ve searched, attempted code, and found the code too difficult or the code''s effects undesirable, say so, and I''ll apologize.

So, what were your first approaches to this, and why didn''t they work or weren''t appropriate?(note that an idea of how to make the lightning but having no idea how to write the code to implement this idea is an acceptable excuse, but should have been detailed in your original post)

Just to show how nice of a guy I am, I''ll let you in on a little secret. For every attempt to represent reality in a computer, there are two ways to generate an algorithm that looks real:
1)Simulate the way reality does it.
2)Simulate the features we recognize as the aspect of reality.

#1 is way out of my league, but perhaps another poster can help you.

For #2, you have to ask yourself what features we recognize as "lightning". Here''s my personal list:
1)Branching
2)Purplish color, with near-white at the center and becoming less bright as one approaches the edges of the "stalk"
3)Diminishing brightness and thickness of the branches
4)Irregularity
5)The fact that the brightest path wends its way from one electrode to the other, although not necessarily in any particularly direct way. In the case of actual lightning, these are the clouds and the ground.

How did I figure out this list? Well, I have a mental image of lightning, and I''ve learned to examine my mental images through certain mental training I''ve undergone. For the less introspective, here is a good place to start. Examining this page has allowed me to discover a non-obvious #6:
The fact that branching is most likely to occur when bending is sharpest.

Now, how does one go about simulating these features? Well, #3 & #4 seems to lend themselves to a self-similar fractal, although #1 does not. #2 is simply a purple-white-purple gradient, which is fairly easy to do. #6 can help us connect #4 to #1. #5 looks like a good starting point for the algorithm.

How did I come up with these points? Creativity and a little bit of experience with image creation and editing.

So, let''s bring them all together. Raw creativity and a bit of experience with self-similar images.

As #5 suggests, we have a line between A & B, whatever they are. Now, we subdivide into two segments at the midpoint(fractals often subdivide at the midpoint). We''re going to take a slight departure from the fractal idiom and use randomness to determine the curvature here. Probably use a normal distribution or whatever is computationally or conceptually convenient. Anyway, take this random value and have the segments meet(yeah, they''ll grow in length) at a point perpendicular from the midpoint of the original line a distance away equal to that random value. If this distance is far enough, branch. To do this, make a point somewhere and just use this scheme on the line from the point to which you moved the midpoint of the line to that new point. Continue using this scheme on the segments that have now been divided into Above-the-midpoint and Below-the-midpoint. Use this scheme on the segments you get from dividing above-the-midpoint and below-the-midpoint into two segments(each). To make this into a graphic, just make the branches less bright and use the gradient.

If there are problems in this fractal, it will most likely be that there is too much randomness(iow, 50% of the bends will be "backwards", which will look odd). To fix this, simply add or subtract by some value to the random value to make it curve less often.(I suppose, subtract on the bottom and add on the top, but I''m not really sure)

The next most likely problem will be that a concave bend on one segment connects with a convex bend on the other, which essentially means it looks like it bends really sharply.

Don''t feel any particular need to expand this 2d figure into 3d. In reality, it''s 3d, but it''s so line-like that the brain would inevitably envision the figure to be perpendicular to the line of vision and stretching out on the plane perpendicular to that line, so it would just look 2d anyway.

For debugging purposes, I''d recommend coding a simple program that will iterate each time before your eyes, so you can see where it goes wrong.

Well, my altruism quota''s all used up. Good luck.

Share this post


Link to post
Share on other sites
quote:
Original post by ByteMe95
omg, I cant STAND it when people point people who are looking for help to google.
I had a whole argument wtih someone on IRC today for that.
First of all, if u read my first post I said I searched teh etnrie web and found nothing useful.
Secondly, if you can''t say anything useful why say anything at all???
It''s true that you said that you''d searched already - but why are you condemning that response in general? It''s not always used in an inapproprate way, and it''s hardly ever intended to be annoying. Flarelocke wasn''t trying to annoy you - why are you so offended?

Share this post


Link to post
Share on other sites
Flare: I thank you for the long post, dont think you care but you have redeemed yourself in my eyes.

I''ve think about exactly what I need a little more and it seems that I need more of an electric bolt type effect rather than lightning (so no branching)
Basically I just need to have a bolt go from point A to point B, which should be easier I would imagine.

And no I didnt try coding anything before I posted because I didnt know what approach to take at all, hence the post.

Thanks to whoever posted http://www.sulaco.co.za/opengl2.htm, it was pretty helpful.

Beer Hunter: If someone says they''ve done a thorough search and your response is all your answers can be found "here" (link to google), I cant see that as being helpful.
Maybe thats just me

thanks guys
- Rob

ByteMe95::~ByteMe95()
My S(h)ite

Share this post


Link to post
Share on other sites
I took in everything you had to say, and i thank you for it

I''m happy to say that I asically got it down now. For an electric bolt it''s rather simple.

For anyone reading this post in the future looking for the answer:

(This is to make an electric bolt go from point A to point B)

Have an array of NUM_SEGMENTS floats which will be your peak offsets, where NUM_SEGMENTS is the amount of segments (peaks) between your 2 control points, I have it set to 32, works nicely.

0 out the array. Now every loop ADD a random amount from -1 to 1 (actually should be less, maybe from -.25 to .25, depending on the look you''re going for), to every offset value, but CAP it at -1 and 1 (if it goes under -1 make it -1, if it goes over 1 make it 1).

Now you have an array of offsets that shoulsd be in the range from -1 to 1. If you like you can have constraints on how far apart adjacent peaks are as well when you update the array.

Now given these points its pretty simple. Startingf from point A, you go to the first offset*Height, where Height is half the hight you want the bolt to go up and down, since offset is in the range -1 to 1. You go that much perpendicular to the line you are rendering, that is where the point lies. On a horizontal line, offset 1 (offset 0 is the starting point A) would be at A.x + 1/NUM_SEGMENTS, A.y + offset[1]*Height

But for non horizontal lines you would need to get the normal to the line and base it on that.

Regardless, this gives you the electrical effect. But, one line doesnt look good. Draw multiple lines using the same offsets, say 4-10 lines, but move every offset randomly by a few pixels so the lines dont coincide exactly, and allow blending.
Set the line colors to some blue, and now when the multiple lines mix itll be whiter in the middle and blue on the outside, looks good.

Eventually you may want to replace the lines with triangle strips for speed.

I realize i did a piss poor job of explaining it, but hopefully it made some sense. If I ever get time maybe I''ll write a tutorial

- Rob

ByteMe95::~ByteMe95()
My S(h)ite

Share this post


Link to post
Share on other sites
I just thought of this, a way to draw a lightning bolt between two arbitrary points.

Lets say we want a lightning bolt that starts at point P1 and goes to P2. Then lets have a function GetPoint(t) that returns a point on the bolt, t=0 returns P1 and t=1 returns P2;

First, find the Vector V1 going from P1 to P2 and normalize it. Then pick a random vector V2 thats != V1, or use the vector from P1 to the camera or something, notmalize that. Then V3 is the cross product of V1 and V2.

Then the point P3 on the bolt will be given by:

P3 = interpolate(P1, P2, t) + (V3 * random_float);

where random_float is a random float (!) in the range [-1,1] or whatever range looks good.

Then just draw i segments, incrementing t by (1/i) for each point.

I think that should work, although im not completely sure.. I think im goin to give it a try right now.

You could easily adapt it to draw trianglestrips by using for each segment the points

{P3,P4} = interpolate(P1, P2, t) + (V3 * (random_float +/- k));

where k is a constant that defines the width of the tristrip.

hopefully that made sense, mathematically and otherwise...

/me goes to try it out


Edit:
This approach would make the bolt flat on the plane whos normal is V2. That may or may not be desirable, but its not hard to fix...

[edited by - demosh on September 11, 2002 6:59:57 PM]

Share this post


Link to post
Share on other sites