Search Unity

HLSL and CG are the same?

Discussion in 'Shaders' started by KillerSneak, Jan 23, 2011.

  1. KillerSneak

    KillerSneak

    Joined:
    Jan 9, 2011
    Posts:
    38
    So I'm new here (to unity3d) and was reading up a little on the shaders. Now as far as I understand is that the HLSL and Cg are the same thing, co-developed by Microsoft and nVidia?

    The only difference being that Cg can be compiled for DirectX and OpenGl where HLSL can only compile for Microsofts DirectX api.

    I hope someone can help me out a bit here so i can understand it a bit more, If this was/is to be true almost any HLSL shader could be compiled as CG shader as well? This also means that many of the free on the net HLSL shaders should be able to be used with Unity3d?

    Hope someone can shed some light on this for me.
     
    Last edited: Jan 23, 2011
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    According to Aras (Unity's lead graphics programmer) HLSL is identical to Cg for most purposes - he explains the matter in this thread.
     
  3. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Yes, the language itself is the same for all practical purposes.

    However, that does not mean you can take any random shader from the internet drop it into Unity and expect it to work. Any shader is bound to work only if shader "interfaces" with the underlying engine/technology the way the underlying engine expects it to. For example, built-in matrices have to have proper names or semantics, and so on.