Difference between revisions of "HPL3/Shaders/Overwriting Existing Shaders"

From Frictional Wiki
< HPL3‎ | Shaders
Jump to navigation Jump to search
(Adding initial stub)
 
m (Typos)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
== Introduction ==
  
{{constructionNotice|This page is currently a work in progress! Information will be added over time based on research and testing.}}
+
[[File:Greyscale Demonstration.jpg|thumb|A simple shader mod that gives SOMA a classic, film noir look...]]Most shaders can be overwritten at runtime by StandAlone and AddOn mods, allowing for them to easily modify shader behavior. Here's an example mod for SOMA in both [https://mega.nz/file/egE1CYZD#WliKF2KuCEwn2XNmt9idmGqaDv8Nr5pIFtEi2EA6ISs StandAlone] and [https://mega.nz/file/L4dEFBJJ#wAIzKE7fF0pAjpXRmDr1bzvDMTvz5mawVrKp0QvbiB8 AddOn] configuration that makes a simple edit to the game's <code>posteffect_tonemapping_frag.hpsl</code> shader. After loading either version, you can see that the entire game is now in black and white!
  
Most shaders can be overwritten at runtime by StandAlone and AddOn mods, allowing for them to easily modify shader behavior.
+
Alternatively, vanilla shaders can be directly modified in the <code>core\shaders\</code> directory of your game install. This can be useful for more complex shader mods which edit the few shaders that cannot be reliably overwritten by normal StandAlone or AddOn mods, which are currently:
 
 
Alternatively, vanilla shaders can be directly modified in the core\shaders\ directory of your game install. This can be useful for more complex shader mods which edit the few shaders that cannot be reliably overwritten by normal StandAlone or AddOn mods, which are currently:
 
  
 
* base_vtx.hpsl
 
* base_vtx.hpsl
Line 25: Line 24:
 
These likely have special behavior in-engine that changes the way they're loaded when compared to other shaders. More testing will be needed to determine why this is the case.  
 
These likely have special behavior in-engine that changes the way they're loaded when compared to other shaders. More testing will be needed to determine why this is the case.  
  
== Set Up==
+
== Set Up ==
 +
 
 +
Edit your mod's <code>resources.cfg</code> file to include the following:
 +
 
 +
<syntaxhighlight lang="xml">
 +
<Resources>
 +
    <Directory Path="/core" AddSubDirs="true" />
 +
</Resources></syntaxhighlight>
 +
 
 +
GLSL shaders should be located in your mod's <code>core\shaders\</code> directory and HPSL shaders should be in <code>core\shaders\hpsl</code>. For existing shaders, your shader MUST have the same name and path as the shader you're trying to overwrite. Most of the shader list is hardcoded within the executable and there is no known way to create new GpuPrograms or delete existing ones without access to the source code. For a simple AddOn that just alters shaders, your file structure will likely look like this:
  
For existing shaders, your shader MUST have the same name as the shader you're trying to overwrite. Most of the shader list is hardcoded within the executable and there is no known way to create new GpuPrograms or delete existing ones without access to the source code.  
+
<syntaxhighlight lang="css">
 +
modFolder/
 +
├── core/
 +
│  ├── shaders/
 +
│  │  ├── hpsl/
 +
├── entry.hpc
 +
├── resources.cfg
 +
</syntaxhighlight>
  
 
=== SOMA ===
 
=== SOMA ===
  
The setup process for SOMA is extremely straightforward and is as simple as placing your shaders in your mod's \core\shaders\ directory, and your changes should be reflected in-game after loading your mod. Keep in mind that not all shader code is compiled on startup and is often conditional depending on what is being rendered in the current map, so some changes will not be immediately apparent!  
+
Beyond this, the setup process for SOMA is extremely straightforward and is as simple as placing your shaders in your mod's <code>core\shaders\</code> directory, and your changes should be reflected in-game after loading your mod. Keep in mind that not all shader code is compiled on startup and is often conditional depending on what is being rendered in the current map, so some changes will not be immediately apparent!  
  
 
=== Amnesia: Rebirth and Amnesia: The Bunker ===
 
=== Amnesia: Rebirth and Amnesia: The Bunker ===
  
For Amnesia: Rebirth and Amnesia: The Bunker, LoadShaderCache MUST be set to false in your mod's user settings configuration file for your mod's custom shaders to be reflected in-game. This will likely lead to slightly degraded performance, but this doesn't seem too noticeable on modern hardware. You will need to overwrite the base game's default_user_settings.cfg in the config folder to automatically set LoadShaderCache to false (for Rebirth) OR you will need to manually instruct users to set LoadShaderCache to false in their .cfg file (for Bunker).  
+
For Amnesia: Rebirth and Amnesia: The Bunker, <code>LoadShaderCache</code> MUST be set to false in your mod's user settings configuration file for your mod's custom shaders to be reflected in-game. This will likely lead to slightly degraded performance, but this doesn't seem too noticeable on modern hardware. You will need to overwrite the base game's <code>default_user_settings.cfg</code> in the config folder to automatically set <code>LoadShaderCache</code> to false (for Rebirth) OR you will need to manually instruct users to set <code>LoadShaderCache</code> to false in their .cfg file (for Bunker).  
  
'''NOTE:''' Make sure SaveShaderCache is set to false! This has much worse performance degradation and worse compatibility than LoadShaderCache, as it constantly regenerates the shadercache.xml file in _shadersource at runtime. This may be useful for directly editing shaders within your base install, but is unlikely to be useful for mods.
+
'''NOTE:''' Make sure <code>SaveShaderCache</code> is set to false! This has much worse performance degradation and worse compatibility than <code>LoadShaderCache</code>, as it constantly regenerates the shadercache.xml file in <code>_shadersource</code> at runtime. This may be useful for directly editing shaders within your base install, but is unlikely to be useful for StandAlone or AddOn mods.

Latest revision as of 23:14, 13 September 2024

Introduction

A simple shader mod that gives SOMA a classic, film noir look...

Most shaders can be overwritten at runtime by StandAlone and AddOn mods, allowing for them to easily modify shader behavior. Here's an example mod for SOMA in both StandAlone and AddOn configuration that makes a simple edit to the game's posteffect_tonemapping_frag.hpsl shader. After loading either version, you can see that the entire game is now in black and white!

Alternatively, vanilla shaders can be directly modified in the core\shaders\ directory of your game install. This can be useful for more complex shader mods which edit the few shaders that cannot be reliably overwritten by normal StandAlone or AddOn mods, which are currently:

  • base_vtx.hpsl
  • base_frag.hpsl
  • cache_terrain_diffuse_frag.hpsl
  • clear_frag.hpsl
  • clear_vtx.hpsl
  • deferred_base_frag.hpsl
  • deferred_base_vtx.hpsl
  • deferred_skybox_frag.hpsl
  • deferred_terrain_gbuffer_frag.hpsl
  • deferred_terrain_tess_cs.hpsl
  • deferred_terrain_tess_es.hpsl
  • deferred_terrain_vtx.hpsl
  • null_frag.hpsl
  • null_frag_array.hpsl
  • null_frag_array2.hpsl
  • null_vtx.hpsl

These likely have special behavior in-engine that changes the way they're loaded when compared to other shaders. More testing will be needed to determine why this is the case.

Set Up

Edit your mod's resources.cfg file to include the following:

<Resources>
    <Directory Path="/core" AddSubDirs="true" />
</Resources>

GLSL shaders should be located in your mod's core\shaders\ directory and HPSL shaders should be in core\shaders\hpsl. For existing shaders, your shader MUST have the same name and path as the shader you're trying to overwrite. Most of the shader list is hardcoded within the executable and there is no known way to create new GpuPrograms or delete existing ones without access to the source code. For a simple AddOn that just alters shaders, your file structure will likely look like this:

modFolder/
├── core/
   ├── shaders/
      ├── hpsl/
├── entry.hpc
├── resources.cfg

SOMA

Beyond this, the setup process for SOMA is extremely straightforward and is as simple as placing your shaders in your mod's core\shaders\ directory, and your changes should be reflected in-game after loading your mod. Keep in mind that not all shader code is compiled on startup and is often conditional depending on what is being rendered in the current map, so some changes will not be immediately apparent!

Amnesia: Rebirth and Amnesia: The Bunker

For Amnesia: Rebirth and Amnesia: The Bunker, LoadShaderCache MUST be set to false in your mod's user settings configuration file for your mod's custom shaders to be reflected in-game. This will likely lead to slightly degraded performance, but this doesn't seem too noticeable on modern hardware. You will need to overwrite the base game's default_user_settings.cfg in the config folder to automatically set LoadShaderCache to false (for Rebirth) OR you will need to manually instruct users to set LoadShaderCache to false in their .cfg file (for Bunker).

NOTE: Make sure SaveShaderCache is set to false! This has much worse performance degradation and worse compatibility than LoadShaderCache, as it constantly regenerates the shadercache.xml file in _shadersource at runtime. This may be useful for directly editing shaders within your base install, but is unlikely to be useful for StandAlone or AddOn mods.