Implementing Deferred lighting into Source 2013: Difference between revisions
(→Implementing into your Source 2013SP mod: gonna add more documentation soon!) |
(Rewriting this tutorial to be more user friendly as the previous one was very time consuming and hard to follow. Sucks to delete so much of it but I don't really know where to put it - feel free to reinstate it somewhere if you have any ideas) Tag: Replaced |
||
(23 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{LanguageBar}} | ||
{{warning|This guide aims to provide a quick and simple way of implementing this feature, but the implementation itself needs further work to make it stable, robust, and usable.}} | |||
{{draft}} | |||
__NOTOC__ | |||
Having [[Deferred lighting|deferred lighting]] in your mod comes with quite a lot of upsides as with it, you can have volumetric lighting, realtime shadows and lighting from the sun and from other light sources, while still keeping the performance steady, which is something that Source's regular dynamic light entities would be incapable of (aka projected textures). However, keep in mind that all publicly available implementations are still unstable and can cause visual glitches and slowdowns. | |||
== | ==Background and resources used== | ||
This implementation was originally [https://github.com/jonathonracz/swarm-deferred-src made by Kristjan Skutta aka Biohazard90], based on [https://github.com/NicolasDe/AlienSwarm Alien Swarm's deferred shading approach], then it was [https://github.com/Sandern/lambdawars expended by the Lambda Wars team], and finally it was [https://github.com/SCell555/sdk-2013-deferred ported to Source 2013 by SCell555]. This implementation has been since ported into various Source SDK forks, but for the purpose of simplicity, this tutorial will focus on adding deferred lighting to the [https://github.com/Source-SDK-Resources/source-sdk-vs2022 source-sdk-vs2022] repo, as it is an almost unchanged {{Src13|4}} SDK repo with added compatibility for modern editions of Visual Studio. | |||
The end result should be identical, or at least very similar, to [https://github.com/54ac/source-sdk-vs2022-deferred source-sdk-vs2022-deferred], which is an implementation of deferred lighting for the source-sdk-vs2022 repo (both MP and SP). | |||
==Preparation== | |||
Using the right tools will make copying code from one repo to another a relatively quick and painless process. | |||
# Download [https://winmerge.org WinMerge] or a similar diff/merge tool. | |||
# Use git to clone the two repos used in this tutorial (or download them as ZIP files): [https://github.com/Source-SDK-Resources/source-sdk-vs2022 source-sdk-vs2022] and [https://github.com/54ac/source-sdk-vs2022-deferred source-sdk-vs2022-deferred]. | |||
# Make sure the source-sdk-vs2022 repo compiles successfully in your installation of Visual Studio 2022 before you modify it. | |||
The repo also includes diff files which should allow you to easily apply all of the necessary changes per branch as long as you know how to use them. This tutorial will focus on the slightly more user-friendly WinMerge approach. | |||
==Implementation using WinMerge== | |||
You can copy all the necessary files and apply changes to the code by comparing both folders in WinMerge. The source-sdk-vs2022-deferred aims to modify as few files as possible, so the process should be relatively quick. | |||
The process is very similar for both the MP and SP branches. In both cases, the new files that need to be transferred are contained in separate deferred folders in the client, server, and shared folders in /game, as well as in /materialsystem/stdshaders and /public. The files that need to be modified are contained in the same folders as well as in /tier1 and the root folder (creategameprojects.bat). | |||
===File modifications=== | |||
Apply the modifications as shown by WinMerge. Consult the manual if you're unsure how to do this, though you could probably do this solely with the Ctrl and arrow keys if you wanted to. The majority of the modifications will involve files in /game/client and /materialsystem/stdshaders. All new entries for files related to deferred lighting are added in *_base.vpc files, and the creategameprojects.bat file is changed to generate the Visual Studio solution for the shader DLL as well. | |||
Once you've applied all the changes shown by WinMerge, run the creategameprojects.bat file to recreate the Visual Studio solutions. At this stage, you should be able to compile the client and server DLLs. | |||
==Compiling shaders with ShaderCompile== | |||
In order to compile the shader DLL, you will need to generate the .inc shader include files. This tutorial uses [https://github.com/SCell555/ShaderCompile SCell555's ShaderCompile tool] to simplify the process. | |||
# Download the ShaderCompile 7z file from the latest release on the GitHub releases page. | |||
# Follow the "getting started" section in the readme of the repo (replace cshader.h and buildshaders.bat, modify game_shader_dx9_base.vpc and buildsdkshaders.bat, copy over ShaderCompile.exe and process_shaders.ps1). | |||
# Run e.g. buildhl2mpshaders.bat to build the shaders. | |||
If the batch file refuses to run, open it in a text editor and encase the paths for GAMEDIR and SOURCEDIR in quotation marks, i.e. so that it looks similar to this (SDKBINDIR is irrelevant here): | |||
<source> | |||
@echo off | |||
setlocal | |||
rem ================================ | |||
rem ==== MOD PATH CONFIGURATIONS === | |||
rem == Set the absolute path to your mod's game directory here == | |||
set GAMEDIR="%cd%\..\..\..\game\mod_hl2mp" | |||
rem == Set the relative or absolute path to Source SDK Base 2013 Singleplayer\bin == | |||
set SDKBINDIR= | |||
rem == Set the Path to your mod's root source code == | |||
rem This should already be correct, accepts relative paths only! | |||
set SOURCEDIR="..\.." | |||
rem ==== MOD PATH CONFIGURATIONS END === | |||
rem ==================================== | |||
call buildsdkshaders.bat | |||
</source> | |||
Once you've compiled all the shaders, launch the creategameprojects.bat file again. You should now be able to compile the shader DLL. | |||
==Notes== | |||
* At this point, deferred lighting should be implemented. If not, either go through the steps again or simply use the source-sdk-vs2022-deferred repo as your starting point. Make sure to read through the notes in the readme. | |||
* Don't be discouraged by how janky it is - use it as motivation to become the first person to create a robust, stable deferred lighting implementation without making it closed source. | |||
=== | |||
* | |||
* | |||
* | |||
== External links == | == External links == | ||
*[https://github.com/Sandern/lambdawars Lambda | * [https://github.com/NicolasDe/AlienSwarm Alien Swarm SDK (deferred shading)] | ||
* [https://github.com/jonathonracz/swarm-deferred-src Biohazard90's deferred lighting implementation for Alien Swarm] | |||
* [https://github.com/Sandern/lambdawars Lambda Wars source code] | |||
* [https://github.com/SCell555/sdk-2013-deferred SCell555's port of deferred lighting to Source SDK 2013] | |||
* [https://github.com/Source-SDK-Resources/source-sdk-vs2022 Source SDK 2013 with Visual Studio 2022 support] | |||
* [https://github.com/54ac/source-sdk-vs2022-deferred Implementation of deferred lighting for the VS2022 fork] | |||
* [https://github.com/SCell555/ShaderCompile SCell555's ShaderCompile tool] | |||
[[Category:Programming]] | |||
[[Category:Shaders|*]] |
Latest revision as of 10:24, 22 August 2024




Remember to check for any notes left by the tagger at this article's talk page.
Having deferred lighting in your mod comes with quite a lot of upsides as with it, you can have volumetric lighting, realtime shadows and lighting from the sun and from other light sources, while still keeping the performance steady, which is something that Source's regular dynamic light entities would be incapable of (aka projected textures). However, keep in mind that all publicly available implementations are still unstable and can cause visual glitches and slowdowns.
Background and resources used
This implementation was originally made by Kristjan Skutta aka Biohazard90, based on Alien Swarm's deferred shading approach, then it was expended by the Lambda Wars team, and finally it was ported to Source 2013 by SCell555. This implementation has been since ported into various Source SDK forks, but for the purpose of simplicity, this tutorial will focus on adding deferred lighting to the source-sdk-vs2022 repo, as it is an almost unchanged Source 2013 SDK repo with added compatibility for modern editions of Visual Studio.
The end result should be identical, or at least very similar, to source-sdk-vs2022-deferred, which is an implementation of deferred lighting for the source-sdk-vs2022 repo (both MP and SP).
Preparation
Using the right tools will make copying code from one repo to another a relatively quick and painless process.
- Download WinMerge or a similar diff/merge tool.
- Use git to clone the two repos used in this tutorial (or download them as ZIP files): source-sdk-vs2022 and source-sdk-vs2022-deferred.
- Make sure the source-sdk-vs2022 repo compiles successfully in your installation of Visual Studio 2022 before you modify it.
The repo also includes diff files which should allow you to easily apply all of the necessary changes per branch as long as you know how to use them. This tutorial will focus on the slightly more user-friendly WinMerge approach.
Implementation using WinMerge
You can copy all the necessary files and apply changes to the code by comparing both folders in WinMerge. The source-sdk-vs2022-deferred aims to modify as few files as possible, so the process should be relatively quick.
The process is very similar for both the MP and SP branches. In both cases, the new files that need to be transferred are contained in separate deferred folders in the client, server, and shared folders in /game, as well as in /materialsystem/stdshaders and /public. The files that need to be modified are contained in the same folders as well as in /tier1 and the root folder (creategameprojects.bat).
File modifications
Apply the modifications as shown by WinMerge. Consult the manual if you're unsure how to do this, though you could probably do this solely with the Ctrl and arrow keys if you wanted to. The majority of the modifications will involve files in /game/client and /materialsystem/stdshaders. All new entries for files related to deferred lighting are added in *_base.vpc files, and the creategameprojects.bat file is changed to generate the Visual Studio solution for the shader DLL as well.
Once you've applied all the changes shown by WinMerge, run the creategameprojects.bat file to recreate the Visual Studio solutions. At this stage, you should be able to compile the client and server DLLs.
Compiling shaders with ShaderCompile
In order to compile the shader DLL, you will need to generate the .inc shader include files. This tutorial uses SCell555's ShaderCompile tool to simplify the process.
- Download the ShaderCompile 7z file from the latest release on the GitHub releases page.
- Follow the "getting started" section in the readme of the repo (replace cshader.h and buildshaders.bat, modify game_shader_dx9_base.vpc and buildsdkshaders.bat, copy over ShaderCompile.exe and process_shaders.ps1).
- Run e.g. buildhl2mpshaders.bat to build the shaders.
If the batch file refuses to run, open it in a text editor and encase the paths for GAMEDIR and SOURCEDIR in quotation marks, i.e. so that it looks similar to this (SDKBINDIR is irrelevant here):
@echo off
setlocal
rem ================================
rem ==== MOD PATH CONFIGURATIONS ===
rem == Set the absolute path to your mod's game directory here ==
set GAMEDIR="%cd%\..\..\..\game\mod_hl2mp"
rem == Set the relative or absolute path to Source SDK Base 2013 Singleplayer\bin ==
set SDKBINDIR=
rem == Set the Path to your mod's root source code ==
rem This should already be correct, accepts relative paths only!
set SOURCEDIR="..\.."
rem ==== MOD PATH CONFIGURATIONS END ===
rem ====================================
call buildsdkshaders.bat
Once you've compiled all the shaders, launch the creategameprojects.bat file again. You should now be able to compile the shader DLL.
Notes
- At this point, deferred lighting should be implemented. If not, either go through the steps again or simply use the source-sdk-vs2022-deferred repo as your starting point. Make sure to read through the notes in the readme.
- Don't be discouraged by how janky it is - use it as motivation to become the first person to create a robust, stable deferred lighting implementation without making it closed source.
External links
- Alien Swarm SDK (deferred shading)
- Biohazard90's deferred lighting implementation for Alien Swarm
- Lambda Wars source code
- SCell555's port of deferred lighting to Source SDK 2013
- Source SDK 2013 with Visual Studio 2022 support
- Implementation of deferred lighting for the VS2022 fork
- SCell555's ShaderCompile tool