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

Unity 4.5: iOS Player Setting "Graphics Level: Automatic" can lead to shader compile bugs

Discussion in 'iOS and tvOS' started by IVxIV, Jul 31, 2014.

  1. IVxIV

    IVxIV

    Joined:
    Nov 13, 2013
    Posts:
    15
    Hello,

    I wanted to call attention to an issue that just bit us in the butt recently on our iOS game, just in case anyone else could be affected similarly, related to Unity 4.5 and (I suspect) the new way that shaders are handled.

    We upgraded our project to Unity 4.5 a while back, but only just now got to the point of performing a comprehensive test pass on our game across the spectrum of iOS devices. During this test pass, we discovered to our surprise that the app was broken on the iPhone 5S, iPad Mini 2 and iPad Air (the UI rendering was completely borked and the app totally unusable). We connected Xcode to one of these devices and discovered that it was a shader compile error, specifically:

    -------- GLSL error: ERROR: 0:6: '' : #version must occur before any other statement in the program

    The full error output, as well as the shader source, is attached. This shader pulls in a number of other Unity cginc files as well.

    With a bit of debugging, we narrowed the cause of our problems to the iOS Player Setting "Graphics Level" which was set to "Automatic". What this appeared to be doing was to cause our shaders to compile for OpenGLES 3.0 on these newer devices which support GLES 3.0, however the shader source generated by the project with this setting had the compilation issue mentioned here. To resolve this issue, we changed the "Graphics Level" player setting to "Force OpenGL ES 2.0".

    I looked through the history of our ProjectSettings.asset file, and prior to upgrading the project to Unity 4.5 we had been using the "Force OpenGL ES 2.0" setting, and I suspect that it was human error on the part of our team that caused this setting to get switched to "Automatic" when we upgraded our project to Unity 4.5. Nevertheless, I wanted to share our experience as a cautionary tale to anyone else developing for iOS - if you use the "Automatic" setting for "Graphics Level", be sure to test on the full range of your supported devices, as it appears that the "Automatic" setting can result in shader code which will potentially not compile at runtime!
     

    Attached Files:

  2. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Hi, thanks for the nice posting.

    I also have had similar issues with other devices - such as the Blackberry Z phones.
    This new feature I thought would be great and set a number of my projects to "Automatic" assuming Unity would select the best option for the devices, it seems I encounter various shader issues and glitches.

    To me this feature is young and still very buggy, needs to be tested on more mobile devices to see if it works accurately. I will also make sure I change this to OpenGL 2.0, but in future if making a new game from scratch on latest Unity3d I expect this to be working correctly.

    Thanks to the original poster, please file a bug with Unity :)
     
  3. IVxIV

    IVxIV

    Joined:
    Nov 13, 2013
    Posts:
    15
    Sorry to hear it's hit you as well; bug report has been filed :)
     
unityunity