Skip to content

Asset: Techsets

fed edited this page Jun 5, 2023 · 1 revision

Techsets

Definition

Techsets (or Material Technique Sets) are sets of rendering techniques that are used to render textures. They are responsible for how almost everything looks the way it does in-game. Each technique has different properties which will render the texture in a different way. The technique that should be used is chosen by the engine based on lighting conditions and other variables.
The individual techniques contain various shader types:

and also store shader arguments, typically either a 1x4 or 4x4 float matrix:

  • code constant: the value is generated by the engine and varies, it is referenced using a numerical id.
  • literal constant: the value is fixed and stored within the argument.
  • material constant: same as literal constant but the value is stored within the material.
  • code texture
  • code sampler
  • material texture
  • material sampler

Additionally to the argument value the argument also has a field called dest (destination) which indicates the index of the constant buffer the argument is copied to. Other fields are also present but there isn't enough information known about them.

Conversion

Techsets from different games are not always compatible and require conversion. The number of techniques and code constants usually changes so they must be remapped. Incorrect code constant ids can result in very bad rendering bugs and issues.
Additionally the shaders themselves might not always work correctly when ported, this was the case when porting from H2 to H1 (but not the opposite). This is caused by difference in constant buffer sizes (H2 > H1), which causes the value of the destination buffer to be too big which results in the same visual bugs caused by incorrect code constant ids.
Both of these cases are already handled by zonetool and shouldn't require any intervention by the user.

Parsing & dumping

Techsets are dumped to the techset folder.
Techniques and techsets are dumped in separate files (.techset, .technique)

Currently zonetool does not support parsing of custom techsets or techniques.

Structure

struct MaterialArgumentCodeConst
{
	unsigned short index;
	unsigned char firstRow;
	unsigned char rowCount;
};

union MaterialArgumentDef
{
	float* literalConst;
	MaterialArgumentCodeConst codeConst;
	unsigned int codeSampler;
	unsigned int nameHash;
};

enum MaterialShaderArgumentType : std::uint8_t
{
	MTL_ARG_CODE_CONST = 0x0,
	MTL_ARG_CODE_TEXTURE = 0x1,
	MTL_ARG_CODE_SAMPLER = 0x2,
	MTL_ARG_MATERIAL_CONST = 0x3,
	MTL_ARG_LITERAL_CONST = 0x4,
	MTL_ARG_MATERIAL_TEXTURE = 0x5,
	MTL_ARG_MATERIAL_SAMPLER = 0x6,
	MTL_ARG_COUNT = 0x7,
};

struct MaterialShaderArgument
{
	unsigned char type;
	unsigned char shader;
	unsigned short dest;
	MaterialArgumentDef u;
};

struct MaterialPass
{
	MaterialVertexShader* vertexShader;
	MaterialVertexDeclaration* vertexDecl;
	MaterialHullShader* hullShader;
	MaterialDomainShader* domainShader;
	MaterialPixelShader* pixelShader;
	unsigned char pixelOutputMask;
	unsigned char perPrimArgCount;
	unsigned char perObjArgCount;
	unsigned char stableArgCount;
	unsigned short perPrimArgSize;
	unsigned short perObjArgSize;
	unsigned short stableArgSize;
	unsigned short zone;
	unsigned char perPrimConstantBuffer;
	unsigned char perObjConstantBuffer;
	unsigned char stableConstantBuffer;
	unsigned int customBufferFlags;
	unsigned char customSamplerFlags;
	unsigned char precompiledIndex;
	unsigned char stageConfig;
	MaterialShaderArgument* args;
};

struct MaterialTechniqueHeader
{
	const char* name;
	unsigned short flags;
	unsigned short passCount;
};

struct MaterialTechnique
{
	MaterialTechniqueHeader hdr;
	MaterialPass passArray[1];
};

struct MaterialTechniqueSet
{
	const char* name;
	unsigned short flags;
	unsigned char worldVertFormat;
	unsigned char preDisplacementOnlyCount;
	MaterialTechnique* techniques[TECHNIQUE_COUNT];
};

Overview

Guides

Assets

Clone this wiki locally