简单的贴图显示shander

Shader "ztq/Diffuse" {
   Properties {
          _Color ("Main Color"Color) = (1,1,1,1//主材质颜色
        _MainTex ("Base (RGB) "2D) = "white" {} //主材质
   }
   SubShader {
        Pass
        {
            Tags
            {
                "LightMode"="ForwardBase"
            }

            CGPROGRAM        
            #include "UnityCG.cginc" //引用库
            #pragma vertex vert      //指定Vertex Shader函数
            #pragma fragment frag    //指定Fragment Shader函数

            uniform sampler2D _MainTex;
            uniform fixed4 _Color;

            struct v2f //申明顶点片段到像素片段函数
            {
                half4 pos : SV_POSITION; //存放顶点坐标信息
                half2 uv : TEXCOORD0//存放主材质的UV信息
            };

            v2f vert(appdata_full v) //顶点片段
            {
                v2f o; //创建O
                o.pos = mul(UNITY_MATRIX_MVP, v.vertex);  //将物体坐标转换到屏幕坐标
                o.uv = v.texcoord.xy; //映射UV
                return o; //返回O
            }
                
            fixed4 frag(v2f i) : COLOR
            {
                fixed4 diffSamplerColor = tex2D( _MainTex, i.uv.xy ); //贴图采样
                return fixed4(diffSamplerColor*_Color) ; //返回颜色
            }
            ENDCG
        }
    } 
}


posted on 2016-04-19 17:20  鸟血惹人怜鱼伤无人知  阅读(444)  评论(0编辑  收藏  举报

导航