顶点变换(顶点Y坐标抬升)

Shader "Custom/test1" {

    properties
    {
        _R("R",range(0,5))=1
    }
    SubShader {
        pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag 

            #include "unitycg.cginc"

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


            v2f vert(appdata_base v)
            {
                v2f o;
                //应用程序输入顶点坐标转换为世界坐标
                float4 wpos = mul(_Object2World,v.vertex);
                //取x,z坐标
                float2 xz = wpos.xz;

                //计算x,z到坐标中心距离
                float d = _R-length(xz);
                d = d<0?0:d;

                float height = 1;

                //顶点变换之后的顶点数据

                float4 uppVertex = float4(v.vertex.x,height*d,v.vertex.z,v.vertex.w);

                o.pos = mul(UNITY_MATRIX_MVP,uppVertex);

                //为变化的顶点数据进行着色
                o.col = float4(uppVertex.y,uppVertex.y,uppVertex.y,1);
                return o;
            }

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

}

你可能感兴趣的:(unity3d)