shader validation in intellij using glslangValidator

tech post, feel free to ignore.

If you're like me and you're writing shaders in glsl using IntelliJ  as your IDE*, you probably have noticed a few things:

1. The glsl plugin for IntelliJ sucks. It just doesn't work well or do what you want. I uninstalled it.
2. Different graphics cards support different features, and can be more strict or less strict.
3. The shader version you select has a sweeping impact on how you need to write your shaders. I go back and forth between writing for GLES 2.0 (version 100) and desktop OpenGL 3.0 (version 130) so I get confused a lot.
4. The lack of validation or simple IDE features means that I spend a lot of time editing, running my app to see the shader compile errors, and then fixing them.

Ok so that's terrible. But you can have really good glsl validation right in your IDE in just a few easy steps. Thanks Nick for helping me out with the File Watcher step!

1. Khronos maintains a glsl reference compiler. You can get it here. Download it and put it somewhere safe.

2. IntelliJ has a plugin called File Watchers, that will wait for a file to be modified and then run an external tool on that file. Install that plugin (you will have to hit the "browse repositories" button to find it. You'll need to restart IntelliJ.

3. Create a file type for your shaders. Make sure to include the *.vert and *.frag line endings (and whatever else if you use tessellation shaders, etc.. The glslangValidator tool expects your files to be named canonically.

Bonus, you can add in a bunch of keywords. I have the OpenGL Shading Language Reference Cards for the OpenGL versions I'm targetting (ES 2.0, ES 3.0) printed out, so I added all of the preprocessor directives, data types, and the builtin functions to the keyword tabs. Yeah!

4. Setup a file watcher by going to the File Watchers section that should now be present under project settings.

Tell it to track the shader file type you set up in step 3. Tell it to run the glslangValidator program that you downloaded in step 1. Set the input and working directory. You could also play around with conf files and other command line options if you want of course.

Then you should get some awesome feedback on your shaders!

*Haha so a couple people? Maybe?

No comments:

Post a Comment