Search Unity

Shader Language: GC or HLSL or GLSL?

Discussion in 'Shaders' started by MatheusMarkies, May 1, 2020.

  1. MatheusMarkies

    MatheusMarkies

    Joined:
    Apr 16, 2017
    Posts:
    67
    Good afternoon.
    I'm starting shader programming and I don't know which language is better at Unity.

    I have a question further: do Computer Shaders work only with HLSL? If so, they only work on DirectX

    If my project is intended for multiple platforms do I need the same Shader to be written in HLSL and GLSL?
     
    Last edited: May 1, 2020
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    There's no such thing as a shader language named GC, you're thinking Cg. Cg was the name of the shader language Unity originally used, and the letters "cg" are littered through out the shader code and even the official documentation, but the last usage of it was scrubbed about 5 years ago (though it had been mostly phased out even before that).

    HLSL is the language all of Unity's own shaders are written in. With most of Unity's built in shaders written in mainly DIrect3D 9 style HLSL (which happens to match Cg on most things, hence the confusion). The newer Post Processing Stack and SRPs are all written in Direct3D 11 style HLSL, wrapped in macros so it can easily be converted back to Direct3D 9 style HLSL for cross compiling into ESSL (GLSL for OpenGL ES, the mobile version of OpenGL).

    All shaders written in HLSL will be cross compiled into whatever form needed for the target API, be it OpenGL, OpenGL ES, Metal, or Vulkan. Assuming all features used that are supported by the target platform... we'll come back to that.

    You can write directly in GLSL (or ESSL), but those shaders will only run on OpenGL or OpenGL ES platforms and Unity will not cross compile from GLSL back to other platforms.

    Compute Shaders written in HLSL will run on Metal, Vulkan, and OpenGL ES, again as long as you don't do anything those platforms don't support. They will not run on OpenGL when using MacOS because MacOS doesn't support Compute Shaders with OpenGL, only Metal.

    https://docs.unity3d.com/Manual/class-ComputeShader.html
     
  3. MatheusMarkies

    MatheusMarkies

    Joined:
    Apr 16, 2017
    Posts:
    67
    Obrigado!
    Thank you!
    I wrote the "gc" wrong, I was referring to the CG.