Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Material.SetMatrix

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public function SetMatrix(propertyName: string, matrix: Matrix4x4): void;
public void SetMatrix(string propertyName, Matrix4x4 matrix);
public def SetMatrix(propertyName as string, matrix as Matrix4x4) as void
public function SetMatrix(nameID: int, matrix: Matrix4x4): void;
public void SetMatrix(int nameID, Matrix4x4 matrix);
public def SetMatrix(nameID as int, matrix as Matrix4x4) as void

Description

Set a named matrix for the shader.

This is mostly used with custom shaders that need extra matrix parameters. Matrix parameters are not exposed in the material inspector, but can be set and queried with SetMatrix and GetMatrix from scripts.

See Also: GetMatrix, Materials, ShaderLab documentation, Shader.PropertyToID

	var rotateSpeed = 30;
	var texture : Texture;

function Start() { // Create a new material with a shader // that rotates the texture. Texture rotation // is performed with a _Rotation matrix. var m : Material = new Material ( "Shader \"Rotating Texture\" {" + "Properties { _MainTex (\"Base\", 2D) = \"white\" {} }" + "SubShader {" + " Pass {" + " Material { Diffuse (1,1,1,0) Ambient (1,1,1,0) }" + " Lighting On" + " SetTexture [_MainTex] {" + " matrix [_Rotation]" + " combine texture * primary double, texture" + " }" + " }" + "}" + "}" ); m.mainTexture = texture; renderer.material = m; }

function Update() { // Construct a rotation matrix and set it for the shader var rot = Quaternion.Euler (0, 0, Time.time * rotateSpeed); var m = Matrix4x4.TRS (Vector3.zero, rot, Vector3(1,1,1) ); renderer.material.SetMatrix ("_Rotation", m); }