1. 程式人生 > >簡單的頂點著色(根據模型座標和世界座標位置)

簡單的頂點著色(根據模型座標和世界座標位置)

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 } } }