English 中文(简体)
SFML Plasma Sprite Effect?
原标题:

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

最佳回答

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 (heightwidthframerate) 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;
}
问题回答

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.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签