---Due to changing software this workflow may require changes over time; always check Valve Developer Community for bug/fixes/updates.
Integrating
a Custom HLSL Shader into the Source Engine
Part
A Steam Mod Setup
1.
Launch Steam > Tools > Source SDK
2.
Create New Mod. Use Half-Life 2:Episode 1 for compatiablity. This may not be
true.
3.
MyMod > Properties > Launch Options, add "-allowdebug"
4.
If switching computers, you wil need to run
Source SDK > Utilities > Refresh SDK Content
Part
B Application Setup
1.
Install Microsoft DirectX SDK, November 2008
DirectX
SDK Nov 2008
http://msdn.microsoft.com/en-us/directx/default.aspx
2. Install Microsoft Visual
Studio
http://www.microsoft.com/express/Downloads/
3. Install Perl
http://www.activestate.com/activeperl/
4. Add binaries to Environment
Variables $PATH:
C:\Program Files\Microsoft DirectX SDK (November 2008)\Utilities\bin\x86;
C:\Perl\bin;
Part
C Compatability Setup A (Source)
1.
Open D:\wgsSafety\src\devtools\bin\fxc_prep.pl
find: $cmd .= "/nologo ";
and
append newline: $cmd
.= "/LD ";
2.
Open D:\wgsSafety\src\materialsystem\stdshaders\runvmpi.pl
for Episode1, change:
$cmdToRun =
"\"$ENV{\"sourcesdk\"}\\bin\\shadercompile.exe\" ...
to
resemble:
$cmdToRun =
"\"$ENV{\"sourcesdk\"}\\bin\\ep1\\bin\\shadercompile.exe\"
...
3.
Open D:\wgsSafety\src\materialsystem\stdshaders\buildshaders.bat
replace:
if not
exist "%sourcesdk%\bin\shadercompile.exe" goto NoShaderCompile
set ChangeToDir=%sourcesdk%\bin
with:
if not
exist "%sourcesdk%\bin\ep1\bin\shadercompile.exe" goto
NoShaderCompile
set ChangeToDir=%sourcesdk%\bin\ep1\bin
4.
Open D:\wgsSafety\src\materialsystem\stdshaders\common_fxc.h
find and replace "linear" with "inLinear"
Part
D Shader Implementation A
http://developer.valvesoftware.com/wiki/Shader_Authoring
http://developer.valvesoftware.com/wiki/Shader_authoring/Quick_Start
1. Create Pixel Shader "post_sepia_ps20.fxc"
2. Create Vertex Shader "post_screenspaceeffect_vs20.fxc"
3.
Create textfile list "modshaders.txt" containting:
post_sepia_ps20.fxc
post_screenspaceeffect_vs20.fxc
4.
Run > cmd.exe, enter the following:
> d:
> cd \wgs\wgsSafety\src\materialsystem\stdshaders
> buildsdkshaders.bat modshaders
–game D:\steam\steamapps\sourcemods\wgssafety
–source D:\wgs\wgsSafety\src\
> buildsdkshaders.bat stdshader_dx8
–game D:\steam\steamapps\sourcemods\wgssafety
–source D:\wgs\wgsSafety\src\
> buildsdkshaders.bat stdshader_dx9
–game D:\steam\steamapps\sourcemods\wgssafety
–source D:\wgs\wgsSafety\src\
If error: shadercompile.exe doesn't exist,
check if it exists properly
> echo
%sourcesdk%
shadercompile.exe
should be in D:\Steam\steamapps\STEAMNAME\sourcesdk\bin\ep1\bin
Part
E Compatability Setup B (Visual Studio)
http://developer.valvesoftware.com/wiki/Compiling_under_VS2008
1.
In Visual Studio, go to Tool > Options > Projects and Solutions > VC++
Directories
Select "Inclide files" and add:
"C:\Program Files\Microsoft DirectX SDK (November 2008)\Include"
Select "Library files" and add:
"C:\Program Files\Microsoft DirectX SDK (November 2008)\Lib\x86"
2.
In Visual Studio, File > Open Solution >
D:\wgs\wgsSafety\src\Game_MODTYPE-2005.sln
3.
Follow the prompt to convert the version. Save as Game_MODTYPE-2008.sln
4.
Select Server and Client projects > Right Click > Properties:
Make sure Configuration is set to Debug (in the top left)
Go to Configuration Properties > Linker > Input
Ignore Specific Library: libc;libcd;libcmtd
Additional Dependancies: user32.lib
5.
Open D:\wgs\wgsSafety\src\public\tier0\memoverride.cpp,
at line 727, remove:
void
__cdecl _invalid_parameter_noinfo(void)
{
Assert(0);
}
6.
Select Server and Client projects > Right Click > Properties:
Go to Configuration Properties > C/C++ > General >Detect 64-bit
Portability
set to "No"
7.
Open D:\wgs\wgsSafety\src\materialsystem\stdshaders\stdshader_dx9-2005.vcproj
Create a new file source
post_sepia.cpp
8.
Edit > Find and Replace > Quick Find, Look in Entire Solution for "BEGIN_VS_SHADER"
Make sure each included shader name is prefixed with SDK_
(For example: UnlitGeneric
should
be SDK_UnlitGeneric)
9.
Go to Solution Explorer > Link Libraries, delete these:
d3d9.lib
d3dx9.lib
10.
Right Click on the Link Libraries folder > Add > Existing Item,
browse to the DirectX SDK location:
C:\Program Files\Microsoft DirectX SDK (November 2008)\Lib\x86
add the following
d3d9.lib
d3dx9.lib
11.
Right Click on the Link Libraries folder > Add > Existing Item,
browse to:
D:\wgs\wgsSafety\src\lib\public
add the following
tier2.lib
tier3.lib
12.
Go to Build > Configuration Manager, Release Mode
13.
Build > Rebuild Solution (COMPILE)!!!
Part
F Shader Implementation B
1.
Creat a new material
D:\wgs\wgsSafety\materials\post_sepia.vmt
2.
In Visual Studio, File > Open Solution >
D:\wgs\wgsSafety\src\Game_MODTYPE-2005.sln
3.
Open, Solution Explorer > client_hl2 > Source files > view_scene.cpp
after the line:
static
ConVar r_screenfademaxsize( "r_screenfademaxsize", "0" );
add the line:
ConVar post_sepia("post_sepia", "0", 0,
"Enable/Disable Sepia shader");
4.
Open, Solution Explorer > client_hl2 > Header files > viewrender.h
Inside the CViewRender block, append the following line:
void
PerformPostProcessEffects( int x, int y, int width, int height );
5.
Return to view_scene.cpp, locate the RenderView( ) function
add the follow line to the end (inside of the function):
PerformPostProcessEffects(
view.x, view.y, view.width, view.height );
6.
Add the following new function after RenderView( )
void
CViewRender::PerformPostProcessEffects(int x,int y,int width,int height)
{
if
( (post_sepia.GetInt() == 0) ) //no active effects, bail out
return;
IMaterial
*pSepiaMat = materials->FindMaterial( "materials/post_sepia",
TEXTURE_GROUP_CLIENT_EFFECTS, true );
if
( g_pMaterialSystemHardwareConfig->GetDXSupportLevel() >= 80 )
{
if ( (post_sepia.GetInt() == 1) && pSepiaMat )
{
DrawScreenEffectMaterial( pSepiaMat, x, y, width, height );
}
}
}
7.
Now Build > Rebuild Solution
8.
Launch the wgsSafety mod from Steam, use ` to open the console.
9.
In the console type the following to enable the post process
post_sepia 1