自定义cginc文件

首先定义一个cginc文件如下所示:

#ifndef MY_CG_INCLUDE  
#define MY_CG_INCLUDE  
struct appdata_x {
    float4 vertex : POSITION;
    float4 texcoord : TEXCOORD0;
};

struct v2f_x{
    float4 pos : SV_POSITION;
    float2 uv  : TEXCOORD0;
};
#endif  

然后引用如下:

 1 Shader "Custom/MyShader"{
 2 Properties{
 3     _MainTex ("Main Tex", 2D) = "white" {}
 4 }
 5 SubShader
 6 {
 7     Tags {"Queue"="Transparent""RenderType"="Transparent"}
 8     Pass
 9     {
10     Tags { "LightMode"="ForwardBase" }
11     CGPROGRAM
12     #pragma vertex vert
13     #pragma fragment frag
14     #include "Lighting.cginc"
15     #include "MyCgInclude.cginc"
16     sampler2D _MainTex;
17     float4 _MainTex_ST;
18 
19     v2f_x vert(appdata_x v)
20     {
21         v2f_img2 o;
22         o.pos=UnityObjectToClipPos(v.vertex);//将顶点坐标变换到裁剪空间中
23         o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);//变换uv坐标
24         return o;
25     }
26 
27     fixed4 frag(v2f_x i):SV_Target
28     {
29         fixed4 c = tex2D (_MainTex, i.uv);//对纹理坐标进行采样
30         return c;
31     }
32     ENDCG
33     }
34     }
35 FallBack "Diffuse"
36 }
原文地址:https://www.cnblogs.com/luxishi/p/7251149.html