Search Unity

GLSL Compatibility

Discussion in 'Shaders' started by kittik, Jun 28, 2018.

  1. kittik

    kittik

    Joined:
    Mar 6, 2015
    Posts:
    565
    I am learning the GLSL language, and I am wondering if GLSL shaders are fully compatable with Unity. I have read that GLSL is a shader aimed towards OS X and Linux devices.

    Can anyone advice that if I use GLSL with #include "UnityCG.glslinc";, on a Windows or another system will it display the final shader, without any performance issues?

    Thank you for the clarification.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    GLSL is a shader language aimed towards the OpenGL API, variants of which are used on MacOS, Linux, Android, iOS, web browsers, and many more platforms, including Windows.

    By default Unity runs using Direct3D on Windows, and shaders written using GLSL will not be displayed (it'llshow as a solid #FF00FF or potentially the fallback shader if one is assigned). You can force the Windows version of the Unity editor to run in OpenGL mode, and you can remove Direct3D as an available API for standalone PC builds. As for are they fully compatible or not, it depends on the GLSL you're writing, as not all versions are compatible with all platforms. Generally yes, though you are giving up some performance options by going strictly OpenGL on Windows and MacOS or iOS (which now both default to using Metal), but in generally a basic shader written in GLSL that runs on all platforms should run just as well on all those platforms.


    I would however suggest you use HLSL instead as Unity can convert your shaders over to GLSL (in it's many flavors), as well as Metal's shading language and many others to try to maximize performance for those platforms.
     
    kittik likes this.
  3. Przemyslaw_Zaworski

    Przemyslaw_Zaworski

    Joined:
    Jun 9, 2017
    Posts:
    328
    Enable OpenGL in Unity3D -> set -force-glcore parameter to editor executable, for instance: "C:\Program Files\Unity\Editor\Unity.exe" -force-glcore

    You can also to try mimic GLSL keywords in HLSL, for example:

    #define mix lerp
    typedef vector<int,2> ivec2;
    typedef vector<float,2> vec2;
    etc.
     
    DavidSWu and kittik like this.