Shader Authoring: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
Line 56: Line 56:
Save the file and it should be all set.
Save the file and it should be all set.


===Missing files===
===Update Runvmpi.pl===
As of May 08 there are some files missing in the steam directory that you need to put there. Into the directory steam/steamapps/<account>/sourcesdk/bin, you need to place three files: shadercompile.exe, shadercompile_dll.dll, and mysql_wrapper.dll
As of May 08 there is an error introduced in runvmpi.pl by having two copies shadercompile.exe: one for Episode One, andone for the Orange Box.
Episode One is the only engine version that currently supports custom shaders, 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


The first two of these can be found in /<account>/sourcesdk/orangebox/bin, so just copy them over.
<code>
-$cmdToRun = "\"$ENV{\"sourcesdk\"}\\bin\\shadercompile.exe\" ...
+$cmdToRun = "\"$ENV{\"sourcesdk\"}\\bin\\ep1\\bin\\shadercompile.exe\" ...
</code>


mysql_wrapper.dll is available  [http://files.filefront.com/mysql+wrapperdll/;11464432;/fileinfo.html here]
To use the Orange Box version, replace "ep1" with "orangebox" above, and place mysql_wrapper.dll in <account>\sourcesdk\bin\orangebox\bin.  It is avaliable [http://files.filefront.com/mysql+wrapperdll/;11464432;/fileinfo.html here]


===Fix common_fxc.h===
===Fix common_fxc.h===

Revision as of 13:37, 3 December 2008

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.

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.pngNote:Just having DirectX 9.x installed is not sufficient, the DirectX SDK must be installed!

Copying Files

With Perl and the DirectX SDK installed, copy the required executables so the SDK compilation tools can use them. The table below assumes that Perl has been installed into C:\Perl, DirectX into C:\DXSDK, and that the mods source code directory is in C:\MyMod\src.

Note.pngNote:Replace the following directory names as appropriate.
Source File Destination Directory
C:\Perl\bin\perl.exe C:\MyMod\src\devtools\bin
C:\Perl\bin\perl58.dll C:\MyMod\src\devtools\bin
C:\DXSDK\Utilities\fxc.exe C:\MyMod\src\dx9sdk\Utilities
C:\DXSDK\Utilities\psa.exe C:\MyMod\src\dx9sdk\Utilities
C:\DXSDK\Utilities\vsa.exe C:\MyMod\src\dx9sdk\Utilities

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.

Update Runvmpi.pl

As of May 08 there is an error introduced in runvmpi.pl by having two copies shadercompile.exe: one for Episode One, andone for the Orange Box. Episode One is the only engine version that currently supports custom shaders, 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\" ...


To use the Orange Box version, replace "ep1" with "orangebox" above, and place mysql_wrapper.dll in <account>\sourcesdk\bin\orangebox\bin. It is avaliable 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

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