自定义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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值