Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

The size of shaders in an Android build is too large (~28Mb)

Discussion in 'Shaders' started by Lebrokholic, Jul 24, 2015.

  1. Lebrokholic

    Lebrokholic

    Joined:
    Jul 1, 2013
    Posts:
    19
    Here is the log:

    Textures 18.2 mb 29.9%
    Meshes 2.3 mb 3.7%
    Animations 5.3 mb 8.7%
    Sounds 0.9 kb 0.0%
    Shaders 28.0 mb 46.0%
    Other Assets 1.2 mb 1.9%
    Levels 1.2 mb 1.9%
    Scripts 662.8 kb 1.1%
    Included DLLs 3.9 mb 6.5%
    File headers 188.5 kb 0.3%
    Complete size 60.9 mb 100.0%
    Do you know what is the problem? I've used not so many materials, most of them are standard.
    Thanks for the following replies!
     
  2. jpease

    jpease

    Joined:
    Apr 18, 2013
    Posts:
    11
    The log should have a section right after that which says "Used Assets, sorted by uncompressed size:", you should be able to figure out which shaders are too large from looking at that list (or post the list here). My guess is that certain standard shaders are problematic and that using custom or mobile shaders would help.
     
  3. Lebrokholic

    Lebrokholic

    Joined:
    Jul 1, 2013
    Posts:
    19
    The sizes of materials in this section are about 0.4-0.8Kb. This is too little to affect the final size of an apk.
    However, I have smth like this:
    27.5 mb 45.1% Resources/unity_builtin_extra
    I strongly believe that this is a cause of my problem, but do not have any idea how to resolve it.
     
  4. Plutoman

    Plutoman

    Joined:
    May 24, 2013
    Posts:
    257
    It's probably all the multi_compile settings. You're most likely using a bunch of different standard shader variations, which are all compiled and used separately.

    You should consolidate the variations to a small set of 4 variations or some such. Every type changes it, as in, one with no normal map is one variation, one with one, is another variation, a fade transparent is one variation, a cutout is another, each one of those with or without normal maps... does that make sense?

    Every minute variation you have is a different compiled shader, even though it's built off the same core standard shader. Graphics cards do not branch efficiently like a CPU, so this is done to make sure that each variation actually performs quickly (it's essentially a necessity).
     
    ercion likes this.
  5. Lebrokholic

    Lebrokholic

    Joined:
    Jul 1, 2013
    Posts:
    19
    Thanks! I'll experiment with that.
     
  6. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    4,424
    You can use the new ShaderVariant to manually select the variants of a shader that you want so as not to include extra shaders variants in the build by mistake.

    Honestly, this is one reason why I hate the mega-shader approach and prefer the "Exact features I need" approach. It's far too easy for an artist to flip a couple of options when experimenting and end up with 50megs of shader variants in your build.
     
  7. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,869
    27 MB for a shader file?! That is massive!
     
  8. DarkCooker

    DarkCooker

    Joined:
    Jan 7, 2015
    Posts:
    101
    Hi Lebrokholic, I found the same problem that shader size is large after build and the Unity_BuildIn_extra is also large

    How can you resolve this problem?

    Thanks very much
     
  9. Lebrokholic

    Lebrokholic

    Joined:
    Jul 1, 2013
    Posts:
    19
    Frankly, I didn't find a solution. It was a part of my previous job, today I don't experience such a strange behavior of Unity. Sorry.
     
unityunity