Ru/Adding PBR to Your Mod: Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 19: | Line 19: | ||
{{note|Если вы не знаете, как компилировать шейдеры, или еще не работали с шейдерами в Source Engine, рекомендуется сначала прочитать эти статьи: [[Shader Authoring]] & [[Source_SDK_2013:_Your_First_Shader|Your First Shader]]}} | {{note:ru|Если вы не знаете, как компилировать шейдеры, или еще не работали с шейдерами в Source Engine, рекомендуется сначала прочитать эти статьи: [[Shader Authoring]] & [[Source_SDK_2013:_Your_First_Shader|Your First Shader]]}} | ||
== Реализация == | == Реализация == | ||
Line 132: | Line 132: | ||
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. | 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.}} | {{note:ru|Depending on your PC and the complexity of the shader, it might take a while.}} | ||
Line 139: | Line 139: | ||
Run the solution and build shaders in '''Release'''. | Run the solution and build shaders in '''Release'''. | ||
{{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.}} | {{note:ru|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 == | == Fixes == | ||
Line 187: | Line 187: | ||
{{note|$emissiontexture is a color texture, not a mask.}} | {{note:ru|$emissiontexture is a color texture, not a mask.}} | ||
{{bug|By default all shadows appear to point towards the user as if the user is holding a light, instead of using exterior light sources.}} | {{bug:ru|By default all shadows appear to point towards the user as if the user is holding a light, instead of using exterior light sources.}} | ||
== Примеры == | == Примеры == | ||
Line 221: | Line 221: | ||
=== Модель, образец материала с картой отражений === | === Модель, образец материала с картой отражений === | ||
{{Note|Metalness channel is ignored and [[$basetexture]] is treated as diffuse.}} | {{Note:ru|Metalness channel is ignored and [[$basetexture]] is treated as diffuse.}} | ||
<pre> | <pre> | ||
PBR | PBR | ||
Line 237: | Line 237: | ||
{{note|[[$envmap]] should just be left as <code>env_cubemap</code>.}} | {{note:ru|[[$envmap]] should just be left as <code>env_cubemap</code>.}} | ||
{{warning|[[$model_(VMT)|$model 1]] '''''MUST''''' be added for models to work!}} | {{warning:ru|[[$model_(VMT)|$model 1]] '''''MUST''''' be added for models to work!}} | ||
== Вывод == | == Вывод == |
Revision as of 06:46, 1 August 2020
Цель этой статьи - показать вам, как реализовать Thexa4's PBR шейдер в вашем Source SDK 2013 моде. Реализация этого шейдера позволит вам использовать metalness/roughness PBR workflow in materials.
Вступление
Требования
- Умение компилировать шейдеры.
- Умение компилировать решения.
Реализация
Прежде чем делать что-то, нам нужно скачать файлы.
Вы можете сделать это, перейдя по ссылкам ниже, нажмите кнопку "Raw" и как только страница загрузится кликните правой кнопкой мыши и выберите "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/.
После того как вы завершите сохранение файлов, откройте файл game_shader_dx9_*.vpc соответствующий вашей ситуации (base/hl2mp/hl2/episodic), и добавьте файлы PBR внутрь $Project "Shaders"
вот так:
$Project "Shaders" { $Folder "Header Files" { $File "common_vertexlitgeneric_dx9.h" $File "common_lightmappedgeneric_fxc.h" $File "common_flashlight_fxc.h" } $Folder "Shader Source" { $Folder "fxc" { $File "pbr_ps30.fxc" $File "pbr_vs30.fxc" $File "pbr_ps20b.fxc" $File "pbr_vs20b.fxc" } $Folder "Headers" { $File "pbr_common_ps2_3_x.h" } $File "mymod_dx9_30.txt" $File "mymod_dx9_20b.txt" } $Folder "Source Files" { $File "pbr_dx9.cpp" } }
We do this so that when we refresh the solution they will appear in the solution explorer.
Компиляция шейдеров
Нам нужно скомпилировать шейдеры перед их испольхованием. Создайте 2 файла в src/materialsystem/stdshaders/ с именем mymod_dx9_30.txt и mymod_dx9_20b.txt, и вставьте это внутрь:
mymod_dx9_30.txt
// // 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 // pbr_vs30.fxc pbr_ps30.fxc
mymod_dx9_20b.txt
// // Standard shaders collection // // These shaders are compiled as the following shader models: // _ps20.vcs // _ps20b.vcs // _vs20.vcs // pbr_vs20b.fxc pbr_ps20b.fxc
Adding new text files 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. Template:Note:ru
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 hardcoding it in src/game/client/c_physicsprop.cpp.
Here is how you can hardcode it:
Под #include "tier0/memdbgon.h"
добавьте это:
#define PBR_CHANGE
Then find ConVar r_PhysPropStaticLighting("r_PhysPropStaticLighting", "1");
and turn it into this:
#ifdef PBR_CHANGE
ConVar r_PhysPropStaticLighting( "r_PhysPropStaticLighting", "0" );
#else
ConVar r_PhysPropStaticLighting( "r_PhysPropStaticLighting", "1" );
#endif
Параметры
- $basetexture - The albedo texture.
- $normaltexture - Sets the normal map (for backwards compatibility).
- $bumpmap - Sets the normal map (new way of setting normalmap).
- $mraotexture - A texture with the metalness on the red channel, roughness on the green channel and ambient occlusion on the blue channel.
- $speculartexture - Enables use of colored F0 (specular map), overrides metalness from MRAO texture.
- $emissiontexture - Allows setting an emission texture. Enabled self illumination.
- $useenvambient <bool> - Makes it use the lowest mip level of the cubemap for ambient light instead of the ambient cubes. Can cause artifacts with moving props.
- $envmap - Defaults to "env_cubemap", allows you to use a custom one.
- $surfaceprop - Links the surface of either a material or model to a set of physical properties.
- $model - Should have a value of "1" if the texture is used on a prop.
- $translucent - Setting this to "1" enables alpha blending.
- $basetexturetransform - Looks like this: "center 0.5 0.5 scale 0.1025 0.1025 rotate 0 translate 0 0" for a 2m by 2m texture.
- $alphatest - Enables clipping the pixel when the alpha goes below $alphatestreference.
- $alphatestreference - Specifies the minimum color value of the alpha channel in which the effect is rounded to 255. A value of ".3" will create a thicker shape while a value of ".7" will create a thinner shape.
- %keywords - A list of keywords separated by commas. Examples of keywords are: architectural,brown,gray,grime,hanger,industrial,metal,modern,shed,urban,wall,floor
- $useparallax <bool> - Use Parallax Occlusion Mapping.
- $parallaxdepth <float> - Depth of the Parallax Map
- $parallaxcenter <float> - Center depth of the Parallax Map
Примеры
Браш (не модельные поверхности), образец материала
PBR { $basetexture "pbr_asset/texture_albedo" $bumpmap "pbr_asset/texture_normal" $mraotexture "pbr_asset/texture_mrao" $envmap "env_cubemap" $surfaceprop "metal" $model 0 }
Модель, образец материала
PBR { $basetexture "models/pbr_asset/texture_albedo" $bumpmap "models/pbr_asset/texture_normal" $mraotexture "models/pbr_asset/texture_mrao" $envmap "env_cubemap" $surfaceprop "metal" $model 1 }
Модель, образец материала с картой отражений
PBR { $basetexture "models/pbr_asset/texture_diffuse" $bumpmap "models/pbr_asset/texture_normal" $mraotexture "models/pbr_asset/texture_mrao" $speculartexture "models/pbr_asset/texture_specular" $envmap "env_cubemap" $surfaceprop "metal" $model 1 }
Вывод
И это все! Теперь в вашем моде есть PBR.