Search Unity

Resolved Why is the dither node so expansive on mobile ?

Discussion in 'Shader Graph' started by Wasplay, Apr 9, 2020.

  1. Wasplay

    Wasplay

    Joined:
    Jun 2, 2018
    Posts:
    46
    This simple shader makes my game drop from a steady 60 to 30fps :
    upload_2020-4-9_20-48-57.png

    I thought using an opaque dither gradient instead of a smooth transparent gradient would improve performance but I was apparently wrong !
    Am I using it the wrong way ?
     
  2. Elizabeth_LeGros

    Elizabeth_LeGros

    Unity Technologies

    Joined:
    Jan 7, 2020
    Posts:
    50
    you are setting the dither output to the alpha clip value, but I am not certain why you would want to change that rather than just multiplying/masking your gradient alpha by the dither output. Could you also check the settings on the pbr master node and make sure its set to be opaque and not transparent. What are you targeting as well?
     
  3. Wasplay

    Wasplay

    Joined:
    Jun 2, 2018
    Posts:
    46
    I set the dither output to the alpha clip because that's what the documentation recommands :
    https://docs.unity3d.com/Packages/com.unity.shadergraph@7.3/manual/Dither-Node.html

    The PBR master node is set to opaque, and the target platform is Android.
    I wanted to convert this :
    upload_2020-4-9_22-55-13.png

    To this :
    upload_2020-4-9_22-54-47.png

    To improve performance, but it makes it far worse, so I'll just stick with the transparent one ! (and it looks far better)
    However I don't know and I don't think it's a normal behaviour, opaque shaders should be faster right ?
     
  4. Elizabeth_LeGros

    Elizabeth_LeGros

    Unity Technologies

    Joined:
    Jan 7, 2020
    Posts:
    50
    Doh! My bad. :)

    The general rule of thumb is certainly that opaque materials are easier to draw than transparent ones unless the overhead for "faking" the transparency gets too large. If you are familiar at all with profiling shaders, it would be worth seeing why it seems so much more expensive. I am not too familiar with mobile performance of different shader operations however, so someone with more experience may have a better answer for you.
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    “Opaque” shaders are more efficient, but only if they’re fully opaque. Any alpha testing (what the alpha threshold does) actually makes them much, much slower. A single alpha tested object compared to a single transparent object, I’d guess the alpha tested object is 2-3 times slower to render, and also makes everything else that renders after it slower too. They’re pretty bad for mobile.

    If you really want to make the above faster, don’t use transparency. Instead lerp the albedo to black and emission to the fog color with the inverse of the value you were using as the alpha. You may need to use the Specular work flow and lerp the Specular color to black as well.
     
  6. Wasplay

    Wasplay

    Joined:
    Jun 2, 2018
    Posts:
    46
    Thanks a lot for your answer ! I didn't know that.
    I can't fade to a single color since the skybox looks like this (I disabled it in the screenshots above) :
    upload_2020-4-10_13-42-39.png
     
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Depending on how you’re doing your skybox, you could probably reproduce the skybox in the object’s shader using the screen position and/or view direction so you can fade to the exact same pattern while keeping things opaque.

    Or just leave it transparent and don’t worry about it too much.
     
    look001 and Wasplay like this.