Shader Patch Textures - PrismaticFlower/shaderpatch GitHub Wiki

Contents

Intro

When using custom materials Shader Patch has no way identifying normal textures used by the game. This is problematic if we want to pass more than just a detail texture to a shader. Furthermore the tool for baking textures for use by the game is severely dated; having support for support for only basic TGA images and block compression that produces obvious visual artifacts.

To solve these problems Shader Patch comes with it's own version of texturemunge. In short it,

  • Wraps textures up into a format for consumption by SP.
  • Supports processing .tga, .png, .exr and .dds images.

Texture Config Files

To determine which images to munge into textures the Shader Patch's tool searches for YAML files of the form name.*.tex. (Where * is replaced with the image container extension, such as png.) When it finds one it munges it, searching for name.* to use as the input image.

As an example texture config files look like this.

Type: image

Uncompressed: no

sRGB: yes

PremultiplyAlpha: no

Below is documentation on what each of those options does.

Type

Controls the type of the texture, potentially causing unique handling of certain aspects of image processing. The following types are currently defined.

Type Description
image Basic texture type, does nothing.
roughness Indicates that the input file is a Roughness Map and that it should be converted to a Metallic-Roughness Map. This is done by shifting the red channel of the input file into the green channel and setting the entire red channel to 0. If PairedImage is specified it is interpreted as a normal map that is used to apply specular AA to the roughness map.
metellicroughness Indicates that the input file is a Metellic-Roughness Map. If PairedImage is specified it is interpreted as a normal map that is used to apply specular AA to the roughness map.
normalmap Indicates that the texture is a normal map and that it should receive special processing to preserve the normals during mip generation.
cubemap Indicates the input texture is an unfolded 4x3 cubemap and that it should be folded into a cubemap. The layout for these textures is the same as stock cubemaps.
passthrough Indicates that no processing should attempted to be done on the texture and it should be passed through to Shader Patch as is. This is intended for use with .dds files.

Uncompressed

A boolean value indicating whether to compress the texture or not. On false the texture will be compressed, on true the texture will be left uncompressed. This is named "Uncompressed" so that the default option is well defined as using compression.

Due to the high number of textures some custom materials can require I strongly advise only setting this to true when it is necessary. Basically, make sure you've spotted unacceptable texture artifacting in game first.

sRGB

A boolean value indicating whether the input image is in sRGB space or not. On true the image will be processed as sRGB while creating the texture and the resulting texture marked as sRGB. Vice-versa for false.

If you're unsure what sRGB is and what to set this then refer to the table below. (This is just what I think is most likely feel free to help me out and edit this page if you have a better idea!)

Texture Type Colour Space
Diffuse/Albedo Texture sRGB
Emissive Texture sRGB
Envmap sRGB
AO Texture Linear
Height Texture Linear
Roughness/Metallicness Texture Linear
Normalmap Texture Linear

PremultiplyAlpha

A boolean value indicating whether to convert the input image to premultiplied alpha or not. The correct value for this depends on the target material type of the material using this texture. If the material transparent textures to have premultiplied alpha then this should be yes else it should be no. If the input texture has no alpha channel it should always be no.

CompressionFormat

The compression format to use. Below is an overview of each one supported and what to use it for. (For a more in depth look see here.)

Name Type Size Use For
BC4 Greyscale 0.5 byte/px greyscale maps, ao map, height map, etc
BC5 RG 1 byte/px normal map, metallic-roughness map
BC6H_UF16 RGB 1 byte/px HDR data
BC7 RGB 1 byte/px color maps
BC7_ALPHA RGBA 1 byte/px color maps with alpha, normal maps with alpha, etc

In general just referencing the above table should be all you need to do to get great results when writing your texture config files.

PairedImage

Specifies the filename (including extension) of a paired image. The image should be in the same folder as the .tex file. The exact meaning of this depends on the texture type.

Munger

In general you shouldn't have to worry about the actual tool itself and can instead focus on the config files. But if you find yourself in the need of writing a script to call it or feel the urge to invoke it directly this section contains documentation on sp_texture_munge.exe's command arguments.

Option Usage Brief
-?, -h, --help Display the list of arguments.
--outputdir, -o <output directory> Path to place munged files in.
--sourcedir, -s <source directory> Path to search for input texture files.
--inputfilter, -f <input filter> Regular Expression (EMCA Script syntax) Filter to test files in the source directory against.

Below is a slightly more detailed description of each argument and it's effect.

outputdir

The target directory that all processed textures will be placed in. If the directory doesn't exist the tool will attempt to create it, if it fails the tool exits displaying an error.

sourcedir

The source directory to search for input files in. The search is recursive. If a freestanding config file is found, that is a file that passes the input filter but lacks an accompanying image file the tool will display an error.

inputfilter

A regular expression used as a filter for input files. It uses EMCA Script syntax. A test for matches will done against the path of each found file in the source directory, if one match is found the file is considered a YAML texture config. This argument is completely optional and has the default value of .+\.tex.