Search Unity

Particles are SLOW on Android/iPhone

Discussion in 'iOS and tvOS' started by Darknuke, Apr 4, 2011.

  1. Darknuke

    Darknuke

    Joined:
    Jan 31, 2011
    Posts:
    223
    I have a single particle effect running on my phone (a flamethrower) so far. My game runs at a solid 50 fps (tho I know i'm probably only getting 30 since it's a phone), but when I use this particle, it drops to 3-5 fps.

    I'm not budgeting very many particles to this effect, but particles do get created and destroyed very often since it is a flamethrower.

    My question is, does the phone just run particles poorly or is it the fact that I'm creating and destroying particles so often that I'm lagging? If the latter, what would you recommend I do to fix that? I have heard of people spriting their particles, but I would like to avoid that if possible (seems like a lot of extra work).
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    The particles are not the problem, the problem is the overdraw from the stacking transparent particles.

    on 3GS it likely should run fine but on 4th gen hardware and the ipad, if you run them at native resolution, the overdraw (redrawing pixels already drawn this frame, which with transparent happens and with particle systems even more, the larger the particles the worse it becomes) is normally too much for the hardware to take and the performance will die as you want to render more pixel per frame (at 30FPS) than you technically can at all

    you can test this by temporally using diffuse instead of a particle / transparent shader so you get a feeling for the impact of overdraw
     
  3. Darknuke

    Darknuke

    Joined:
    Jan 31, 2011
    Posts:
    223
    Thanks. That is very useful information. I didn't realize that could be a problem. I'll keep that in mind if I run into optimization problems with particles when I start calling a ton of them. I'll be sure to use as little transparent particles as I can.

    I did find out what my issue was though. I didn't put in a timer for the particles/bullets that were coming out for the flamethrower so it was calling every frame. Woops >_<.
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    particles every frame is not needfully bad, question is how many you emited each frame and how large they are ;-)

    But good to hear that you found the culprit and got him ass kicked
     
    FranklinDasJV likes this.
  5. nickazg

    nickazg

    Joined:
    Jan 9, 2012
    Posts:
    7

    So just to clarify, transparent particle do you mean the transparency/Alpha of the color like the settings under particle animator. Or are you referring to the actual shader (Particles/Alpha Blended Premultiply). Btw when i change the shader to diffuse the particles disappear ??
     
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    He means the shader + overdraw. You see, when you draw something that is transparent, over something else that is transparent you are suffering a phenomenon known as overdraw. Things drawn on top of other things.

    When using an opaque shader such as vertex lit, or diffuse, the iOS hardware is able to prevent overdraw by culling it in hardware so a lot less fill rate is used.

    TLDR / DID NOT UNDERSTAND VERSION:

    Try to minimise anything you can see through from drawing on top of other stuff that you can see through. The hardware is bad at it.
    You can try spreading the particles further apart. You can try bigger particles, but less of them. Use your imagination.
     
  7. nickazg

    nickazg

    Joined:
    Jan 9, 2012
    Posts:
    7
    Ahh thanks i get it now. Lol im trying to make water, I guess its gunna have to be a pretty awesome texture :D. Just wondering is there a way of and a bump/normal map to a particle material?
     
  8. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    Yeah, it takes a fair bit of experience to get particles right. Generally speaking:

    - Minimise the number of particles you need to emit, because each particle needs to be simulated.
    - Make the particle texture as dense / opaque as you can, so that you can use the smallest number to add the required amount of colour.
    - Make sure you maximise the use of your texture space. Blank-looking pixels cost as much to blend as opaque ones.
    - Make the size of individual particles as small as you can, because every pixel matters.

    Of course, the whole thing's a balancing act, especially the first and last points there. Using larger particles can often mean using less particles, but if there's then a lot of overlap you'll be killing your overdraw... Practise and experience is the way to go.
     
  9. rohit_212

    rohit_212

    Joined:
    Oct 29, 2013
    Posts:
    1
    thanks it helped me alot:p
     
  10. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    http://blogs.unity3d.com/2012/03/23/shadowgun-optimizing-for-mobile-sample-level/

    GPUs on mobile devices are designed to avoid drawing each pixel more than once.

    Think of it this way. How do you draw a teapot? Well, firstly you draw the sky. Then you draw the clouds and the trees. Then you draw the bus on the road, and the garden gate. Next you draw the walls of the house, then the wallpaper, and then the cupboard on the wall. Next you draw the table, and finally (hooray!) you draw the teapot. This is how all rendering engines work. Clearly it's stupid. So, modern (PC/console) engines use something called occlusion culling. This stops the stupid rendering of stuff that is not visible. Mobile devices can support occlusion culling, but their GPUs are designed to figure out what's visible on the screen. They do not typically use a z-buffer for this. Instead, they use a tile-renderer, where triangles are sorted into the tile where they fall. These lists of triangles per tile are then sorted. The GPU is thus effectively doing a per-triangle occlusion cull. Now, for opaque geometry this operation is fast and effective. For semi-opaque geometry, this sorting is much more complex. It's this sorting that consumes time. Worse, the GPU will have to run pixel shaders on all of these semi-transparent triangles, so the pixels are drawn multiple times - overdraw.

    In short, find a way to get your particle effect without using particles.
     
    FranklinDasJV, XeroxisLabz and digzou like this.
  11. Kurius

    Kurius

    Joined:
    Sep 29, 2013
    Posts:
    412
    I'm wondering why in this case the older hardware would have better performance than the newer hardware?
     
  12. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Because the 3GS almost has the same GPU as the 4 and iPad1, but those 2 have almost 4 times the screen space to draw, so it'll have to work 4 times harder. Doesn't apply to 4S, iPad2 and above though. The time of writing was quite old - 2011.

    The iPhones from 4S onward get progressively faster, so you don't have that issue.

    The iPads get a bit slower as they move to retina res, then regain the speed. So the iPad3 might be a little slower at native res, but the iPad 4 gets a bit faster again, and the iPad Air gets faster still (at native res) - for fill rate. Triangle throughput is a bit varied from device to device but that's rarely ever a bottleneck.
     
  13. Kurius

    Kurius

    Joined:
    Sep 29, 2013
    Posts:
    412
    Thanks for that nicely detailed response!
     
  14. bobeogames

    bobeogames

    Joined:
    Feb 9, 2019
    Posts:
    20
    I ran into the same problem on my android game. For anyone may interest, the solution I found is change the Shader of Material of the particle to Mobile/Particles/Additive (the one used for mobile I think) and it resolves the problem.