Search Unity

Standard Shader Variants Size in WebGL Scene Bundles

Discussion in 'Shaders' started by bigbrainz, Feb 14, 2019.

  1. bigbrainz

    bigbrainz

    Joined:
    Jul 21, 2015
    Posts:
    177
    Bundle size is critical for us and shaders seem to be taking up far too much space. For example, we made some test scene bundles ranging from 5 to 22 spheres with moderately complex materials on them. There is 1 mixed soft-shadow directional light and one point light with soft shadows. See below.

    The textures for the materials ended up totaling roughly 2.6 MB and we put those in separate bundles.

    With a plain Standard shader material assigned to all spheres the bundle size is just .3MB
    Using just 5 materials, each with diverse usage of the Standard shader bumps the bundle size up to 4.6 MB
    With 22 materials, we introduce a few more variations of features we're using from the Standard Shader and that bumps the bundle size up to 7.4 MB.

    SO . . . just 5 shaders is adding 4.3 MB. A few more is bumping it to 7MB.

    1. That seems unreasonably heavy to us. We fight for scraps of each MB and it seems excessive that the Standard Shader would be so cavalier about adding so much to the bundles. Does this seem reasonable to others? Our schools often have hundreds of kids downloading thousands of bundles using a single poor connection so any extra MB is critical.
    2. It appears the bulk of the problem is that it's building thousands of shader variants, even though we seem to only need between 5 and 22. Is there some way to get the Standard shader to cut WAY down on what it's packing in to the bundles?
    3. Is there some kind of shader we can buy (or make) that can be much lighter? Perhaps by simply not pulling in so many shader variations?
    4. What else can we do to get rid of all this shader bloat in all our scene bundles?
    I've submitted this test as bug #1125735, but I haven't heard anything back from Unity yet.

    Notes:
    • These tests were all done in 2018.3.5
    • We've already gone through our materials and tried to make sure we're aligning how each material uses the Standard shader so we get as few variations as possible.
    • We tried switching to the mobile shader. It's much smaller, but we really do need better looking textures much of the time.
    • We looked into limiting shader variations via keywords, but it seems this is not possible with the Standard Shader.
    • The really wasteful part is that it loads basically all these same shader MBs into EVERY scene bundle. They're slightly different, but even if we could just get one Shader bundle that could be re-used with all scenes that would be vastly lighter.


    upload_2019-2-13_16-44-35.png
    upload_2019-2-13_16-45-11.png

    It's really a shame when we whittle nice scene like these down to 6MB and just the dumb shader variants DOUBLE it up to 12 MB. There's got to be a better solution out there . . .

    upload_2019-2-13_17-9-48.png
    upload_2019-2-13_17-10-48.png
     
    Last edited: Feb 14, 2019