Shader Authoring

From Valve Developer Community
Revision as of 09:27, 21 March 2020 by TobyTurbo64 (talk | contribs)
Jump to: navigation, search

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.

Once you have downloaded 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.

@echo off
rem ================================
rem == Set the absolute path to your mod's game directory here ==
set GAMEDIR="E:\Half Life 2 Zero\Half Life 2 Zero Game"
rem == Set the relative or absolute path to Source SDK Base 2013 Singleplayer\bin ==
set SDKBINDIR="D:\Steam\steamapps\common\Source SDK Base 2013 Singleplayer\bin"
rem ==  Set the Path to your mod's root source code ==
rem This should already be correct, accepts relative paths only!
set SOURCEDIR="E:\Half Life 2 Zero\Half Life 2 Zero Source"
rem ====================================
call buildsdkshaders.bat

Note: You must put quotation marks around paths with spaces in.

Modify stdshader_dx9_20b.txt

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

See also