vmt

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2019 License: Unlicense Imports: 5 Imported by: 0

README

GoDoc Go report card GolangCI CircleCI codecov

vmt

Vmt is a parser for Valve Material Format (.vmt) files.

Vmt's in Source can be a little painful; large number of possible parameters, many being specific to a particular shader. This package exists to reduce the pain of parsing materials.

You can use either the Properties struct provided, or a custom definition to only get the properties desired. Properties must be correctly typed in whatever definition is used.

If there are parameters missing from the standard Properties definition, please submit a PR to add them.

For now, nested properties are unsupported (e.g. Proxies).

Usage:

There are 3 ways to read material definitions using this package:

From a github.com/golang-source-engine/filesystem

This is the recommended solution, as it is the only method of resolving a material that uses the include property.

var fs *filesystem.Filesystem // create this elsewhere
result := vmt.NewProperties()
mat,err := vmt.FromFilesystem("metal/metal_01.vmt", fs, result)
From a stream
stream,_ := os.Open("metal/metal_01.vmt")
result := vmt.NewProperties()
mat,err := vmt.FromStream(stream, result)
From existing github.com/galaco/keyvalues
var kv *keyvalues.KeyValue // create this elsewhere
result := vmt.NewProperties()
mat,err := vmt.FromKeyValues(kv, result)
Material Definitions

If you've ever used the build-in json package, this should be familiar. See the Properties struct in this package for the default material. However, you can define your own definition below:

package foo

type CustomShader struct {
    MyProperty string `vmt:$myproperty`
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorMaterialKeyValuesEmpty = errors.New("material contains empty key value(s)")
)

Functions

This section is empty.

Types

type Material

type Material interface{}

Material represents expected properties in a particular material It is important to define the following property in any implementation:

ShaderName string `vmt:"__SHADER_NAME__"`

Properties should be defined in the following format:

BaseTexture string `vmt:"$basetexture"`

func FromFilesystem

func FromFilesystem(filePath string, fs virtualFilesystem, definition Material) (Material, error)

FromFilesystem loads a material from filesystem Its important to note this is the ONLY way to automatically resolve `import` properties present in a vmt

func FromKeyValues

func FromKeyValues(kvs *keyvalues.KeyValue, definition Material) (Material, error)

FromKeyValues builds a material from keyvalue definitions. Please note that `include` keys cannot be automatically resolved using this method of parsing.

func FromStream

func FromStream(stream io.Reader, definition Material) (Material, error)

FromStream builds a material from a data stream. Please note that `include` keys cannot be automatically resolved using this method of parsing. In many cases it would be better to pass use FromFilesystem.

type Properties

type Properties struct {
	// ShaderName is special, as it is the only property where
	// the value we want is the key itself. __SHADER_NAME__ is a custom
	// key that the parser can manually map to.
	ShaderName string `vmt:"__SHADER_NAME__"`

	// Basics
	BaseTexture string `vmt:"$basetexture"`
	SurfaceProp string `vmt:"$surfaceprop"`
	Detail      string `vmt:"$detail"`
	Model       int    `vmt:"$model"`

	// Adjustment
	BaseTextureTransform string `vmt:"$basetexturetransform"`
	Color                string `vmt:"$color"`
	SeamlessScale        string `vmt:"$seamless_scale"`

	// Transparency
	Alpha                float32 `vmt:"$alpha"`
	AlphaTest            string  `vmt:"$alphatest"`
	BlendModulateTexture string  `vmt:"$blendmodulatetexture"`
	DistanceAlpha        string  `vmt:"$distancealpha"`
	NoCull               string  `vmt:"$nocull"`
	Translucent          int     `vmt:"$translucent"`

	// Lighting
	Bumpmap          string `vmt:"$bumpmap"`
	SSBump           string `vmt:"$ssbump"`
	ParallaxMap      string `vmt:"$parallaxmap"`
	Selfillum        int    `vmt:"$selfillum"`
	LightwarpTexture string `vmt:"$lightwarptexture"`
	HalfLambert      string `vmt:"$halflambert"`
	AmbientOcclusion string `vmt:"$ambientocclusion"`
	Rimlight         string `vmt:"$rimlight"`

	// Reflection
	Reflectivity string `vmt:"$reflectivity"`
	Phong        string `vmt:"$phong"`
	Envmap       string `vmt:"$envmap"`

	// Optimization
	IgnoreZ int `vmt:"$ignorez"`

	// Texture Organization
	CompileKeywords      string `vmt:"%keywords"`
	CompileNoToolTexture int    `vmt:"%notooltexture"`
	CompileToolTexture   string `vmt:"%tooltexture"`

	// Effect
	TreeSway string `vmt:"$treeSway"`
	NoFog    int    `vmt:"$nofog"`

	// Misc
	CompileClip        int `vmt:"%compileclip"`
	CompileDetail      int `vmt:"%compiledetail"`
	CompileLadder      int `vmt:"%compileladder"`
	CompileNoDraw      int `vmt:"%compilenodraw"`
	CompileNoLight     int `vmt:"%compilenolight"`
	CompileNonSolid    int `vmt:"%compilenonsolid"`
	CompilePassBullets int `vmt:"%compilepassbullets"`
	CompileSkip        int `vmt:"%compileskip"`
	CompileSky         int `vmt:"%compilesky"`

	AllowDiffuseModulation string `vmt:"$allowdiffusemodulation"`

	BasetextureNoEnvmap            string `vmt:"$basetexturenoenvmap"`
	BlendTintByBaseAlpha           string `vmt:"$blendtintbybasealpha"`
	BumpmapBaseTexture2WithBumpmap string `vmt:"$bumpbasetexture2withbumpmap"`
	BumpFrame                      string `vmt:"$bumpframe"`
	Bumpoffset                     string `vmt:"$bumpoffset"`
	BumpScale                      string `vmt:"$bumpscale"`
	BumpTransform                  string `vmt:"$bumptransform"`

	DisplacementMap string `vmt:"$displacementmap"`

	EmissiveBlend       string `vmt:"$emissiveblend"`
	EnvmapContrast      string `vmt:"$envmapcontrast"`
	EnvmapFrame         string `vmt:"$envmapframe"`
	EnvmapMask          string `vmt:"$envmapmask"`
	EnvmapMaskFrame     string `vmt:"$envmapmaskframe"`
	EnvmapMaskScale     string `vmt:"$envmapmaskscale"`
	EnvmpaMaskTransform string `vmt:"$envmapmasktransform"`
	EnvmapSaturation    string `vmt:"$envmapsaturation"`
	EnvmpaTint          string `vmt:"$envmaptint"`

	Flesh string `vmt:"$flesh"`

	MaxFogDensityScalar string `vmt:"$maxfogdensityscalar"`

	NoDraw    string `vmt:"$no_draw"`
	NoDecal   string `vmt:"$nodecal"`
	NormalMap string `vmt:"$normalmap"`
	NoTint    string `vmt:"$notint"`

	PointSampleMagFilter string `vmt:"$PointSampleMagFilter"`

	VertexAlpha int `vmt:"$vertexalpha"`
	VertexColor int `vmt:"$vertexcolor"`

	WriteZ int `vmt:"$writeZ"`
}

Properties is an example material that contains all known material properties. This should be updated as more properties are added or discovered in games.

func NewProperties

func NewProperties() *Properties

NewProperties returns *Properties

Directories

Path Synopsis
samples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL