Author Topic: Advice on creating a lovely plasma effect  (Read 6525 times)

0 Members and 1 Guest are viewing this topic.

Offline PhotonStorm

  • ZX 81
  • *
  • Posts: 5
  • Karma: 2
    • View Profile
    • PhotonStorm
Hi all,

Ok so I'm sort of stuck in the 80s/90s when it comes to demo effects, but I like it here and they fit into my games well :)

But I'd love some help creating a really flexible plasma effect.

I've got a "stock one" which I roll out now and again, it's pretty - but to be honest I've only a vague idea how it works, and it doesn't allow for much in the way of manipulation of the waves. You can see it here http://www.photonstorm.com/games/quartet (play the game, then click the Credits option in the menu)

What I'm after is something that I can easily change the starting values to create much more diverse and interesting plasma waves, or ideally alter them in real-time so the effect sort of "evolves".

If you've any advice or code for this I'd be extremely grateful :)

Cheers,

Rich

Offline LittleWhite

  • Senior Member
  • Amiga 1200
  • ********
  • Posts: 418
  • Karma: 31
  • It's me!
    • View Profile
Re: Advice on creating a lovely plasma effect
« Reply #1 on: May 09, 2011 »
Hello,

Until now, I am doing pretty the same than you, with sample cos / sin and incrementing it.
Ok, it's the simple plasma effect, it does the job and we are happy.

You can try to change the initial pattern, or the evolving pattern. For exemple, you can adde the value of the actual colour (don't forget to divide by something :D  ; don't forget to keep a minima of 1) to the pixel. Like this, following the colour the evolution might change.

This is my first idea ....
The demoscene will never die, never!

Offline combatking0

  • JavaScript lives!
  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4569
  • Karma: 235
  • Retroman!
    • View Profile
    • Combat King's Barcode Battler Home
Re: Advice on creating a lovely plasma effect
« Reply #2 on: May 09, 2011 »
If you're doing this in Flash, I can work on this with you. I guess you're using the additive blending mode to achive the effect - if you're using Flash.
You are our 9001st visitor.
Challenge Trophies Won:

Offline PhotonStorm

  • ZX 81
  • *
  • Posts: 5
  • Karma: 2
    • View Profile
    • PhotonStorm
Re: Advice on creating a lovely plasma effect
« Reply #3 on: May 09, 2011 »
Nope, just using a simple sine going through a pre-calculated palette. Pixels plotted in real-time. No blend modes (didn't see the need?). Happy to post the AS3 source.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Advice on creating a lovely plasma effect
« Reply #4 on: May 09, 2011 »
Nope, just using a simple sine going through a pre-calculated palette. Pixels plotted in real-time. No blend modes (didn't see the need?). Happy to post the AS3 source.

There's nothing wrong with using this method - it's what I'd use too and in fact a lot of Amiga plasmas were nothing but massive pre-calculated colour tables.

There are a lot of interesting ways you can make patterns, I really love Perlin Noise but if you're after something more traditional then some simple sine + cos will suffice.

I have to say that I have never coded 1 byte of actionscript in my life so the following will be up to you to impliment if you decide.

Firstly I guess that you'll have some kind of X + Y loop to render your screen.  You can use the X and Y co-ordinates to generate some colour values using sine and cos.

I don't know if Actionscript does it's trig in radians or degrees so you may need to convert radians to degrees, the formula to do so is;

degree = radian * pi / 180

It will be better for you to pre-calculate that and just multiply by the number you pre-calculated so;

Rad2Deg = Pi/180

Or if you don't have a Pi command in Actionscript;

Rad2deg = 4*atn(1)/180

The thing to remember about sin and cos is that it will generate a number between -1 and +1 so this needs to be converted into a usable number for your colours.

For example

size = 125
number = (size * sin(angle)) + size

Depending on angle you get a number in the range of 0 and 250 which is quite convenient for what you want to do.

So taking this into account, you can do something like;

Rad2Deg = Pi/180
size = 125

for x=0 to width
  for y=0 to height
  red= size * sin ((x+y+some_offset)*Rad2Deg)
  green= size * sin ((x+y+some_offset)*Rad2Deg)
  blue= size * sin ((x+y+some_offset)*Rad2Deg)
  plot x,y,rgb(red,green,blue)
  next y
next x

That would make a grey pattern, try varying the red, green and blue offsets and playing with the formulas to make it more interesting.

If you want to go all out for speed you could pre-calculate a huge palette into an array or chunk of memory and fill it with ready made colour values that you can reference with just one line instead of 3 for r,g,b.

And welcome to DBF, your game has a definite C64 vibe to it :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline combatking0

  • JavaScript lives!
  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4569
  • Karma: 235
  • Retroman!
    • View Profile
    • Combat King's Barcode Battler Home
Re: Advice on creating a lovely plasma effect
« Reply #5 on: May 09, 2011 »
Actionscript 2 does Trig in Radians - I assume AS3 is the same.

The stage objects however, take their rotations in degrees. I'm not sure if AS3 corrects this or not, but it doesn't look like Mr. Storm is rotating anything on the stage as such, just performing many trig calculations - so disregard this second sentence ;)

No point using blend modes for this effect - it may over complicate things.
You are our 9001st visitor.
Challenge Trophies Won:

Offline Xetick

  • Atari ST
  • ***
  • Posts: 132
  • Karma: 80
    • View Profile
    • Plane9
Re: Advice on creating a lovely plasma effect
« Reply #6 on: May 10, 2011 »
I have one in Plane9 that might work for you or at least give you some idea. The scene is called Plasma and its all done in a shader. The plasma moves to the beat of the music. I think I got the base of it from this forum actually.

The interesting bit is
Code: [Select]
float colx = (sin((p.y+in2.x)*PI2)+sin((p.x+p.y)*PI2))*0.5+0.5;
float coly = (sin((p.y+in2.y)*PI2)+sin((p.y+in2.z)*PI2))*0.5+0.5;
float4 color = float4(cos(((colx*coly)+float3(0.1,0.2,0.3))*PI2+in1)*0.5+0.5, 1.0);

p is the current "pixel" in the -0.3 to 0.3 range

The in1 & in2 values are computed as

Code: [Select]
in1.x = min(1,band(-1,2,0,0)*100);
in1.y = min(1,band(0,2,0,0)*50);
in1.z = min(1,band(1,2,0,0)*75);

in2.x = noise2(1, t*0.01)*15;
in2.y = noise2(2, t*0.01)*15+t*0.001;
in2.z = noise2(3, t*0.02)*15;

Just change those to something you have in your engine
Plane9 - Home of the Plane9 3d screensaver/music visualizer
Challenge Trophies Won:

Offline PhotonStorm

  • ZX 81
  • *
  • Posts: 5
  • Karma: 2
    • View Profile
    • PhotonStorm
Re: Advice on creating a lovely plasma effect
« Reply #7 on: May 10, 2011 »
Thanks for the suggestions guys. I'm playing with the code for this tonight so I'll post my results!

BTW Xetick - Plane9 looks lovely - can I just ask, why is your p (pixel) value on a -0.3 to 0.3 range? And I assume band() and noise() are to do with music values?

Offline Xetick

  • Atari ST
  • ***
  • Posts: 132
  • Karma: 80
    • View Profile
    • Plane9
Re: Advice on creating a lovely plasma effect
« Reply #8 on: May 10, 2011 »
why is your p (pixel) value on a -0.3 to 0.3 range? And I assume band() and noise() are to do with music values?

p is really from -1 to 1 but for this plasma it looked better if i "zoomed" in a bit so i just scaled the value with 0.3 before using it.
band() is for the music. It's basically a beat detection with a specific damping and part of the frequency. In this case high damping, so low changing values, over the bass frequency for the different speakers -1=both,0=left,1=right
noise2() is a 2 dimensional simplex noise
But for your plasma effect using a bunch of cos/sin values should probably work just fine instead of the band and noise2

If you install the visualizer start the editor then go to "DemoScene/Plasma" in the right explorer tree window you can see the complete scene and its shader.
Plane9 - Home of the Plane9 3d screensaver/music visualizer
Challenge Trophies Won: