顶点进行缩放旋转操作

using UnityEngine;
using System.Collections;

public class uniform : MonoBehaviour {

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void 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;

        Matrix4x4 Sm = new Matrix4x4();
        Sm[0,0] = Mathf.Sin(Time.realtimeSinceStartup);
        Sm[1,1] = Mathf.Cos(Time.realtimeSinceStartup);
        Sm[2,2] = Mathf.Sin(Time.realtimeSinceStartup);
        Sm[3,3] = 1;
        Matrix4x4 mvp = Camera.main.projectionMatrix*Camera.main.worldToCameraMatrix*transform.localToWorldMatrix*Sm;

        GetComponent().material.SetMatrix("mvp",mvp);
    }
}

Shader "Custom/test1" {

    SubShader {
        pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag 

            #include "unitycg.cginc"

            float4x4 mvp;

            struct v2f{
                float4 pos:POSITION;
            };


            v2f vert(appdata_base v)
            {
                v2f o;
                o.pos = mul(mvp,v.vertex);
                //o.pos = mul(UNITY_MATRIX_MVP,v.vertex);
                return o;
            }

            fixed4 frag():COLOR
            {
                return fixed4(1,1,1,1);
            }
            ENDCG
        }
    }

}

你可能感兴趣的:(unity3d)