Author Topic: Windows build compiling time/freeze issue and workaround  (Read 2844 times)

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 5137
    • View Profile
EDIT: the information below in this post relates to versions pre-6.4. From version 6.4 and up, a new "Build Options" section is available in the inspector that allows you to easily disable the shader features you are not using, effectively reducing compilation time and build size!

Hello there,

Some users have reached us asking for a fix or suggestions to speed up build time on Windows platform. This post tries to explain why Unity can take so much time compiling some complex shaders like Volumetric Fog & Mist, and a workaround to speed up this process.

Firstly we recommend you to sign up on this forum if you have not done before to grab latest update which will always include some nice improvements.

The reason a Windows build takes so much time (indeed it seems to hang but it will finish if you give it enough time...) is that Volumetric Fog shader uses lot of keywords to ensure the best performance. During the build process, Unity compiles a version of the shader for each platform (dx9, dx11, gles, …) and each keyword combination.
In the end, this can take a even some hours to complete, but once you build it once, it will be lot faster next time as Unity caches the build output of the shaders.

Now, there’s a workaround to speed this build process.

You need to edit VolumetricFog.shader file and locate the lines starting with "#pragma multi_compile xxxxx” where xxxxx are the keywords. Each keyword refer to a shader feature, for example, Fog of War, Point Lights or Light Scattering (read the documentation for a description of each keyword purpose).

Delete any of those keywords (or comment out the pragma multi_compile completely) that you don’t use .

As you reduce the number of multi_compile directives, the build process will speed up. But as commented before, just be patient the first time you launch the build.

This is a know issue with Unity – it seems that they’re improving it in future versions. On Mac the build process take 5-10 minutes as much since it only compiles for OpenGL platforms.

Ok, you may be asking, why does this happen with this shader and not others? Well, because we want the best performance for your game and because any extra instruction or code in the shader means less FPS for your game. We could have omitted the multi_compile directives and instead use classic “if” sentences, but that will affect shader performance anyway, since most of the time the GPU process in parallel blocks of code and ultimately can discard branch results that are not useful – but that means extra work for the GPU and can add lag to the main execution of the shader.

Hope this info helps – if you have any question regarding editing the shader, let me know.

Thanks.
« Last Edit: November 09, 2016, 04:51:10 AM by Kronnect »