Adding PBR to Your Mod: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(How to Implement Physically Based Rendering (PBR) To your mod)
Line 64: Line 64:


=== Fixes ===
=== Fixes ===
Physics props turn black when used with the PBR shader after 2-3 seconds. this is due to Prop Sleeping. after a set time, props "bake" their lighting for optimization. you can bypass this by typing r_PhysPropStaticLighting 1 on console or hard-coding it on c_physicsprop.cpp
Physics props turn black when used with the PBR shader after 2-3 seconds. this is due to Prop Sleeping. after a set time, props "bake" their lighting for optimization. you can bypass this by typing r_PhysPropStaticLighting 0 on console or hard-coding it on c_physicsprop.cpp

Revision as of 11:20, 23 February 2020

Introduction

In this article we would look at the PBR shader and implement it to our SDK2013 Mod. PBR is a physically based shading model that is used on newer games. Implementing this shader to our mod would enable us to use metalness, roughness workflows to our materials.

Requirements

Files we need

Before doing anything, we will clone this repository https://github.com/thexa4/source-pbr so that we have all the files we will need. the PBR implementation is made by thexa4.

Implementation

The PBR shader consists of 3 files.

  • 1. pbr_dx9.cpp
  • 2. pbr_vs30.fxc
  • 3. pbr_ps30.fxc

After cloning the git repository above, go to mp/src/materialsystem/stdshaders/ and find for those 3 files. Copy them to src/materialsystem/stdshaders/ of your mod. after you are done copying, open game_shader_dx9.vpc and add the PBR files so that when we refresh the solution they would appear.

	$Folder "fxc"
	{
		$File	"pbr_ps30.fxc"
		$File	"pbr_vs30.fxc"
	}

        $Folder "Source Files"
	{
		$File	"pbr_dx9.cpp"
	}

Shader Compilation

We need to compile the shaders that we have before we can use them. Create a file named mymod_dx9_30.txt and add

//
// 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 would enable us to compile the PBR shaders without affecting the standard LightmappedGeneric shaders. This would reduce compile times significantly. open buildsdkshaders.bat 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 

that would enable us to use the custom text file that we made earlier to compile PBR. After that, we can now run buildhl2mpshaders.bat/buildhl2shaders.bat/buildepisodicshaders.bat depending on your mod. make sure you followed Shader authoring so that the shaders will be properly placed on your modfolder/shaders/fxc. depending on your PC and the complexity of the shader, it will 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. you can check first if pbr_dx9.cpp exists in the shader project. if not, add it to the vpc file.

Thats it! you should have PBR in your mod. https://wiki.empiresmod.com/PBR lists the shader parameters you can use to create materials.

Fixes

Physics props turn black when used with the PBR shader after 2-3 seconds. this is due to Prop Sleeping. after a set time, props "bake" their lighting for optimization. you can bypass this by typing r_PhysPropStaticLighting 0 on console or hard-coding it on c_physicsprop.cpp