SFML 等离子精灵效果?
有没有一种方法可以在 SFML 中创建等离子效果,并且不会降低我的帧速率?
Is there a way to create a plasma effect in SFML that doesn't slow my framerate to a crawl?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1)直接在内存中将图像位作为字节(或int/任何取决于您的目标颜色深度)数组进行操作。不要每次都使用从图像中 GetsPixel() 的任何内容。
2)尽量减少数学。对于等离子效果,您通常会使用大量三角函数,当您每秒执行这些函数(高度宽度帧速率)次时,这些函数的速度相当慢。要么使用快速专用数学库进行计算,要么更好的是,在开始时缓存计算,并在效果期间使用查找表将数学完全从每个帧中删除。
3) 使老式等离子效果运行得如此之快的原因之一是调色板循环。我不知道有什么方法可以直接使用 SFML 复制此内容(或一般调色板),但您可以使用 GLSL 着色器来获得相同类型的结果,而不会影响性能。像这样的事情:
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:
您可以在 RAM 中制作等离子效果,然后将其放在纹理上并上传吗?这不是着色器效果,但它会给你等离子体效果。
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.