Adding PBR to Your Mod
Introduction
The goal of this article is to implement Thexa4's PBR shader into our own Source SDK 2013 mod.
PBR is a physically based shading model that is used in newer games. Implementing this shader will enable us to use metalness and roughness workflows in our materials.
Requirements
- Ability to compile shaders.
- Ability to compile the solution.

Implementation
Before doing anything, we need to download the files we need.
You can do this by clicking one of the links below, hitting the "Raw" button and once the page has loaded right click the page and select "Save As...".
Then save the files to your Source mod's code directory under src/materialsystem/stdshaders/.
After you're done saving the files, open the game_shader_dx9_*.vpc file appropriate for your situation (base/hl2mp/hl2/episodic), and add the PBR files within $Project "Shaders"
like so:
$Project "Shaders" { $Folder "fxc" { $File "pbr_ps30.fxc" $File "pbr_vs30.fxc" } $Folder "Source Files" { $File "pbr_dx9.cpp" } }
We do this so that when we refresh the solution they will appear in our solution.
Shader Compilation
We need to compile the shaders that we have before we can use them. Create a file in src/materialsystem/stdshaders/ named mymod_dx9_30.txt and add this inside it:
// // vs 3.0 ps 3.0 shaders collection // // These shaders are forced to compile as shader model 3.0 // using the new compiler. // _ps30.vcs // _vs30.vcs // // There are no examples of such shaders in the SDK, but add yours here. pbr_vs30b.fxc pbr_ps30b.fxc
Adding a new text file for shader compilation will enable us to compile the PBR shaders without affecting the standard LightmappedGeneric shaders.
This will also reduce compile times significantly.
Now open the buildsdkshaders.bat file using Notepad and edit this part below from:
%BUILD_SHADER% stdshader_dx9_20b -game %GAMEDIR% -source %SOURCEDIR% %BUILD_SHADER% stdshader_dx9_30 -game %GAMEDIR% -source %SOURCEDIR% -dx9_30 -force30
To:
%BUILD_SHADER% mymod_dx9_20b -game %GAMEDIR% -source %SOURCEDIR% %BUILD_SHADER% mymod_dx9_30 -game %GAMEDIR% -source %SOURCEDIR% -dx9_30 -force30
This will enable us to use the custom text file that we made earlier to compile our PBR shader.
After that, we can now start the shader compilation by running buildhl2mpshaders.bat, buildhl2shaders.bat or buildepisodicshaders.bat depending on your mod.
Make sure you've followed Shader Authoring to the point where the newly compiled shaders will be properly placed on your mod's modfolder/shaders/fxc/ folder.

If the shaders compile without problems, go back to your source code directory /src/ and run createallprojects.bat.
Run the solution and build shaders in Release. You can check first if pbr_dx9.cpp exists in the shader project.
If not, add it to the .vpc file.
That's it! You should now have PBR in your mod.
https://wiki.empiresmod.com/PBR lists the shader parameters you can use when creating materials.
Fixes
Physics props turn black when used with the PBR shader after 2-3 seconds due to Prop Sleeping. After a set time, props "bake" their lighting for optimization.
You can bypass this by typing r_PhysPropStaticLighting 0
on the console or by hard-coding it in src/game/client/c_physicsprop.cpp