Material

A Material describes the surface of anything drawn on the graphics card! It is typically composed of a Shader, and shader properties like colors, textures, transparency info, etc.

Items drawn with the same Material can be batched together into a single, fast operation on the graphics card, so re-using materials can be extremely beneficial for performance!

Instance Methods

   
Material Creates a material from a shader, and uses the shader’s default settings. Uses an auto-generated id.
Copy Creates a new Material asset with the same shader and properties! Draw calls with the new Material will not batch together with this one.
SetColor Sets a shader parameter with the given name to the provided value. If no parameter is found, nothing happens, and the value is not set!
SetFloat Sets a shader parameter with the given name to the provided value. If no parameter is found, nothing happens, and the value is not set!
SetMatrix Sets a shader parameter with the given name to the provided value. If no parameter is found, nothing happens, and the value is not set!
SetTexture Sets a shader parameter with the given name to the provided value. If no parameter is found, nothing happens, and the value is not set!
SetVector Sets a shader parameter with the given name to the provided value. If no parameter is found, nothing happens, and the value is not set!

Static Fields and Properties

   
Cull FaceCull How should this material cull faces?
int ParamCount The number of shader parameters available to this material.
int QueueOffset This property will force this material to draw earlier or later in the draw queue. Positive values make it draw later, negative makes it earlier. This can be helpful for tweaking performance! If you know an object is always going to be close to the user and likely to obscure lots of objects (like hands), drawing it earlier can mean objects behind it get discarded much faster! Similarly, objects that are far away (skybox!) can be pushed towards the back of the queue, so they’re more likely to be discarded early.
Shader Shader Gets a link to the Shader that the Material is currently using
Transparency Transparency What type of transparency does this Material use? Default is None. Transparency has an impact on performance, and draw order. Check the Transparency enum for details.
bool Wireframe Should this material draw only the edges/wires of the mesh? This can be useful for debugging, and even some kinds of visualization work.

Static Methods

   
Find Looks for a Material asset that’s already loaded, matching the given id!

Examples

Material parameter access

Material does have an array operator overload for setting shader parameters really quickly! You can do this with strings representing shader parameter names, or use the MatParamName enum for compile safety.

exampleMaterial[MatParamName.DiffuseTex] = gridTex;
exampleMaterial[MatParamName.TexScale  ] = 2;