Saturday 31 July 2010

Notepad++ for HLSL fx file syntax highlighting

I got to the stage in my coding that I needed to do more HLSL shaders. I had used Visual Studio to do the initial editing but it does not colour code HLSL fx files. I tried to add colour coding to Visual Studio but I think the free Express version does not support highlighting of other file types.

The first choice was to use NVidia FX Composer. I didn't get on with that. It looked clever with drag and drop shader creation and immediate preview but the learning curve to work out how to do a specific effect not already built in was too great. I also struggled to use some of the built in ones so I decided to revert to a normal text editor.

My editor of choice is Notepad++. Totally free, quick and you can add custom syntax highlighting.

HLSL Syntax Highlighting

I found several examples of colour coding for HLSL effect files with a quick search on the web. The trouble was none of them quite looked right to me.

The one available for download from the Notepad++ library site on sourceforge had some typing mistakes. Others had insufficient keywords or font and colour choices not to my liking. So I've created my own variant. I don't claim it to be perfect it just meets my requirements.

Lots of keywords
Similar colour choices to Visual Studio
All one font type and size
My other criterion was an additional file extension of 'fxh' as well as 'fx'. I use 'fxh' for include files which I find I use a lot when working with HLSL effect files.

Download XML

Notepad++ userDefineLang.xml for HLSL (zipped 2kb) July 2010

Installation

I may not have read the instructions properly but the only ones I found told me to copy the userDefineLang.xml file to the program folder of Notepad++.

'C:\Program Files\Notepad++'

That did not work on either of the machines I tried. Windows XP nor Windows 7. In both cases the userDefineLang.xml file had to be in the users Application Data folder. This varies between operating systems but is similar to the following:

'C:\Documents and Settings\%username%\Application Data\Notepad++'
'C:\Users\%username%\AppData\Roaming\Notepad++'

If you already have a userDefineLang.xml file for something else, you can simply add the new language to the end of the existing one in the same file. Remove the duplicated pair of <NotepadPlus> tags from the middle.

No comments: