Shaders

Shaders

Lumberyard supports writing custom shaders. Lumberyard follows Physically Based Rendering (PBR) techniques and is almost fully deferred. It uses forward only for translucent materials or for hair/skin. Lumberyard runs DirectX for graphics and uses a shader language similar to Cg/HLSL. Shader files are of three main types:

*.cfi [dev\Engine\Shaders\HWScripts\CryFX] – include files
*.cfx [dev\Engine\Shaders\HWScripts\CryFX] – shader files containing shader params
*.ext [dev\Engine\Shaders] – shader generation params for shader

Shader params are similar to having constants declared in the shader that affect the shading process. Properties such as alpha composition, opacity, etc, are shader parameters. Shader generation param, on the other hand, are values that define the overall working of the shader. Parameters such as whether the shading should be simple or advanced fall under shader generation parameters. A lot of the times, some shader parameters will only be exposed according to the shader parameters that are set.

Setup

Setting up a custom shader in Lumberyard is not very hard. Run-time compilation of shaders makes it easy to immediately see the changes made in a shader in the game, and hot reloading of shaders is also supported.
Setting up a custom shader:

  1. You’ll need a .ext and .cfx file for your shader
  2. dev\Editor\Materials\ShaderList.xml
    Add your shader to the list:
    <Shader name=”MyTestShader” />
  3. Copy:
    MyTestShader.ext -> dev\Engine\Shaders
    MyTestShader.cfx -> dev\Engine\Shaders\HWScripts\CryFX
  4. In Lumberyard, restart Tools->Material Editor
  5. In the Material Editor, create a new material and under Material Settings, attach your shader from the drop down menu under Material Settings->Shader.

For hot reloading of shaders, open dev\system_windows_pc.cfd (or another config file according to OS) and append to the file:
sys_PakPriority=0 (to ensure shaders load from file system instead of pak files)
r_ShadersEditing=1 (to enable shader recompilation at runtime)
To reload shaders in a game executable, go to the console at dev\ and type:
> r_reloadshaders 1

Resources

Sidebar