This article relates to the game "Team Fortress 2". Click here for more information.

Pyrovision

From Valve Developer Community
Jump to: navigation, search

English (en)español (es)
Edit
ctf_2fort with the Pyro vision effect applied.

Pyro vision is an effect applied in the game Team Fortress 2. It allows the player to enter the imaginary world featured in the "Meet the Pyro" animated short.

It works by using a material replacement list and a custom developed shader.

Material replacement

When a material is loaded, it attempts to find a replacements.vmt file in that directory. If it doesn’t find one in that immediate directory, it will attempt to find one going up in the directory hierarchy through the materials directory. Both the original material and the replacement material are fully loaded, so you should be cautious about how many new textures are introduced via the replaced material.

The replacements.vmt file is split into two sections: patterns and templates. Patterns represent a partial material name match. If a match is found, the template specified will point to a name in the template section for the alternate material. Within each template, you must specify a sub section which represents the original source shader type. Under that, you specify the replaced shader type and the parameters associated with it.

Patterns

Patterns represent a sequence list of starting name matches. The replacement system will sequentially scan down the list until a name pattern matches. Thus, you can put very specific material name matches higher up in the list and general name matches later on. For example:

patterns
{
	concretewall001d	// matches concretewall001d*
	{
		template	"peach02"
	}
	concretewall012d	// matches concretewall012d*
	{
		template	"pink01"
	}
	concretewall		// matches concretewall* ( except if matched by what is above )
	{
		template	"blue01"
	}
}

A material named "concretewall001d" or "concretewall001dnew" would get mapped to "peach02", "concretewall012d" would to mapped to "pink01" and anything else that begins with "concretewall" would get matched to "blue01".

Templates

Templates specify the replacement definition for the material. Under each template name you specify the shader type that is replaced. This allows you to have one template which can handle multiple shader sources, such as both VertexLitGeneric and LightmappedGeneric. Under each shader type, you specify a brand new shader definition. For Pyrovision, most new shaders are of type pyro_vision, though in reality it can be an type of shader that can handle the incoming vertex format from the source shader.

Parameters that you specify can both be your own custom values. If you specify a value that starts with a dollar sign, it will attempt to use that as a source field to copy over the value from the original material definition. Finally, if you specify a key of "$copyall" with any value, it will copy all source material parameters down.

templates
{		
peach02	// template name
	{
		"LightmappedGeneric"	// source shader type for LightmappedGeneric
		{
			pyro_vision		// new replaced shader type and material definition
			{
				$basetexture			$basetexture
				$vertexcolor			$vertexcolor

				$EFFECT				1
				$COLORBAR				"rj/colorbar_peach02"
					
				$DIFFUSE_WHITE			0.5
				$GRAY_POWER				0.8
				$GRAY_STEP				"[ 0.0 1.0 ]"
				$LIGHTMAP_GRADIENTS		255
			}
		}
		"VertexLitGeneric"	// source shader type for VertexLitGeneric
		{
			pyro_vision
			{
				$EFFECT				1
				$VERTEX_LIT				1
					
				$basetexture			"pyroconcretewall"
				$vertexcolor			$vertexcolor

				$EFFECT				1
				$COLORBAR				"rj/colorbar_patch02"

				$DIFFUSE_WHITE			0.5
				$DIFFUSE_BASE			0.1
				$GRAY_POWER				0.4
				$GRAY_STEP				"[ 0.0 1.0 ]"
				$LIGHTMAP_GRADIENTS		255
			}
		}
	}
}

See also

Pyro vision (shader)

Dreams of Chronic and Sustained Cruelty A blog post about how the pyro vision effect was developed.