zoukankan      html  css  js  c++  java
  • [转]Shader开发工具的使用(语法高亮工具及VS中编译shader的配置)Syntax Hightlighting and Build HLSL

    To be able to fully debug shader programs you will need either a shader IDE like FXComposer or a GPU debugging tool like Nvidia Nsight. These are both complex tools and beyond the scope of a quick tutorial but what I can do if provide you a quick guide to aid you in writing shaders directly within Visual Studio. You will not be able to perform any sort of in-depth debugging, but it will help you deal with silly syntax errors. The first thing need is NShader. NShader is a shader syntax highlighting plugin for visual studio and helps with clarity when editing and writing shader programs.

    Currently, NVidia Parallel NSight 2.x is overriding file associations of .fx, .hlsl, .glsl and default them to a basic c++ syntax highlighting, while removing previous NShader configuration. 

    To remove NSight overriding, you just have to edit the file C:\Program Files (x86)\NVIDIA Parallel Nsight 2.x\Common\Nvda.Vsip.Net.dll.pkgdef and remove the following lines (should start at line 79):

    [$RootKey$\Languages\File Extensions\.fx]@="{b2f072b0-abc1-11d0-9d62-00c04fd9dfd9}"[$RootKey$\Languages\File Extensions\.fxh]@="{b2f072b0-abc1-11d0-9d62-00c04fd9dfd9}"[$RootKey$\Languages\File Extensions\.glsl]@="{b2f072b0-abc1-11d0-9d62-00c04fd9dfd9}"[$RootKey$\Languages\File Extensions\.hlsl]@="{b2f072b0-abc1-11d0-9d62-00c04fd9dfd9}"


    This will remove NSight highlighting in favor of NShader.

    The second thing is to create a custom build step within Visual Studio for your shader programs. This custom build step will use the MS shader compiler to compile your shader programs and notify you of any errors as well as tell you on which lines the errors can be found. To do this, we first select our shader file and right-click then select properties (see figure 1 below).

    Figure 1: Shader Code File Properties

    Doing so will bring up the properties windows, the first step is to ensure that the configuration drop down is set to “all configurations”. The select Item Type and choose “Custom Build Tool” from the drop down (see figure 2).

    Figure 2: Enable Custom Build Tool Step

    Click Apply, this will then show the custom build menu tab on the left hand side. Select the tab and you be presented with the following dialog window:

    Figure 3: Set Custom Build Tool Parameters

    Under the general heading, set the command line value to the following:

    "$(DXSDK_DIR)Utilities\bin\x86\"fxc.exe  /T fx_4_0 /Fo "%(Filename).fxo" "%(FullPath)"

    This will mean that every time the shader file is modified and the solution is compiled, the shader file will be compiled using the microsoft FX compiler (FXC). The /T flag specifies the type of shader file being compile (i.e. the HLSL version). the /Fo flag refers to the compiled output file and the %(FullPath) macro refers to the full path of the current shader file.

    Also set the Custom Build Tool outputs to: $(filename).fxo , this is the same as specified in the FXC commandline. Click OK, and you are done.

    The results of the this process is shown below, all HLSL errors will pop up in the Visual Studio Error Dialog, double clicking on the error will take you to the line of code that caused the error.

    Figure 4: The results of the Custom Build Step

    I’ve wasted a ton of time attempting to find silly syntax errors when developing shader programs, and this little custom build step has been a great help. I hope it helps you in some way as well…

    Reference:

    1.http://nshader.codeplex.com/wikipage?title=How%20to%20use%20NShader%20syntax%20highlighting%20with%20NSight&referringTitle=Home

    2.http://takinginitiative.net/2011/02/19/debugging-hlsl/

  • 相关阅读:
    IPFS实践之初体验
    自己写的屏幕录像及播放软件
    绿色ip扫描工具
    ASIHTTPRequest 编码问题
    ios开发中,A valid provisioning profile for this executable was not found,的解决方法
    毕业设计之蚁群算法的研究——起始篇
    分享两个模拟get和post方法的工具类,让应用能够与服务器进行数据交互
    安卓中生成二维码和扫描二维码
    分享一个安卓中异步获取网络图片并自适应大小的第三方程序(来自github)
    不只是个程序员
  • 原文地址:https://www.cnblogs.com/RobinG/p/2522903.html
Copyright © 2011-2022 走看看