首先,准备一个大小为1的面片(GameObject >> 3D Object >> Quad),
再准备一个空的fragment shader,创建一个材质使用这个shader,并将面片的材质选为该材质。
开工。
2楼中提到了格子的概念,我们先来划分用于装数字的格子吧
属性中定义
_CellSize ("Cell Size (xyz)", Vector) = (0.03, 0.04, 0.03, 0)
代表以x = 0.03, y = 0.04一格
另外定义三张图
_RandomTex ("Random Tex", 2D) = "white" {}
_FlowingTex ("Flowing Tex", 2D) = "white" {}
_NumberTex ("Number Tex", 2D) = "white" {}
分别代表2楼的三张图
再定义属性:
_TexelSizes ("Random Texel Size, Flowing Texel Size, Number Count", Vector) = (0.015625, 0.00390625, 10, 0)
记录两张噪声图的大小以及数字的个数。
#define _RandomTexelSize (_TexelSizes.x)
#define _FlowingTexelSize (_TexelSizes.y)
#define _NumberCount (_TexelSizes.z)
然后我们就可以把格子划分出来了
fixed4 frag (v2f i) : COLOR
{
float3 cellc = i.texc.xyz / _CellSize;
fixed4 c = tex2D(_RandomTex, cellc.xy * _RandomTexelSize).rgba;
return c;
}