Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Best transparent shader for leaves on mobile [android]

Discussion in 'Shaders' started by pretender, Jul 21, 2015.

  1. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    Using standard shader properly selectes cutout but performance is not good. Using "Nature/Tree Creator Leaves Fast" gives better performance. Is there any guidelines in getting good framerates for leaves/trees and what is the best shader for mobile for these kinds of things?

    Thanks!
     
  2. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    I would suggest doing the least pixel operations in your shader, and only use alpha testing when it's absolutely necessary.
    The standard shader is something I wouldn't recommend for mobiles anyways, since I find the performance is terrible, like you just found out.
     
  3. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    so what do you propose?
     
  4. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Well, I custom write my shaders, but for you, just chop and change and see what works. :) if you can also write your own, I suggest doing that if you're that concerned, that way, you can squeeze out the best performance possible.

    If, however, using the tree creator shader looks fine, then I would suggest leaving it at that. It's that simple. :)
     
    jubaerjams8548 likes this.
  5. jubaerjams8548

    jubaerjams8548

    Joined:
    Jun 8, 2020
    Posts:
    33
    Hey @FuzzyQuills buddy, Can i get a little help?, actually im using a foliage sway shader which is using alpha blend, but when i am getting close to the objects....performance is getting dropped...can I show you the shader.... if you please give me dome tips to make it highly performant , as im using it in mobile....
     
    Last edited: Nov 4, 2022
  6. jubaerjams8548

    jubaerjams8548

    Joined:
    Jun 8, 2020
    Posts:
    33
    @FuzzyQuills bump!
     
  7. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    692
    It's not like there is some magical shader that will make performance way better. Alpha clip is still known to be slow on even modern mobile devices due to overdraw.

    Your best bet is to limit the amount of overdraw by limiting the amount of overlapping alpha cards. Also see if maybe instead of more overdraw you can exchange it for a more complex mesh that fits the alpha region better.

    From my tests, spending more time in the vertex shader is often worth it if it involves spending less time "overdrawing" pixels.

    Also, all that being said, reducing the complexity of your fragment shader certainly will help with overdraw performance. Also calling discard() at a reasonably early moment in your fragment shader will be important as well.
     
  8. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    631
    Hi, I think it is because of severe overdraw.

    For many overlapping leaves, using high-poly modified meshes (rather than quads) can increase the overall triangle counts a lot.

    So you should pay attention to the triangle counts when modifying the mesh.

    Another way is to try URP and use Alpha Clipping (need to test it by yourself because there's no extremely simple shaders in URP by default).

    If you are using URP or HDRP (obviously not), you can enable Depth Priming (DepthPrepass in HDRP) to reduce the cost of opaque overdraw, especially when mobile Early-Z is off because of Alpha Clipping.

    For BIRP (non-scriptable RP), I'm not sure if it's easy to implement DepthPrepass by yourself.