Garry's Mod Wiki

Material Parameters

This page describes possible values for the second parameter of the Material function when importing .png or .jpg textures, as well as some specific material key-values being set in that process.

For a list of all flags that can be controlled by settings the $flags int, see https://developer.valvesoftware.com/wiki/Material_Flags

Possible values are:

Value Description
vertexlitgeneric Makes the created material a VertexLitGeneric, so it can be applied to models. Default shader is UnlitGeneric
nocull Sets the $nocull to 1 in the created material.
alphatest Sets the $alphatest to 1 in the created material instead of $vertexalpha being set to 1.
mips Generates Mipmaps for the imported texture, or sets No Level Of Detail and No Mipmaps if unset. This adjusts the material's dimensions to a power of 2.
noclamp Makes the image able to tile when used with non standard UV maps or surface.DrawTexturedRectUV. Sets the CLAMPS and CLAMPT flags if unset.
smooth If set does nothing, if unset - enables Point Sampling (Texture Filtering) on the material as well as adds the No Level Of Detail flag to it.
ignorez If set, the material will be given $ignorez flag, which is necessary for some rendering operations, such as render targets and 3d2d

Additional Notes

When you call Material with a file extension, the engine creates a material and a new texture from that file.

The created texture will have its size set to the closest power of two size.

The material is given the following parameters by default:

"UnlitGeneric" { "$basetexture" "<set to the newly created texture>" "$vertexcolor" "1" "$realwidth" "X" // The width of the actual png/jpg file "$realheight" "X" // The height of the actual png/jpg file // Custom parameters "$nocull" "1" // Only set if nocull parameter is given "$alphatest" "1" // Only set if alphatest parameter is given "vertexalpha" "1" // Only set if alphatest parameter is NOT given }

vertexlitgeneric

This is used in the VMT of most models that need correct lighting and shadows. You don't really need to worry about it for 2D textures though, since they don't need lighting. The other commonly used option is unlitgeneric, which makes the model have no lighting at all, similar to typing mat_fullbright 1 in the console. It is unknown why it exists for 2D textures though, probably just for usage with Mesh.

nocull

This makes the back of the texture get drawn all the time. If you're working in cam.Start3D2D then it can help if you want a double sided texture.

alphatest

This makes the material have an alpha of either 0 or 1, instead of a range between those values. It makes the alpha edges look very hard, but it can fix some transparency related problems. It can be used to allow alpha in stencils. If you're trying to use a material in a stencil with an alpha channel, use alphatest. It also allows the flashlight cast shadows from the material.

mips

This makes low-res versions of the texture that it swaps out as it gets smaller. It can help improve performance, and you usually can't see the difference.

This can improve smoothing if you're scaling down the texture a lot.

noclamp

This allows the texture to tile, so if you want a repeating pattern then it can help. surface.DrawTexturedRectUV will help you draw a pattern. It also stops the edges getting stretched, which can make it look smoother.

smooth

This stops point sampling, which makes textures look like Minecraft. It makes the texture look smoother when you scale it.