Adding PBR to Your Mod: Difference between revisions
GamerDude27 (talk | contribs) m (Cleanup, better description of PBR) |
GamerDude27 (talk | contribs) m (Some small changes in formatting and readability) |
||
Line 1: | Line 1: | ||
[[File:PBR_comparison.png|500px|thumb|right|Left: Base Source Engine shaders.<br> Right: The PBR shader.]] | |||
== Introduction == | == Introduction == | ||
The goal of this article is to implement [https://github.com/thexa4/source-pbr Thexa4's PBR shader] into your own Source SDK 2013 mod. | The goal of this article is to show you how to implement [https://github.com/thexa4/source-pbr Thexa4's PBR shader] into your own Source SDK 2013 mod. | ||
Line 23: | Line 25: | ||
You can do this by | You can do this by going to the links below, clicking the "Raw" button and once the page has loaded right-click and select "Save As...". | ||
Then save the files to your Source mod's code directory under '''src/materialsystem/stdshaders/'''. | Then all you have to do is save each one of the files to your Source mod's code directory under '''src/materialsystem/stdshaders/'''. | ||
* [https://github.com/thexa4/source-pbr/blob/feature/pbr-base/mp/src/materialsystem/stdshaders/pbr_dx9.cpp pbr_dx9.cpp] | * [https://github.com/thexa4/source-pbr/blob/feature/pbr-base/mp/src/materialsystem/stdshaders/pbr_dx9.cpp pbr_dx9.cpp] | ||
Line 32: | Line 34: | ||
After you' | After you've finished saving the files, open the '''game_shader_dx9_*.vpc''' file appropriate for your situation (base/hl2mp/hl2/episodic), and add the PBR files within <code>$Project "Shaders"</code> like so: | ||
<pre> | <pre> | ||
$Project "Shaders" | $Project "Shaders" | ||
Line 49: | Line 51: | ||
</pre> | </pre> | ||
We do this so that when we refresh the solution they will appear in | We do this so that when we refresh the solution they will appear in the solution explorer. | ||
=== Shader Compilation === | === 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: | 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 of it: | ||
<pre> | <pre> | ||
// | // | ||
Line 90: | Line 92: | ||
After that, we can now start the shader compilation by running '''buildhl2mpshaders.bat''', '''buildhl2shaders.bat''' or '''buildepisodicshaders.bat''' depending on your mod. | After that, we can now start the shader compilation by running '''buildhl2mpshaders.bat''', '''buildhl2shaders.bat''' or '''buildepisodicshaders.bat''' depending on your mod's base. | ||
Make sure you've followed the [[Shader Authoring]] article to the point where the newly compiled shaders will be properly placed on your mod's '''shaders/fxc/''' folder. | |||
{{note|Depending on your PC and the complexity of the shader, it might take a while.}} | |||
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'''. | |||
If the | {{note|If '''pbr_dx9.cpp''' does not exist in the '''Shader''' project. Make sure that you've properly included it in the '''.vpc''' file you edited earlier.}} | ||
== 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 <code>r_PhysPropStaticLighting 0</code> on the console or by hard-coding it in '''src/game/client/c_physicsprop.cpp''' | |||
== Conclucion == | |||
That's it! You should now have PBR in your mod. | |||
You can find a list of all the shader parameters you can use when creating materials here: | |||
https://wiki.empiresmod.com/PBR |
Revision as of 12:58, 24 February 2020
Introduction
The goal of this article is to show you how to implement Thexa4's PBR shader into your own Source SDK 2013 mod.
Physically Based Rendering or PBR is a shading model in computer graphics that seeks to render graphics in a way that more accurately models the flow of light in the real world.
Many PBR pipelines (though not all) have an accurate simulation of photorealism as their goal, often in real-time computing.
Implementing this shader will allow you to use the metalness/roughness PBR workflow in 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 going to the links below, clicking the "Raw" button and once the page has loaded right-click and select "Save As...".
Then all you have to do is save each one of the files to your Source mod's code directory under src/materialsystem/stdshaders/.
After you've finished 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 the solution explorer.
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 of 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 allow you 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 allow you 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's base.
Make sure you've followed the Shader Authoring article to the point where the newly compiled shaders will be properly placed on your mod's 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.

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
Conclucion
That's it! You should now have PBR in your mod.
You can find a list of all the shader parameters you can use when creating materials here: