預覽網頁

2013年8月27日 星期二

如何解決NShader 1.3在Visual Studio 2012 無法標示的問題


  • English Topic:
          How to fix the highlighting problem in NShahder 1.3

  • 目的
              NShader由Alexander Mutel 所開發的Visual Studio的擴充套件,其目的為方便使用者可以在Visual Studio的平台上進
          行GLSL, HLSL與CG語法的寫作。更一步說明,一般的Visual Studio會把Shader Language (例如: .vert, .frag和.glsl)識
          為純文字,所以Shader Language中無論是函式或常數,文字一律為統一顏色,造成寫作者的困擾。因此,NShader
          就是讓Visual Studio可以自動辨別Shader Language中的函式與常數,利用不同的顏色區分出來,以方便寫作。

          PS. NShader僅用於標示(highlight) Shader Language, 並非用於編譯與除錯

  • 步驟
          此處安裝步驟先教導如何安裝NShader, 再如何避免標示的問題。

          1. 到NShader官網下載擴充檔
              For Visual Studio 2010+2012: http://nshader.codeplex.com/releases/view/89782
              For Visual Studio 2008: http://nshader.codeplex.com/releases/view/45399



           2. 擴充檔的安裝,請參考如何在visual studio 中加入擴充檔 (.vsix),是否安裝成功請參照無可救藥: NShader

           3. 安裝完成後,創一個測試檔(範例中使用GLSL語法的.vert跟.frag檔),並用Visual Studio讀取,此時看到的檔案是
               被歸類為純文字檔,因此全部顯示為預設的黑色


           4. 官網所提供的解決方法: 
               a. Remove the registry entry:
                   HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\FontAndColors\Cache
                   HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0_Config
               b. 一般網路盛行的修改NShader.pkgdef內容的方法
              
            以下分成步驟5與6進行解說

            5.  Remove the registry entry
                 到底HKEY_CURRENT_USER在哪裡呢?其實他在regedit.exe中。打開"開始",並輸入"regedit"你就可以找
                 到他,按照路徑找到HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\FontAndColors\Cache
                 以及 HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0_Config予以刪除


            6. 接下來修改NShader.pkgdef 
               (你安裝Visual Studio的所在磁碟\Visaul Studio資料夾\Common7\IDE\Extensions\14qinxaz.qhy\NShader.pkgdef )
                打開該檔案,並在
  1. "CodeBase"="$PackageFolder$\NShader.dll"

              中加入以下內容:
              a. For NShader1.2
  1. [$RootKey$\Languages\File Extensions\.shader]
  2. @="{479b8c71-c9de-3669-869d-ae1d91602d7c}"
              b. For NShader1.3
  1. [$RootKey$\Languages\File Extensions\.shader]
  2. @="{4c554917-0eb7-3742-9f6b-f2f529fc6729}"


               7. 重新啟動Visual Studio2012, 打開.vert,可以發現NShader已經把函式標註出來囉~


  • 參考資料
          [1] NShader官網:
               http://nshader.codeplex.com/

          [2] Support for .shader file extension

          [3] How to use NShader with Utility Shaders

          [4] 無可救藥: NShader

          [5] How to I enable syntax highlighting of CUDA .cu files in Visual Studio 2010
               (regedit的用法出自本篇)

沒有留言:

張貼留言