views:

201

answers:

2

Is there a way to create a plasma effect in SFML that doesn't slow my framerate to a crawl?

A: 

Can you just make your plasma effect in RAM, then place it on a texture and upload it? It's not a shader effect, but it will give you a plasma effect.

Michael Dorgan
+2  A: 

1) Manipulate the image bits directly in memory as a byte (or int/whatever depending on your target colour depth) array. Don't use anything which GetsPixel() from an image each time.

2) Minimise your maths. For plasma effects you'll usually be using a lot of trig functions which are fairly slow when you're doing them (height*width*framerate) times per second. Either use a fast dedicated maths library for your calucations or, better yet, cache the calculations at the start and use a look-up table during the effect to cut the math out of each frame entirely.

3) One of the things which made old-school plasma effects run so fast was palette cycling. I'm not aware of any way to replicate this (or palettes in general) with SFML directly but you can use GLSL shaders to get the same kind of result without a big performance hit. Something like this:

float4 PS_ColorShift(float2 Tex : TEXCOORD0) : COLOR0 
{ 
    float4 color = tex2D(colorMap, Tex);

    color.r = color.r+sin(colorshift_timer+0.01f);
    color.g = color.g+sin(colorshift_timer+0.02f);
    color.b = color.b+sin(colorshift_timer+0.03f);
    color.a = 1.0f;

    saturate(color);

    return color;
}
FerretallicA