Garry's Mod Wiki

IMaterial

A Material object. It represents a game material, similarly to how a .vmt file does, which are in fact loaded into an IMaterial object.

In most cases the game works with materials as far as file paths go. Materials then point to different ITextures (.vtf files) they might be using.
They are not the same and cannot be interchanged.

A material object can be created with Material or CreateMaterial.

Methods

Color IMaterial:GetColor( number x, number y )
Returns the color of the specified pixel of the $basetexture, only works for materials created from PNG files. Basically identical to ITexture:GetColor used on IMaterial:GetTexture( "$basetexture" ).
number IMaterial:GetFloat( string materialFloat )
Returns the specified material value as a float, or nil if the value is not set.
number IMaterial:GetInt( string materialInt )
Returns the specified material value as a int, rounds the value if its a float, or nil if the value is not set. Note: Please note that certain material flags such as $model are stored in the $flags variable and cannot be directly retrieved with this function. See the full list here: Material Flags
table IMaterial:GetKeyValues()
Gets all the key values defined for the material.
VMatrix IMaterial:GetMatrix( string materialMatrix )
Returns the specified material matrix as a int, or nil if the value is not set or is not a matrix.
string IMaterial:GetName()
Returns the name of the material, in most cases the path.
string IMaterial:GetShader()
Returns the name of the materials shader. This function does not work serverside on Linux SRCDS.Issue Tracker: 3256
string IMaterial:GetString( string materialString )
Returns the specified material string, or nil if the value is not set or if the value can not be converted to a string.
ITexture IMaterial:GetTexture( string param )
Returns an ITexture based on the passed shader parameter.
Vector IMaterial:GetVector( string materialVector )
Returns the specified material vector, or nil if the value is not set. See also IMaterial:GetVectorLinear
Returns the specified material vector as a 4 component vector.
Vector IMaterial:GetVectorLinear( string materialVector )
Returns the specified material linear color vector, or nil if the value is not set. See https://en.wikipedia.org/wiki/Gamma_correction See also IMaterial:GetVector
number IMaterial:Height()
Returns the height of the member texture set for $basetexture.
boolean IMaterial:IsError()
Returns whenever the material is valid, i.e. whether it was not loaded successfully from disk or not.
IMaterial:Recompute()
Recomputes the material's snapshot. This needs to be called if you have changed variables on your material and it isn't changing. Be careful though - this function is slow - so try to call it only when needed!
IMaterial:SetDynamicImage( string path )
Changes the Material into the give Image. Internal: This is used internally - although you're able to use it you probably shouldn't. This is used by the Background to change the Image.
IMaterial:SetFloat( string materialFloat, number float )
Sets the specified material float to the specified float, does nothing on a type mismatch.
IMaterial:SetInt( string materialInt, number int )
Sets the specified material value to the specified int, does nothing on a type mismatch. Note: Please note that certain material flags such as $model are stored in the $flags variable and cannot be directly set with this function. See the full list here: Material Flags
IMaterial:SetMatrix( string materialMatrix, VMatrix matrix )
Sets the specified material value to the specified matrix, does nothing on a type mismatch.
IMaterial:SetShader( string shaderName )
Deprecated: We advise against using this. It may be changed or removed in a future update. This function does nothing The functionality of this function was removed due to the amount of crashes it caused.
IMaterial:SetString( string materialString, string string )
Sets the specified material value to the specified string, does nothing on a type mismatch.
IMaterial:SetTexture( string materialTexture, ITexture texture )
Sets the specified material texture to the specified texture, does nothing on a type mismatch.
IMaterial:SetUndefined( string materialValueName )
Unsets the value for the specified material value.
IMaterial:SetVector( string MaterialVector, Vector vec )
Sets the specified material vector to the specified vector, does nothing on a type mismatch.
IMaterial:SetVector4D( string name, number x, number y, number z, number w )
Sets the specified material vector to the specified 4 component vector, does nothing on a type mismatch.
number IMaterial:Width()
Returns the width of the member texture set for $basetexture.