简单的顶点着色(根据模型坐标和世界坐标位置)

Shader "Custom/test1" {

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

            #include "unitycg.cginc"

            float4x4 mvp;

            struct v2f{
                float4 pos:POSITION;
                fixed4 col:COLOR;
            };


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

                //对于模型坐标的判断
                //if(v.vertex.x>0)
                //  o.col = fixed4(1,0,0,1);
                //else
                //  o.col = fixed4(0,0,1,1);

                //if(v.vertex.x==0.5&&v.vertex.y==0.5&&v.vertex.z==0.5)
                //  o.col = fixed4(1,0,0,1);
                //else
                //  o.col = fixed4(0,0,1,1);

                //模型坐标转向世界坐标的控制
                float4 wpos = mul(_Object2World,v.vertex);
                if(v.vertex.x>0)
                    o.col = fixed4(1,0,0,1);
                else
                    o.col = fixed4(0,0,1,1);
                return o;
            }

            fixed4 frag(v2f IN):COLOR
            {
                return IN.col;
            }
            ENDCG
        }
    }

}

你可能感兴趣的:(unity3d)