MaterialExtract class extracts Source 2 materials to editable vmat (Valve Material) format with associated texture files.
Constructor
The material data to extract.
Resource edit information containing metadata.
File loader for resolving texture dependencies.
Provider for shader-specific data. Defaults to
BasicShaderDataProvider.Alternate Constructor
The material resource to extract. Must contain a Material data block.
File loader for resolving dependencies. If provided, uses
ShaderDataProvider.Methods
ToContentFile
ContentFile - Content file containing vmat data with texture files in AdditionalFiles.
Behavior:
- Generates vmat KeyValues format file
- Loads and unpacks referenced textures
- Extracts texture channels into separate material maps
- Skips default textures and uniform-only textures when appropriate
ToValveMaterial
string - Material definition in KeyValues1 text format.
Format includes:
- Layer0 with shader name
- Integer, float, and vector parameters
- Texture parameters (unpacked to individual maps)
- Dynamic expressions
- Attributes and system attributes
- Tool attributes (e.g., SubrectDefinition)
- Original compiled texture paths for reference
GetTextureUnpackInfos
The material’s texture parameter name (e.g., “g_tColor”).
Path to the compiled texture file.
Loaded texture data, or null if not available.
Whether to skip default textures (materials/default/*).
Whether to skip textures that have uniform vector overrides.
IEnumerable<UnpackInfo> - Information about how to unpack texture channels.
Static Methods
OutTextureName
Path to the compiled texture (must end with .vtex).
Whether to preserve the original file extension from the hash.
Whether this is an HDR texture (determines .exr vs .png).
Optional suffix to append (e.g., “_rough”, “_metal”).
string - The generated output file name.
Logic:
- Strips
.vtexextension and.generatedsuffix - Attempts to extract original filename from hash-based naming
- Replaces texture type suffixes when desiredSuffix is provided
- Adds appropriate image extension (.exr or .png)
Helper Types
UnpackInfo (struct)
Information about how to unpack a texture channel.The texture parameter name for the unpacked channel.
The output file name for this unpacked texture.
Which channel(s) to extract from the source texture.
Usage Examples
Basic Material Extraction
Get Material as String
Custom Texture Unpacking
Material Format
The generated vmat file follows this structure:Notes
- The class automatically unpacks packed texture channels (e.g., roughness/metalness/AO)
- Default textures from
materials/default/can be optionally omitted - Textures with uniform vector overrides can be skipped to reduce file size
- Original compiled texture paths are preserved in a “Compiled Textures” section
- The shader data provider determines how textures are unpacked based on shader type
- Layered material names (e.g., TextureColorA vs TextureColor) are properly handled