OpenGL ES。滚动 3 层星空纹理让我从 60 -> 40帧/秒
我需要为 2D 空间滚动射击游戏绘制背景。我需要实现 3 层恒星:背景中的一个遥远的星云(移动非常慢),一层遥远的恒星(移动缓慢)和一层靠近的恒星(移动正常)在另外两层之上。
我第一次尝试的方法是使用 3 个 320 x 480 的纹理,它们是星星的透明 png。我用了GL_BLEND和SRC_ALPHA,ONE_MINUS_SRC_ALPHA。
即使在 3GS 上,结果也不是很好。在第一代设备上,FPS 下降到 40..50,所以我认为我这样做的方式是错误的。
当我禁用 GL_BLEND 时,即使在第一代设备上一切都运行良好,并且 FPS 再次回到 60...所以这一定是我正在尝试绑定大型透明纹理的事实。
问题是我不知道如何以其他方式做到这一点...
我应该像不透明纹理一样只绘制第一个星云,然后尝试用在屏幕上移动的小点来模拟中间和顶部的恒星层吗?
对于混合问题还有其他方法吗?如何加快渲染过程?一个大的纹理(图块集)是答案吗?
请帮助我,因为我被困在这里,无法出去。
I need to draw the background for a 2D space scrolling shooter. I need to implement 3 layers of stars: one distant nebula (moving really slow) in the background, one layer of far away stars (moving slow) and one layer of close stars (moving normal) on top of the other two.
The way i first tried this was using 3 textures of 320 x 480 that were transparent pngs of the stars. I used GL_BLEND and SRC_ALPHA, ONE_MINUS_SRC_ALPHA.
The results were not great even on the 3GS. On the first generation devices the FPS dropped to 40..50 so i think i'm doing this the wrong way.
When i disable the GL_BLEND everything works great even on the 1st gen devices and the FPS is back to 60 again... so it's must be the fact that i'm trying to belnd large transparent textures.
The problem is i don't know how to do it some other way...
Should i draw only the first nebula like an opaque texture and then try to emulate the middle and top star layer with small points moving around the screen?
Is there any other approach on the blending issue? How can i speed up the rendering process? Is one big texture (tileset) the answer?
Please help me cuz i'm stuck here and i can't get out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道您希望星星是什么样子,但您可能想尝试使用
DrawElements
中的GL_POINTS
或 < code>DrawArrays 可能只是用几何图层替换顶部两层。您可以使用PointSize
、PointSizePointerOES
和PointParameter
操作点来修改点的渲染。I don't know how you want your stars to look like, but you might want to try to move them from a texture to geometry by using
GL_POINTS
in theDrawElements
orDrawArrays
maybe just replace the top two layers with layers of geometry. You can manipulate the points usingPointSize
,PointSizePointerOES
andPointParameter
to modify the rendering of the points.您可能想使用多重纹理来看看是否可以加快速度。每个多纹理阶段都可以分配一个唯一的变换矩阵,因此您应该能够以不同的速度平移每个层。
我相信所有 iPhone 型号都支持两个纹理阶段,因此您应该能够将两个图层合并到一个绘制调用中。您可能仍然需要对第三层进行混合。
另请注意,Alpha 测试可能比 Alpha 混合更快。
祝你好运!
You might want to use multi-texturing to see if that speeds it up. Each multi-texture stage can be assigned a unique transformation matrix, so you should be able to translate each layer at different speeds.
I believe all iPhone models support two texture stages, so you should be able to combine two of your layers into a single draw call. You might still need to resort to blending for the third layer.
Also note that alpha testing could be faster than alpha blending.
Good luck!
后面的星云绝对应该是不透明的;其他所有东西都被绘制在它上面,我认为它后面唯一的东西是黑色的。此外,prideout 有一个观点:假设您的星形图层可以有效地具有 1 位 alpha,那么您绝对可以尝试。如果做不到这一点,Harald 提到的 GL_POINTS 技术也能发挥作用。
The back nebula should definitely be opaque; everything else is getting drawn on top of it, and I assume the only thing behind it is black. Also, prideout has a point: assuming your star layers can have effectively 1-bit alpha, that's definitely something you can try. Failing that, the GL_POINTS technique Harald mentions would work as well.