Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

VS 2012 and 2013 CG Syntax Highlighting (no plugins required)

Discussion in 'Shaders' started by braaad, Jul 4, 2014.

  1. braaad

    braaad

    Joined:
    Oct 4, 2012
    Posts:
    102
    After reading the NShader thread on here a while back I did some investigating. VS2012/13 have hlsl support and since CG is almost identical, you can associate .shader and .cginc files with hlsl and get accurate highlighting.

    The only way I found to do this (if someone has a way in the actual IDE please do share but I gave up) is to add registry entries.

    Warning: Don't edit the registry if you don't know what you are doing.

    You can save the below text as .reg files and run them, alternatively you can navigate to the path specified and add them manually. With regard to the extension GUID, this should be the same on all installs as it is consistent on mine, however it might be worth checking yours out just in case. You can find it by looking here in your registry HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0_Config\Languages\File Extensions\.hlsl or for 2012 here HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0_Config\Languages\File Extensions\.hlsl

    It is also worth noting that you can associate other types to hlsl here also buy just changing .shader to whatever you want.

    Windows Registry Editor Version 5.00

    [HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0_Config\Languages\File Extensions\.shader]
    @="{B2F072B0-ABC1-11D0-9D62-00C04FD9DFD9}"
    "HLSLFile"=dword:00000001

    [HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0_Config\Languages\File Extensions\.cginc]
    @="{B2F072B0-ABC1-11D0-9D62-00C04FD9DFD9}"
    "HLSLFile"=dword:00000001

    Windows Registry Editor Version 5.00

    [HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0_Config\Languages\File Extensions\.shader]
    @="{B2F072B0-ABC1-11D0-9D62-00C04FD9DFD9}"
    "HLSLFile"=dword:00000001

    [HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0_Config\Languages\File Extensions\.cginc]
    @="{B2F072B0-ABC1-11D0-9D62-00C04FD9DFD9}"
    "HLSLFile"=dword:00000001

    Like I said before if there is an easier way of doing this please let me know, but for now this works.
     
  2. Nims

    Nims

    Joined:
    Nov 11, 2013
    Posts:
    86
    Thanks for the find, unlike the previous solutions the color highlighting is much better this way.
    But still the lack of intellisense is annoying (So I have reverted to editing shaders in SublimeText ).
     
  3. braaad

    braaad

    Joined:
    Oct 4, 2012
    Posts:
    102
    Intellisense would be nice but I can pretty much count on one hand the amount of functions that I regularly use (mul, dot, max, lerp, pow, exp, saturate) and shaders compile almost instantly so iterations are fast. Being able to edit the shader along side my regular project definitely outweights no Intellisense, for me anyway.
     
  4. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    In VS2015 you can set this up in the IDE itself by going to Tools > Options > Text Editor > File Extension and adding the extension and associating it with the shader editor. I thought this was also possible in 2013 but I can't find the shader editor editor type in the list on the PC I'm on at the moment (I swear I saw it on my work PC though).
     
  5. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
  6. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Yeah his tool is much more advanced. I'm actually using it myself now!
     
  7. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    Have you found a combination of the settings that keeps it from messing up the indents due to thinking there are errors on Unity-specific stuff earlier in the file?