MVP矩阵 :
MVP变换 :
模型 --> 视口 --> 摄像机的变换,对应于顶点的透视变换,为了产生立体效果。
struct v2f {
float4 pos : POSITION;
}
v2f vert(appdata_base v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP , v.vertex); // MVP矩阵与顶点相乘,MVP矩阵在左
return o;
} // 即可产生立体效果
用矩阵的方式完成物体的旋转 :
C#脚本 :利用旋转矩阵
update()
{
Matrix4x4 RM = new Matrix4x4();
RM[0,0] = Mathf.Cos(Time.realtimeSinceStartup);
RM[0,2] = Mathf.Sin(Time.realtimeSinceStartup);
RM[1,1] = 1;
RM[2,0] = -Mathf.Sin(TIme.realtimeSinceStartup);
RM[2,2] = Mathf.Cos(Time.realtimeSinceStartup);
RM[3,3] = 1;
GetComponent<Render>().material.SetMatrix("rm" , RM);
}
Shader :
float4x4 rm; //不加uniform,默认也会是uniform
v2f vert(appdata_base) {
v2f o;
float4x4 m = mul(UNITY_MATRIX_MVP , rm); // 得到MVP矩阵和旋转矩阵相乘得到的矩阵
o.pos = mul(m , v.vertex);
}
1273

被折叠的 条评论
为什么被折叠?



