Difference between revisions of "Shader Authoring"

From Valve Developer Community
Jump to: navigation, search
(Fix shadercompile.exe path)
(fix was outdated, no longer necessary)
Line 71: Line 71:
If for some reason you want to use the Orange Box version, replace "ep1" with "orangebox" above, and place mysql_wrapper.dll in <account>\sourcesdk\bin\orangebox\bin.  It is available [http://files.filefront.com/mysql+wrapperdll/;11464432;/fileinfo.html here]
If for some reason you want to use the Orange Box version, replace "ep1" with "orangebox" above, and place mysql_wrapper.dll in <account>\sourcesdk\bin\orangebox\bin.  It is available [http://files.filefront.com/mysql+wrapperdll/;11464432;/fileinfo.html here]
===Fix common_fxc.h===
As of the July 2008 release, compiling any shader with fxc.exe that uses the include file "common_fxc.h" will result in the following compile error.
common_fxc.h<156,36>: error X3000: syntax error: unexpected token 'linear'
To fix this, simply change all instances of the variable "linear" to any other valid HLSL variable name such as "inLinear"
== See also ==
== See also ==

Revision as of 09:13, 6 May 2010

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 Perl and DirectX

To install Perl, go to the download page on http://www.perl.com , download, and install Perl - a recommended version of Perl for windows is ActivePerl.

The Orange Box SDK also relies on the non-standard perl package, String-CRC32. If you are using Active Perl, you can install it through the Perl Package Manager which can be launched from <PerlDir>\bin\ppm.bat

To install the latest DirectX SDK, go to Microsoft's DirectX site, download, and install the DirectX SDK. Be sure to get the latest possible version of the SDK, if a previous version is installed, remove it and download a more recent version.

Note:Just having DirectX 9.x installed is not sufficient, the DirectX SDK must be installed!
Note:It is recommended that you use the November 2008 SDK as needed binaries have been removed from newer releases

Setting The Path

With Perl and the DirectX SDK installed, make sure your "Path" environmental variable has been updated appropriately. In Windows, you can check this by right clicking on properties, going to the Advanced tab, and clicking on "Environment Variables". Assuming that Perl is installed into C:\Perl, and DirectX into C:\DXSDK, your "Path" variable should contain both C:\Perl\bin and C:\DXSDK\Utilities\bin\x86 in a semicolon delimited list.

By setting up the Environmental Variable in this way, you can update the Perl and DirectX sdk as you please without having to copy files. If for some reason you do not wish to do this, you can simply copy the required files into a different directory and add that to your path instead.

Note that you may need to restart your computer for these changes to the environment to take full effect.

Shader compiling with newer DirectX SDKs

Compiling shaders with newer DirectX SDKs from February 2007 and onwards requires a special flag to be set for the fxc.exe file in order to successfully compile shaders.(This is fixes the out of range errors received) And modification to a shader header file.

In the mod's code directory

open \src\devtools\bin\fxc_prep.pl Find:

$cmd .= "/nologo ";

Add Below:

$cmd .= "/LD ";

Save the file and it should be all set.

Fix shadercompile.exe path

As of May 08 there is an error introduced in runvmpi.pl and buildsdkshaders.bat by having two copies shadercompile.exe: one for Episode One, and one for the Orange Box.

Episode One is the only engine version that currently supports custom shaders, so you will most likely want to redirect runvmpi.pl to use that version. Open <moddir>/src/materialsystem/stdshaders/runvmpi.pl and make the following change

-$cmdToRun = "\"$ENV{\"sourcesdk\"}\\bin\\shadercompile.exe\" ...
+$cmdToRun = "\"$ENV{\"sourcesdk\"}\\bin\\ep1\\bin\\shadercompile.exe\" ...

Then open buildsdkshaders.bat and make the following change

-if not exist "%sourcesdk%\bin\shadercompile.exe" goto NoShaderCompile
-set ChangeToDir=%sourcesdk%\bin
+if not exist "%sourcesdk%\bin\ep1\bin\shadercompile.exe" goto NoShaderCompile
+set ChangeToDir=%sourcesdk%\bin\ep1\bin

Warning: The buildsdkshaders.bat file has been completely rewrote since then, the path to shadercompile.exe is stored elsewhere now.

You can also update the error message in that file if you like, but it's not strictly necessary.

If for some reason you want to use the Orange Box version, replace "ep1" with "orangebox" above, and place mysql_wrapper.dll in <account>\sourcesdk\bin\orangebox\bin. It is available here

See also

Template:Otherlang:en Template:Otherlang:en:ru