forked from przemyslawzaworski/Unity3D-CG-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfont.shader
50 lines (45 loc) · 1.13 KB
/
font.shader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//source:https://www.shadertoy.com/view/4sBfRd
Shader "Font"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {} //assign font.png (texture source: www.shadertoy.com)
}
Subshader
{
Pass
{
CGPROGRAM
#pragma vertex vertex_shader
#pragma fragment pixel_shader
#pragma target 2.0
sampler2D _MainTex;
struct custom_type
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
custom_type vertex_shader (float4 vertex : POSITION, float2 uv : TEXCOORD0)
{
custom_type vs;
vs.vertex = UnityObjectToClipPos (vertex);
vs.uv = uv;
return vs;
}
float4 pixel_shader (custom_type ps) : COLOR
{
uint t[12] = {72,69,76,76,79,32,87,79,82,76,68,33}; //every number is another char
float2 position = float2(0.5,1.0); //xy coordinates (x: 0.0->1.0 y: 0.0->2.0 )
float2 U = ps.uv.xy*2.0-position;
float c = 0.0;
float3 d = float3(1.0,1.0,1.0); //RGB font color
for (int i=0; i<12;i++,U.x-=.1)
{
c +=(length(U-.06)<.06)?tex2D(_MainTex,U*.5+frac(float2(t[i],15-t[i]/16)/16.)).x:0.0;
}
return float4(c*d.x,c*d.y,c*d.z,1.0);
}
ENDCG
}
}
}