最简单的不受光(unlit)shader

# 功能就是原样显示一张贴图

Shader "My/Unlit"
{
    Properties
    {
        _MainTex("Texture", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType" = "Opaque" }
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION; //模型空间顶点(点坐标一般用float)
                float2 texcoord : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;

            v2f vert(appdata v) //顶点着色器(逐顶点)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex); //三角顶点的local坐标转为裁剪空间坐标
                o.uv = TRANSFORM_TEX(v.texcoord, _MainTex); //应用贴图的tiling和offset
                return o;
            }

            fixed4 frag(v2f i) : SV_Target //片元着色器(逐像素)
            {
                fixed4 c = tex2D(_MainTex, i.uv); //颜色一般用fixed
                return c;
            }
            ENDCG
        }
    }
}

 

posted @ 2022-08-14 22:27  yanghui01  阅读(164)  评论(0)    收藏  举报