魔法光阵(模仿一位老师的)

原文地址:http://blog.csdn.net/zzxiang1985/article/details/50706641

图片资源:

稍微修改后的shader:

 1 Shader "Unlit/MagicCircle"
 2 {
 3     Properties
 4     {
 5         _MainTex ("Texture", 2D) = "white" {}//图片
 6         _FlowColor("Flow Color", Color) = (1,1,1,1)//流光颜色
 7         _Period("Period", float) = 1//流光流动周期
 8         _MaxRidius("MaxRidius", float) = 0.5//光阵外径,不用和图片对应哈,和流光周期一起影响流光速度
 9         _FlowWidth("Flow Width", Range(0,1)) = 0.1//流光光带宽度
10     }
11     SubShader
12     {
13         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}  
14         Cull Off
15         Lighting Off
16         ZWrite Off
17         Fog {Mode Off}
18         Blend One One
19         LOD 100
20 
21         Pass
22         {
23             CGPROGRAM
24             #pragma vertex vert
25             #pragma fragment frag
26             
27             #include "UnityCG.cginc"
28 
29             struct appdata
30             {
31                 float4 vertex : POSITION;
32                 float2 uv : TEXCOORD0;
33             };
34 
35             struct v2f
36             {
37                 float2 uv : TEXCOORD0;
38                 float4 vertex : SV_POSITION;
39             };
40 
41             sampler2D _MainTex;
42 
43             fixed4 _FlowColor;
44             float _Period;
45             float _FlowWidth;
46             float _MaxRidius;
47 
48             v2f vert (appdata v)
49             {
50                 v2f o;
51                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
52                 o.uv =v.uv;
53                 return o;
54             }
55             
56             fixed4 frag (v2f i) : SV_Target
57             {
58                 fixed4 col = tex2D(_MainTex, i.uv);
59                 float2 center = float2(0.5,0.5);
60                 float dis = distance(i.uv, center);
61                 float flowMax = fmod(_Time.y, _Period) / _Period * (_MaxRidius + _FlowWidth);
62                 float flowMin = flowMax - _FlowWidth;
63                 if (dis >= flowMin && dis <= flowMax)//如果该像素在在光带内
64                 {
65                     float halfW = _FlowWidth / 2;
66                     float flowMid = flowMax - halfW;
67                     float rate = 1 - (abs(dis-flowMid) / halfW);
68 
69                     col = col + col * _FlowColor * rate;//rate用来羽化流动的光环
70                 }
71                 return col;
72             }
73             ENDCG
74         }
75     }
76 }

 

posted @ 2017-05-11 12:30  BigTreee  阅读(327)  评论(0编辑  收藏  举报