MaterialPropertyBlock.AddMatrix 添加矩阵

function AddMatrix (name : string, value : Matrix4x4) : void
function AddMatrix (nameID : int, value : Matrix4x4) : void

Description描述

Add a matrix material property.

添加一个矩阵材质属性。

For performance reasons, the property block can contain only a limited number of property values. Two 4x4 matrices, six vectors/colors or 12 floats can be stored in the block. Storage space for the values is shared, so storing one matrix leaves twice less space to store vectors and floats. When block's storage is filled up, additional Add calls will be ignored.

出于性能原因,属性块只能包含属性值的有限数量。两个4x4矩形,六个向量/颜色或存12个浮点数可以存储在这个块中,存储空间的值被共享,所以存储一个矩阵留下两倍少的空间来存储向量和浮点数。当块的存储空间填满后,额外的Add调用将被忽略。

Function variant that takes nameID is faster. If you are adding properties with the same name repeatedly, use Shader.PropertyToID to get unique identifier for the name, and pass the identifier to AddMatrix.

使用nameID的函数变量更快,如果你重复添加相同名称的属性,使用Shader.PropertyToID得到唯一的名称标识,并传递这个标示到AddColor。

var rotateSpeed = 30;
var texture : Texture;
var aMesh : Mesh;

// Create a new material with a shader
// that rotates the texture. Texture rotation
// is performed with a _Rotation matrix.
//创建一个新的材质带有一个旋转纹理shader。纹理选择由一个_Rotation矩阵执行
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;


function Update() {
	var materialProperty : MaterialPropertyBlock = new MaterialPropertyBlock();
	// Construct a rotation matrix and set it for the shader
	//构造一个旋转矩阵并设置它
	var rot : Quaternion = Quaternion.Euler (0, 0, Time.time * rotateSpeed);
	var mtrx : Matrix4x4 = Matrix4x4.TRS (Vector3.zero, rot, Vector3(1,1,1) );

	// Update the rotation matrix.
	//更新这个旋转矩阵
	materialProperty.AddMatrix ("_Rotation", mtrx);
	Graphics.DrawMesh(aMesh, Vector3(-5,0,0), Quaternion.identity,
	m, 0, null, 0, materialProperty);
}
Page last updated: 2011-3-1