Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Why are GLSL shaders only reccommended for testing?

Discussion in 'Shaders' started by Startec, Nov 10, 2015.

  1. Startec

    Startec

    Joined:
    Nov 10, 2015
    Posts:
    12
    Hello,

    I am a programmer with some experience in GLSL and no experience in other shading languages. I read in the manual that "use of raw GLSL is only recommended for testing" (http://docs.unity3d.com/Manual/SL-GLSLShaderPrograms.html)

    This is somewhat dissapointing as I was hoping to be able to write shaders for unity. Can someone explain the logic behind this, and if, in truth, it is okay to use our own GLSL shaders?
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    The standard shader language of Unity enables conversion to all shader languages, while GLSL does not as far as I know. The differences between GLSL, HLSL and unity shaders are not that big. The most noticeable is probably the way variables are defined. Where you define a vec4 in GLSL, you define it by type in HLSL and unity. (float4, half4, fixed4.) If you look at some shader examples, it should be fairly recognizable.
     
    Startec likes this.
  3. StevenGerrard

    StevenGerrard

    Joined:
    Jun 1, 2015
    Posts:
    97
    The reason not recommend use GLSL maybe " Compatibility ".
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    On Windows the Unity runs in Direct3d mode by default. If you write your standers in GLSL you'll need to force the Windows player to only use OpenGL. Also if you're using Windows you'll need to force the editor to use OpenGL with a command line or the shader won't render in the editor.

    Unity's shaderlab is normally written in CG, a subset of HLSL, which allows it to take any shader written and automatically convert it to GLSL, HLSL, and the custom shader languages used for consoles and automatic handling of various texture formats for the different platforms which makes things much more portable. If you write your shaders as GLSL directly you loose all of these benefits. As far as going from GLSL to CG the basics are nearly identical. It's just a matter of translating vec4 to float4 and mix to lerp, etc. If you look around you can find tables that show the GLSL and HLSL equivalents for various commands.
     
    Startec likes this.
  5. marcSP

    marcSP

    Joined:
    Jan 13, 2016
    Posts:
    7
    and... what about performance?
    can you tell me guys wich one is best on the latests unity? (I'm talking about iOS & Android only)

    With previous unity versions, I have the impression that GLSL was ther winner (mainly because it was not translated at all so you could be extremely picky with the precission and other performance tricks)

    However, nowadays I'm not sure...
     
  6. CPXTom

    CPXTom

    Joined:
    Apr 24, 2010
    Posts:
    113
    We've written the majority of our shaders in GLSL, but we're developing on OSX and our games have been primarily mobile. As @marcSP mentioned we did it for performance reasons, also not sure if this is still a concern though. We have had to write the odd CG shader here and there because GLSL isn't supported very well with Unity's shader library. Anytime I need a shader that is going to be integrating with Unity's lighting system, I usually need to write a CG shader.