Source SDK 2013: Shader Authoring

From Valve Developer Community
Revision as of 16:34, 26 December 2014 by Deniz Sezen (talk | contribs) (Made wording clearer.)
Jump to navigation Jump to search

Introduction

Shaders are an important part of Source development. They allow you to create and utilize complex graphical effects that would not be possible with art assets alone. This intention of this page will be to serve as both an introduction to and a gateway for shader development using the Source 2013 SDK.

Pre-requisites

Assumptions

In order to avoid cluttering this page with tons of information, this guide assumes you've already checked out the Source 2013 SDK from GitHub. If you haven't, please follow the instructions on the Source SDK 2013 page. This guide will further assume that you've built the SDK successfully before reading this page.

Installing Perl

The Source SDK contains a bunch of perl scripts that are run during the shader compile process. Naturally, to run these, you'll need to install ActivePerl. You should grab the 64-bit version from here and install it. When the installation completes, you will need to install the String-CRC32 Perl module using the Perl Package Manager which you can find via the start menu. When both products are installed, open up a command prompt window and type:

perl -v

You should see output similar to the following:

This is perl 5, version 18, subversion 4 (v5.18.4) built for MSWin32-x64-multi-thread (with 1 registered patch, see perl -V for more detail)

Copyright 1987-2013, Larry Wall

Binary build 1803 [298573] provided by ActiveState http://www.ActiveState.com
Built Oct 20 2014 10:19:51

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

If you see output similar to the above, it means Perl was installed successfully and you can continue.

Setting up the build

Previous versions of the Source SDK used to ship all of the code for the stdshader_dx9 module. This paradigm was abandoned in favor of using a custom game shader module approach. There are two advantages with this approach:

  1. You no longer need to build all of the base shaders that ship with the Source SDK.
    • Like vertexlitgeneric which had thousands of shader combinations.
  2. You can replace stock SDK shaders with your own implementation.
    • In theory all you'd need to do is create a shader with the same name.

Creating your game_shader_dx9 project

Navigate to src/materialsystem/stdshaders and perform the following steps:

  1. Copy the game_shader_dx9_episodic.vpc file and rename it to game_shader_dx9_<modname>.vpc.
  2. Modify the game_shader_dx9 section in src/vpc_scripts/projects.vgc so that it points to the game_shader_dx9_<modname>.vpc file you created in step 1.
  3. Create a batch file that actually generates a solution/makefile for the shaders project group.

Creating a batch file to build shaders

You'll need to create a batch file that calls buildsdkshaders.bat in order to compile your shaders. Luckily, you can just re-use the batch files shipped with the SDK. Navigate to src/materialsystem/stdshaders and perform the following steps to create your batch file:

  1. Copy buildepisodicshaders.bat and rename it to build<modname>shaders.bat.
  2. Open up build<modname>shaders.bat in notepad and modify the following:
    1. Change GAMEDIR to wherever your mod directory is located at.
    2. Change SDKBINDIR to point to the \bin directory of the variant of the Source SDK Base 2013 you're basing your mod off of.

You should now have a batch file that is capable of building shaders for your mod.