Shader Authoring
This document describes how to author shaders in the Source SDK, for further information on what a shader is and how they can be used, please see Shader.
Getting Started
Every material that is used in Source specifies which shader it uses to render itself. The shader contains the logic and equations to take the source artwork and lighting, and produce the final rendered color for every pixel that the shader is used on.
The Source SDK fully supports Microsoft DirectX HLSL (High Level Shading Language) and shader assembly languages for writing shaders. It is recommended to use HLSL whenever possible and to only write shader assembly as a last resort.
There are a number of external tools required to compile shaders for use in the Source SDK, the following sections detail the tools and provides links for download along with brief instructions on installation and usage.
The tools used are Perl, the DirectX SDK and make, the following processes, in general, only have to be performed once before the process of compiling shaders can begin.
Installing SCell555's Shader Compile
To install Scell555's Shader Compile tools, you must download the zip file which they provide with every release:[1]
Once you have got the zip file, open it up and you should see the following folders:
- bin
- headers
- stdshaders
place "bin" into "\devtools\" and place "stdshaders" into "\materialsystem\". If you are using visual studio 2013, then place "\headers\VS2013\cshader.h\" into "\puplic\"; I have not tested other versions of Visual Studio, but I assume that you would use "\headers\cshader.h\" instead.
Modify buildepisodicshaders.bat
Open "\materialsystem\stdshaders\buildepisodicshaders.bat" and set the GAMEDIR AND SDKBINDIR as instructed. You might also need to modify the call to vsvars32.bat on line 7 of "buildsdkshaders.bat". If you are using Visual Studio 2013 it should point to %VS120COMNTOOLS% instead.
rem == Set the absolute path to your mod's game directory here ==
rem == Note that this path needs does not support long file/directory names ==
rem == So instead of a path such as "C:\Program Files\Steam\steamapps\mymod" ==
rem == you need to find the 8.3 abbreviation for the directory name using 'dir /x' ==
rem == and set the directory to something like C:\PROGRA~2\Steam\steamapps\sourcemods\mymod ==
set GAMEDIR= YOUR PATH HERE
rem == Set the relative path to SourceSDK\bin\orangebox\bin ==
rem == As above, this path does not support long directory names or spaces ==
rem == e.g. ..\..\..\..\..\PROGRA~2\Steam\steamapps\<USER NAME>\sourcesdk\bin\orangebox\bin ==
set SDKBINDIR= YOUR PATH HERE
Note: You must put quotation marks around paths with spaces in.
Open up "materialsystem/stdshaders/stdshader_dx9_20b.txt" and comment out all of the lines which compile shaders like so:
//
// Standard shaders collection
//
// These shaders are compiled as the following shader models:
// _ps20.vcs
// _ps20b.vcs
// _vs20.vcs
//
//example_model_ps20b.fxc
//example_model_vs20.fxc
//SDK_Bloom_ps2x.fxc
//SDK_screenspaceeffect_vs20.fxc
//SDK_bloomadd_ps2x.fxc
See also
- You can get more information about HLSL and shader assembly programming in the online MSDN docs.
- Category:Material System -- for more general information on the usage of shaders in materials.