Archive for July, 2011

Shader Editor

Posted: July 29, 2011 in General, Real-Time Rendering

This is a shader editor application I wrote that allows you to write and then test your shaders in the same editor. You write the shader in HLSL on the right and then see it rendered to a mesh on the left. The editor has a bunch of default meshs such as cubes, spheres and planes etc, but also allows you to import your own using my 3dsmax exporter. Ive written my Effect library to compile shaders for multiple vertex formats, so that if you have a shader you want to be used on different formats, you can use preprocess compilation techniques to break the HLSL code into a series of #if #else defines for each format your shader supports. The shader is then compiled for each format. When a mesh is then loaded in and an Effect is to be applied, its vertex format is compared against the compiled versions of the effect, and if a match is found( ie, if that shader was compiled for that particular vertex format), then that specialised shader is applied. The editor is pretty handy as it also reports back any compilation errors from fxc.exe in text window at the bottom of the editor, and also includes an assembler view, which allows you to see the code in assembly. Textures are supported by simply specifiying the location of the file within the Texture definition using Annotations, this is also made easier by using the snippet tool for common code. Once the effect is compiled and produces the correct results, the editor allows you to then make a material from that effect. A material within my engine defines an effect to be applied and the effect parameters(such as textures, samplers and material values), which are either created in code, or loaded\saved as an xml file. The editor creates a material file by parsing the effect file for values that the user can set, this being textures\samplers and any data within “cbMaterial”, which is the material constant buffer. Again, using annotations within the shader, the author can specify how the user sees this data within the editor. So a “float4 DiffuseColour” can be given the annotation “GUI_COLOUR”, which will present the user with a colour selection tool, or a “float SpecularPower” can be given the annotation “GUI_SLIDER MIN[0] MAX[100]”, which will present the user with a slider tool to set floating point values. This list of values are then presented to the user using GUI widgets, which they can use to set the values in a convenient way. As settings are changed, the results are again seen in the view window. Once the user is happy, they can then export to material to an XML file. The Effect is exported separately, and is only referenced by the material.