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

Tutorial: How to use NShader with Unity shaders

Discussion in 'Shaders' started by IJM, Oct 21, 2011.

  1. IJM

    IJM

    Joined:
    Aug 31, 2010
    Posts:
    143
    "NShader is an extension to Visual Studio 2008/2010 that provides syntax highlighting for various shader languages including HLSL - GLSL - CG.."

    Step 1:
    Download and Install NShader
    http://nshader.codeplex.com/

    Step 2:
    Go to this folder:
    <VsInstallRootFolder>\Common7\IDE\Extensions\Alexandre Mutel\NShader\version\

    Step 3:
    Open "NShader.pkgdef" in notepad.

    Step 4:
    Add this:
    Code (csharp):
    1. [$RootKey$\Languages\File Extensions\.shader]
    2. @="{479b8c71-c9de-3669-869d-ae1d91602d7c}"
    under this:
    Code (csharp):
    1. "CodeBase"="$PackageFolder$\NShader.dll"
     
    Last edited: Oct 21, 2011
  2. the_Simian

    the_Simian

    Joined:
    Mar 13, 2011
    Posts:
    37
    Thank you, you are an internet hero.
     
  3. T-Strijker

    T-Strijker

    Joined:
    Apr 12, 2010
    Posts:
    26
    Nice this will help me learn how to make shader a little bit easier :)
     
  4. homeros

    homeros

    Joined:
    Dec 23, 2009
    Posts:
    121
    I have vs 2010 and I've installed this plugin. But even after changing the .pkgdef file like you said I get either a freeze or an empty blue square when trying to open .shader files. Do you have any idea what the problem might be?
     
  5. Fundead

    Fundead

    Joined:
    May 14, 2012
    Posts:
    21
    Coincidentally, homeros, I went looking for the exact same solution and wound up here too, only to run into the same crash you did. The fix is that IJM's solution no longer works with the latest NShader 1.3 version - but works perfectly with the older 1.2 version. Grab it here and apply the above addition to the .pkgdef file and you'll have .shader code highlighting working perfectly:

    http://nshader.codeplex.com/releases/view/59952

    And thanks, OP, for the initial fix. Shader coding with sexy highlighting, woohoo!
     
  6. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    Great~But unity shader is not the same as these ,So, Nshader how work in Unity?
     
  7. retypeNick

    retypeNick

    Joined:
    Sep 17, 2012
    Posts:
    12
    Any idea, how to get this work with 1.3 :/
     
  8. MADmarine

    MADmarine

    Joined:
    Aug 31, 2010
    Posts:
    627
    Works great with the 1.2 release for me.
     
  9. hrjunker

    hrjunker

    Joined:
    Nov 15, 2011
    Posts:
    26
    Hi guys here is the solution if you are using the NShader 1.3

    1) Close your VS2012 (or VS2010)

    2) Edit the NShader.pkgdef located in YOUR_DRIVE:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\a_cryptic_subfolder (search for it in extensions directory). 10.0 for VS2010 version.

    3) Add the following line to NShader.pkgdef (where other extensions are):

    [$RootKey$\Languages\File Extensions\.shader]
    @="{4c554917-0eb7-3742-9f6b-f2f529fc6729}"
    4) Then to be sure that everything is going to be highlighted correctly, open a registry and remove the following registry (be careful!):

    HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\FontAndColors\Cache

    HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0_Config
    Launch VS and It should be ok.

    Credits: http://nshader.codeplex.com/discussions/394745
     
  10. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,972
    Thank you, works great.
    Life is a bit easier.
     
  11. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
  12. jesta

    jesta

    Joined:
    Jun 19, 2010
    Posts:
    293
  13. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,972
    To support .cginc files add also
    [$RootKey$\Languages\File Extensions\.cginc]
    @="{4c554917-0eb7-3742-9f6b-f2f529fc6729}"

    Thanks again
     
  14. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Did anyone manage to get this work in VS2013??
     
  15. Grespon

    Grespon

    Joined:
    Apr 13, 2012
    Posts:
    388
    Amazing. Working on VS 2012 following hrlarsen recipe.
     
  16. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Turned out in VS2013 the Rootkey were different...
     
  17. skalev

    skalev

    Joined:
    Feb 16, 2012
    Posts:
    264
    just in case anyone didn't figure it out on their own, you should probably add:

    [$RootKey$\Languages\File Extensions\.cginc]
    @="{4c554917-0eb7-3742-9f6b-f2f529fc6729}"

    as well, so that formatting and coloring works for CGINC files as well.
     
  18. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    this VSIX package is not working for VS2013... would be nice to get a NuGet one going...
     
  19. Nims

    Nims

    Joined:
    Nov 11, 2013
    Posts:
    86
    Trying to get NShader to work in VS 2013 - still no luck.
    I am using the release from here:
    https://nshader.codeplex.com/discussions/462583

    Deleted the key:
    HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\FontAndColors\Cache.

    And then added the following:
    [HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0_Config\Languages\File Extensions\.compute]
    @="{4c554917-0eb7-3742-9f6b-f2f529fc6729}"

    [HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0_Config\Languages\File Extensions\.shader]
    @="{4c554917-0eb7-3742-9f6b-f2f529fc6729}"

    Still no luck after restarting VS 2013, still no color coding - Any suggestions would be appreciated.
    Do I need to delete this key?
    HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\ 12.0_Config
    (To scared to try it out - as i didn't see anything about doing this regarding installing NShader in VS 2013. - Please note this is the 12.0_Config NOT the 11.0_Config).
     
    Last edited: Apr 21, 2014
  20. S-ed

    S-ed

    Joined:
    Jan 12, 2013
    Posts:
    2
    Ok. Here's small update:
    http://www.jostavo.net/NShader.rar (it's a new fork for 2013 by SilentSouls that uses embedded coloring, the one Nims mentioned before)

    I've added support of .shader, .compute, .cginc (sorry just handling not native support, see attach)

    *optional* - in VisualStudio go Tools > Extensions and Updates find NShader and uninstall it, reboot studio (it need to be restarted to remove files)
    Make sure Visual Studio is closed

    Who afraid to download my file, install one from jostavo.net and then create and add .reg:
    For future updates:
    {af99cc5c-2a8a-3547-b255-896525bc39d1} - is UUID for current build only!

    To find one You needed - open NShader.pkgdef and look for:
    Or after install go
    There will be yours.
     

    Attached Files:

  21. Askanison4

    Askanison4

    Joined:
    Jan 16, 2014
    Posts:
    1
    S-ed: Thanks, that last file of yours seems to have done the trick here for me. Thanks :)
     
  22. rooftoppr

    rooftoppr

    Joined:
    Sep 26, 2014
    Posts:
    4
    @S-ed: Thanks so much! Your .vsix worked perfectly for VS2013
     
  23. kuato4

    kuato4

    Joined:
    May 14, 2015
    Posts:
    3
    Thanks!
     
  24. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    I've forked NShader from Issam Khalil's fork and added a couple of features. You can download a zip with the vsix file and get more info here!
     
  25. IceBeamGames

    IceBeamGames

    Joined:
    Feb 9, 2014
    Posts:
    170
    Is there any way to get this to work for VS2015 preview?
     
  26. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    It'll need to be rebuilt for VS2015. I'll try to do that in the next couple of days.
     
  27. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
  28. aefreedman

    aefreedman

    Joined:
    Dec 29, 2014
    Posts:
    1
    Having trouble with VS 2015 Enterprise highlighting Unity shader files. I've tried uninstalling NShader and reinstalling, and making sure the .map files are in the appdata folder. Nothing.
     
  29. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Are you using that version that I posted? Is that the VS 2015 RC or the full release?

    edit: ah just realised you said Enterprise. I guess it's not the RC then.. I don't have access to enterprise at the moment, but I'll re-install 2015 and see if I can repro.
     
    Last edited: Jul 29, 2015
  30. Wompipomp

    Wompipomp

    Joined:
    Aug 31, 2014
    Posts:
    24
    @samizzo thank you very much. Works perfektly with VS 2015 Community Edition
     
    samizzo likes this.
  31. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Hey @aefreedman did you ever get it working? I wasn't able to repro, but it worked fine in the community edition.