关于shader的学习

教程地址:https://onevcat.com/2013/07/shader-tutorial-1

因为想做一些特效,所以想稍微了解一下shader的代码,一下是一些笔记

 1 // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
 2 
 3 Shader "Custom/Edge"  
 4 {  
 5     Properties  
 6     {  
 7     //name ("客户端显示名字",可调节的值)=默认值
 8         _Edge ("Edge", Range(0, 0.2)) = 0.043  
 9         _EdgeColor ("EdgeColor", Color) = (1, 1, 1, 1)  
10         _MainTex ("MainTex", 2D) = "white" {}  
11     }  
12     SubShader  
13     {  
14         Pass  
15         {  
16         //开始标记,表明这里开始是一段CG程序,与之匹配是下面的ENDCG
17             CGPROGRAM 
18             //编译指令 声明我们要写个啥样的着色器 着色器的名字
19             #pragma vertex vert  
20             #pragma fragment frag  
21             #include "UnityCG.cginc"  
22   
23   //链接上面的_声明 ,因为这是一段CG程序,和上面是两个独立的块
24             fixed _Edge;  
25             fixed4 _EdgeColor; 
26             sampler2D _MainTex;  
27   
28             struct appdata  
29             {  
30                 float4 vertex : POSITION;  
31                 fixed2 uv : TEXCOORD0;  
32             };  
33   
34             struct v2f  
35             {  
36                 float4 vertex : SV_POSITION;  
37                 float4 objVertex : TEXCOORD0;  
38                 fixed2 uv : TEXCOORD1;  
39             };  
40   
41             v2f vert (appdata v)  
42             {  
43                 v2f o;  
44                 o.vertex = UnityObjectToClipPos(v.vertex);  
45                 o.objVertex = v.vertex;  
46                 o.uv = v.uv;  
47   
48                 return o;  
49             }  
50               
51             fixed4 frag (v2f i) : SV_Target  
52             {     
53                 fixed x = i.uv.x;  
54                 fixed y = i.uv.y;  
55                       
56                 if((x < _Edge) || (abs(1 - x) < _Edge) || (y < _Edge) || (abs(1 - y) < _Edge))   
57                 {  
58                     return _EdgeColor * abs(cos(_Time.y));  
59                 }  
60                 else   
61                 {  
62                     fixed4 color = tex2D(_MainTex, i.uv);  
63                     return color;  
64                 }  
65   
66                 //return i.objVertex;  
67                 //return fixed4(i.uv, 0, 1);  
68             }  
69             ENDCG  
70         }  
71     }  
72 }  
原文地址:https://www.cnblogs.com/ninomiya/p/8981693.html