Search Unity

Hiding your shader code

Discussion in 'Shaders' started by ClosingTime, Mar 15, 2018.

  1. ClosingTime

    ClosingTime

    Joined:
    Nov 23, 2016
    Posts:
    241
    A big issue with OpenGL is that you need to provide the source code in glsl with the deployed app.
    With DirectX you can just ship the binaries of the shaders instead of the source code.
    Perhaps Vulkan can do that as well.

    How can you verify that your shaders source code don't get into your app for everyone to see in Unity?

    Let's divide it to every platform:

    Android
    iOS
    OsX
    Windows
    Linux

    And with the technologies to use:
    Unity Shaders "template"
    Vulkan Binaries(?)
    DirectX Binaries(?)
    Metal Binaries(?)
    Something else?

    I think it's appalling that your shaders source code get distributed.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    They're semi-obfuscated versions of the shaders, but un-compiled shader code is required by OpenGL so there's nothing you can do about this.
     
  3. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,243
    It always has to be unpacked when on GPU.
     
  4. ClosingTime

    ClosingTime

    Joined:
    Nov 23, 2016
    Posts:
    241
    The difference is that you ship binaries in shader assembly in DirectX and in OpenGL you ship text files.

    That is my question, how to avoid OpenGL deployment in unity. There are alternative to OpenGL even on Android and iOS, such as Vulkan and Metal
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    You can select which APIs to use per platform in the player settings, but I believe OpenGL ES 2.0 shaders are always deployed for iOS builds to support older iOS devices which don't support Metal.

    If you set the minimum OS version to iOS 11 it shouldn't need those anymore, as iOS 11 is only supported on devices with Metal. However it may still include GLES shaders (I don't know, I've never checked). If it does then you can set your own shaders to use #pragma target 3.5 which will prevent then from compiling to GLES 2.0. The shaders may still be included, but the code should be from their fallbacks if they have one.
     
  6. ClosingTime

    ClosingTime

    Joined:
    Nov 23, 2016
    Posts:
    241
    Ok thanks.
    Now, is there an option to provide Unity only with shader binaries instead of source code?
    For instance I compile the shaders externally and then only provide the binaries?
    Can it use shader binaries?
     
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    No.