Converting Materials

From Pragma
Jump to: navigation, search

Description

Generally you don't need to convert textures(.vtf-files) or materials(.vmt-files) from the source engine, as they're supported directly (You should just be able to copy the files). This is, however, not recommended, and you should convert them to the appropriate formats in pragma.
Converting materials from the source engine is a two step process:

Convert texture

First of all you have to convert all of the .vtf-files associated with your material. To do that, you'll need a vtf-plugin for your image manipulation software, e.g.:

You will also need an additional plugin, depending on what target-format you want to use. Supported formats are: .png, .dds, .ktx, .vtf and .tga. You can find more information about when to use which format here.

Convert to .png / .tga

This is very straight-forward, simply load the .vtf in your image manipulation program, and export it as .png/.tga. No additional plugins should be required.

Convert to .dds

You'll need an additional .dds-plugin to be able to export your image as .dds:

Once you have that installed, simply import the .vtf-file, and export it as .dds. It is highly recommended that you use a compressed format, more specifically:

  • DXT1/BC1: Use this format if your image contains no alpha-channel and if quality is not very important.
  • DXT3/BC2: This format is mostly deprecated. The compression for the alpha-channel is slightly different compared to DXT5, but for most cases you should stick to DXT5.
  • DXT5/BC3: For most cases this format should have the best quality/file size ratio. For normal maps, you might want to use BC5 for better quality instead.
  • BC5/3Dc: This format will usually result in the best quality, but will also increase the image file size significantly. Use this format especially when dealing with normal maps.

Other formats are not guaranteed to work!

Convert to .ktx

This is the recommended format for most cases, however it requires an intermediate step, since there are no .ktx-plugins for Gimp or Photoshop at this time.
First of all, you'll have to download the PVRTexTool, which is included in the PowerVR Tools package. You can uncheck all of the other tools during installation.
Once it's installed, load your source .vtf-file in your image manipulation program and export it in a lossless common format (e.g. .png).
Next, start the PVRTexTool and load the .png-image. Next, you have to generate the mipmaps for the image. To do so, follow these steps:
1) Click on the PVRTexToolGUI 2016-04-06 11-55-20.png-Icon, set the "Sample Filter" to "Linear" and the "Number Of MIP Maps" to "Full MIP Map Chain", then click on "Generate MIP Maps".
2) Go to Edit >> Encode, a new window should pop up. Select "DirectX 11 (11_1)" from the drop-down menu for "Group/API" on the left side and an appropriate BCx-compression algorithm from the right side. Click "Encode" to close the window and start the encoding. This may take a few seconds.
3) Select the encoded image from the "Surface Browser"
4) Go to File >> Save As..., change the file type to "Khronos Textures (*.ktx)" and save your image.

ETC2 compression-algorithms are also supported by the engine, but they might not be supported by some GPUs, so avoid using them.
You can read more about the ETC2 compression codec here.

Convert material

Converting the material (.vmt) is fairly straight-forward. First, create a new text-file and change the extension to ".wmi", then open it in a text editor. The contents of the .wmi-file are dependent on what you intend to use it for, you can find a list of available parameters here. Here are some examples:

World and Model Materials

This is most likely what you will be using for most materials:

"LightmappedGeneric"
{
	"$baseTexture" "wood/woodwall048_roof"
	"$bumpmap" "wood/woodwall048_roof_normal"
	"$surfaceprop" "wood"
	"%keywords" "ep2"
}

becomes:

"textured"
{
	$texture diffusemap "wood/woodwall048_roof"
	$texture normalmap "wood/woodwall048_roof_normal"
	$string surfacematerial "wood"
}

Skybox Materials

"sky"
{
	"$basetexture" "skybox/sky_ep02_02bk"
	"$nofog" 1
	$ignorez 1
	"$basetexturetransform" "center 0 0 scale 1 2 rotate 0 translate 0 0"
}

becomes:

"skybox"
{
	$cubemap skybox "skybox/sky_ep02_02" // This will expect to find the following texture image files: "skybox/sky_ep02_02bk", "skybox/sky_ep02_02dn", "skybox/sky_ep02_02ft", "skybox/sky_ep02_02lf", "skybox/sky_ep02_02rt", "skybox/sky_ep02_02up"
}

Note: In the Source engine you have a separate material file for each side of the skybox texture, this is not the case in Pragma. Just create 1 material for the entire skybox without any postfix ("bk", etc.).

Particle Materials

"particle"
{
	$texture diffusemap "particles/fire_sprites_v1"
	animation
	{
		$int offset 0
		$int frames 64
		$int fps 46
		$int columns 8
		$int rows 8
	}
}

When using animated particle textures, a single image with a sprite-sheet is expected. 'frames' is the number of sprite images that should be used, 'offset' is an offset in sprite images (if any), 'rows' and 'columns' are the number of sprite image rows and columns inside the file. For example, the above definition is an animation which uses every frame from this image:
Fire sprites v1.png

See Also