码迷,mamicode.com
首页 > 其他好文 > 详细

黑客帝国数字矩阵特效做法

时间:2017-09-30 21:07:21      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:efi   rac   repr   ima   ges   矩阵   write   class   shader   

技术分享

Shader源码:

 1 Shader "_17th_Code/NumberMatrix"
 2 {
 3     Properties
 4     {
 5         _TintColor ("Tint Color", Color) = (1,1,1,1)
 6         _RandomTex ("Random Tex", 2D) = "white" {}
 7         _FlowingTex ("Flowing Tex", 2D) = "white" {}
 8         _NumberTex ("Number Tex", 2D) = "white" {}
 9         _CellSize ("格子大小,只取XY", Vector) = (0.03, 0.04, 0.03, 0)
10         _TexelSizes ("X:Random Tex宽度,Y:Flowing Tex宽度,Z:Number Tex数字个数(这些数值根据图片更改)", Vector) = (0.015625, 0.00390625, 10, 0)
11         _Speed ("X:图片下落速度,Y:数字变化速度", Vector) = (1,5,0,0)
12         _Intensity ("Global Intensity", Float) = 1
13     }
14 
15     Subshader
16     {
17         Tags
18         {
19             "RenderType"="Transparent"
20             "Queue"="Transparent"
21             "IgnoreProjector"="True"
22         }
23         Pass
24         {
25             Fog { Mode Off }
26             Lighting Off
27             Blend One One
28             Cull Off
29             ZWrite Off
30 
31             CGPROGRAM
32             #pragma vertex vert
33             #pragma fragment frag
34             #pragma target 3.0
35             
36             float4 _TintColor;
37             sampler2D _RandomTex;
38             sampler2D _FlowingTex;
39             sampler2D _NumberTex;
40             float4 _CellSize;
41             float4 _TexelSizes;
42             float4 _Speed;
43             float _Intensity;
44             
45             #define _RandomTexelSize (_TexelSizes.x)
46             #define _FlowingTexelSize (_TexelSizes.y)
47             #define _NumberCount (_TexelSizes.z)
48             #define T (_Time.y)
49             #define EPSILON (0.00876)
50 
51             struct appdata_v
52             {
53                 float4 vertex : POSITION;
54             };
55 
56             struct v2f
57             {
58                 float4 pos : POSITION;
59                 float3 texc : TEXCOORD0;
60             };
61 
62             v2f vert (appdata_v v)
63             {
64                 v2f o;
65                 o.pos = UnityObjectToClipPos (v.vertex);
66                 o.texc = v.vertex.xyz;
67                 return o;
68             }
69             
70             fixed4 frag (v2f i) : COLOR
71             {
72                 float3 cellc = i.texc.xyz / _CellSize + EPSILON;
73                 float speed = tex2D(_RandomTex, cellc.xz * _RandomTexelSize).g * 3 + 1;
74                 cellc.y += T*speed*_Speed.x;
75                 float intens = tex2D(_FlowingTex, cellc.xy * _FlowingTexelSize).r;
76                 
77                 float2 nc = cellc;
78                 nc.x += round(T*_Speed.y*speed);
79                 float number = round(tex2D(_RandomTex, nc * _RandomTexelSize).r * _NumberCount) / _NumberCount;
80                 
81                 float2 number_tex_base = float2(number, 0);
82                 float2 number_tex = number_tex_base + float2(frac(cellc.x/_NumberCount), frac(cellc.y));
83                 fixed4 ncolor = tex2Dlod(_NumberTex, float4(number_tex, 0, 0)).rgba;
84                 
85                 return ncolor * pow(intens,3) * _Intensity * _TintColor;
86             }
87             ENDCG
88         }
89     }
90 }

 

黑客帝国数字矩阵特效做法

标签:efi   rac   repr   ima   ges   矩阵   write   class   shader   

原文地址:http://www.cnblogs.com/AaronBlogs/p/7615895.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!