开发者

OpenGL ES 2.0 -- Best route for simple particle systems

开发者 https://www.devze.com 2023-04-03 04:29 出处:网络
I am attempting to create a very simplistic particle system for an Android application using OpenGL ES 2.0.Basically it is just for linear moving clouds in the background.My first thought before start

I am attempting to create a very simplistic particle system for an Android application using OpenGL ES 2.0. Basically it is just for linear moving clouds in the background. My first thought before starting this was to work with point sprites, and that is what I have been trying to do. It's been pretty difficult for me to get this working, but those problems aside, are point sprites really the way to go for this?

I have read quite a few 开发者_Python百科conflicting things about them in my searches to solve my bugs, and I don't want to invest a great deal of my time into making it all work right if it is not the solution I should be going for in the first place. People post all kinds of troubles with them such as clipping, and even performance dips in comparison to just using triangles. I would like an experienced users insight into where point sprites fit in and when they should be used, including in situations like mine where they will not be more than a few dozen "particles" on the screen at very most.


Keep in mind that there are hard size limits for point sprites, and the bigger size, the slower performance. If your goal is to have only 12 "particles", I think you should render them as quads. On the other hand, if your goal is to have 12 clouds consisting of many, many "cloud particles" each to give them an animated effect, then yes you should go with point sprites.

The bottleneck will be the fill rate, especially since you will probably use blending.

If you have 100+ clouds, the question whether to use point sprites or not becomes more relevant. To animate them, you either have to send a new buffer to opengl each frame (method 1), or render each cloud in a separate call with a different transformation matrix (method 2). The latter will most likely be the slowest, but the former requires you to send 4 new vertices per cloud (assuming indexed rendering) compared to just 1 new vertex per cloud if you used point sprites (method 3).

At this point it's very easy to roughly calculate what will be the fastest. Method 2 means 16*4*num_clouds bytes of data transferred to the gpu each frame, method 1 is d*4*num_clouds, while method 3 d*num_clouds, where d is 2 or 3 depending on whether you need z.

Worth noting is also that method 1 and 3 send the data in one batch, while method 2 sends 16*4 bytes at a time.

Since you are using GL ES 2 you could skip the matrix in method 2 and just send the translation as a vector, but you will still suffer from non-batched data transfer and the cost of setting a uniform per instance.

EDIT: Actually, what you would do in the case of many particles would be to set a uniform time, and have a velocity for the clouds as static attributes, and then animate them in the shader by multiplying the velocity with the time, and making sure they wrap around the edge if necessary. So you would only need to transfer 4 bytes per frame for a fully animated cloud scene.


I recommend you to read the particle article of "iPhone 3D Programming".

  • iPhone 3D Programming - Rendering Confetti, Fireworks, and More: Point Sprites

The title of this book includes 'iPhone', but this book explains OpenGL ES 1.1/2.0 generally. Thus you can use the knowledge from this book for Android or Android NDK.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号