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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Mobile dissolve shader

Discussion in 'Shaders' started by Catinightmare, Nov 11, 2014.

  1. Catinightmare

    Catinightmare

    Joined:
    Sep 18, 2013
    Posts:
    11
    I would like to create explosion effect that uses dissolve shader(transparent cutout, animating the cutout value).

    I know that alpha-test is expensive in mobile platforms due to the clip instruction in the cutout shader.
    I tried to replace the clip instruction by if-else but it is as bad as using clip instruction. Is there any other way I can create a cheap dissolve shader for mobile?

    thanks for help >_<
     
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Why not output an alpha value and use alphablend instead? ie alpha of 0 is hidden?
     
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,448
    Sounds like it's about tile-based deferred rendering on iOS. Did you read the OpenGL ES Programming Guide for iOS by Apple? You want to read the Use Hidden Surface Removal Effectively paragraph, this should clarify things :)

    BTW: rather than an if/else branch, you can use the step intrinsic to mimic if/else, which was the preferred approach "back then".
     
  4. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Also if youre writing your own cg, make sure to use fixed or half precision where possible. fixed is good enough for colors, and helps performance. And get rid of any lighting or extra stuff you don't need. Don't use a surface shader. I would think outputting an alpha value and just using alpha blending should be ok?
     
  5. Catinightmare

    Catinightmare

    Joined:
    Sep 18, 2013
    Posts:
    11
    Thanks so much for your hints Peter77 and imagniaryhuman! I modified the code to use 'step', and the shader is alpha blend that alpha = 0 when it is smaller than the cutoff value.

    I build the demo scene to my android phone with exactly the same particle effect:
    one using Mobile/Particles/Alpha blended shader --> frame-rate keeps at 50 fps
    [ii]
    one using the modified "cutout" alpha blend shader --> frame-rate drops from 50+fps to 28fps
    [iii]
    one using the original cutout shader that is using the clip instruction --> frame-rate drops to 20fps

    Is the frame-rate drop in [ii] because of the "step" intrinsic? as "step" is doing a simple if else instruction (branching?)
     
  6. Catinightmare

    Catinightmare

    Joined:
    Sep 18, 2013
    Posts:
    11
    the above result is from my phone samsung galaxy s (i9000).

    i just test the shaders on galaxy s3, frame-rate of and [ii] are same.
     
  7. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I think the point of `step` is that it does a direct conversion of the data, bypassing any decision making. I don't think it does any kind of branching as such.