PDA

View Full Version : OpenGL Plasma

XFire
08-05-2002, 02:42 AM
Hi folks,

i would like to know how a plasma effect could be done in opengl. Unfortunatly i have'nt found any information about plasmas - and how to write them.
I would be grateful if you could briefly explain how plasma works / or post a link to a plasma tutorial.

Morglum
08-05-2002, 05:27 AM
Plasma is just ionic gas. Lightning bolts, neon lamps are two examples of plasma. For a neon lamp I'd just draw a cylinder with emissive material property. For a lightning bolt, I don't know.

Niftybitz
08-05-2002, 05:52 AM
Hi there!

Plasma is a very simple effect to perform. The only thing you need is a couple of sine and cosine functions to generate 2D waves, that when using a upcounting angle will seem to move and even makes the different waves combine at some points. A simple way to create a two-dimensional plasma-map is as follows (C++ pseudo-code):

counter=0;
const ZOOMFACTOR=10;

for(x=0;x<256;x++)
for(y=0;y<256;y++)
{
PlasmaColor[counter]=
30*sin(x/(256/2/PI)/ZOOMFACTOR*1.283f)+
20*cos(y/(256/2/PI)/ZOOMFACTOR*2.085f)+
30*sin((x+y)/(256/2/PI)/ZOOMFACTOR*.031f)
}

Now you have calculated a plasma-map. Oh yeah, those strange float values, those are just some values i thought of while writing this http://www.opengl.org/discussion_boards/ubb/wink.gif In fact, the whole routine was just made up by me, while writing this http://www.opengl.org/discussion_boards/ubb/smile.gif)

To make this plasma move (very kewl effect),
just add an upcounting angle to x and y, while calculating the waves, like:

LOOP:
col=sin((x+angle)/(256/2/PI));
angle++;
WHILE NOT DONE, GOTO LOOP

Of course the 256/2/PI should be a precalculated value and you could even generate a sine and cosine list and use a displacement value in the list to make the plasma move, like this:

for(i=0;i<256;i++)
{
sinetable[i]=SINE_CALCULATION;
cosinetable[i]=COSINE_CALCULATION;
}

for(y=0;y<256;y++)
for(x=0;x<256;x++)
{
PlasmaCol[i]=
sinetable[(x+displacement)%256]+
cosinetable[(y+displacement)%256];
}
displacement++;

Just some code-fragments (again made up while writing this http://www.opengl.org/discussion_boards/ubb/smile.gif) and i think you got my point.

Btw, in OpenGL, you can use the texture matrix stack to add a plasma effect to a texture you've applied to a cube. You could just use the glTranslatef() function to distort the texture coordinates.

Hope you understood all, but i think you can experiment with this all. Just go and experiment with different cosine and sine waves to generate interesting patterns.

Have fun and mail me if you still don't understand it all.

Ciao,

Niftybitz.

Morglum
08-05-2002, 05:54 AM
Originally posted by XFire:
I would be grateful if you could briefly explain how plasma works

Take a gas. For example that might be air. It is constituted of many molecules of gas, not necessarily all identical. For example in the air there is approx. 80% azote, 20% oxygen.

Each molecule has a "Level of energy" (plain translation from french, sorry). This level of energy might vary. In general, it is the lowest possible for that molecule. This lowest level is called the "fundamental level". Other (higher) levels of energy are called "excited levels".

In general (and this is the case here) the level of energy cannot vary continuously. It takes discrete values. One says that it is "quantified" (whence the name of quantum mechanics) :
possible values are : Level 0 (fundamental), Level 1 (excited), Level 2 (excited), and so on ...

Now take two electrodes (that is, two wires connected to a source of electricity) and separate them by a distance of 1 inch. Apply a growing electric tension between them : first 0 volt, then 10 volts, then 50 ...

At the beginning, nothing happens because you do not provide to the air between the electrodes enough energy to reach the first excited level. So it remains at the fundamental level.

But when you reach a tension of approx. 5000 volts (or something like that, I haven't made the computation), a bolt appears between the electrodes. You've produced plasma.

What's happening ? You've provided to the molecules of air between the electrodes enough energy to reach the first excited level. That produces no light;in fact, that's invisible. But the excited levels are not stable. After a very short moment (much less than 1 second) each excited molecule goes back to its fundamental level, and a photon is created. This photon takes away the energy lost by the molecule when passing from the (high energy) excited level to the (low energy) fundamental level.

Because photons are created, you see light. This is why plasmas tend to be luminous. Got it ?

XFire
08-05-2002, 12:56 PM
Thank's all!

@Niftybitz: Wow, great explanation, just got it to work (basically). Thank you verry much!

Niftybitz
08-05-2002, 10:55 PM
You're welcome http://www.opengl.org/discussion_boards/ubb/smile.gif