forked from UnityCommunity/UnityLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCirclesPattern.shader
More file actions
68 lines (58 loc) · 1.69 KB
/
Copy pathCirclesPattern.shader
File metadata and controls
68 lines (58 loc) · 1.69 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// draws circle pattern
Shader "UnityLibrary/2D/Patterns/Circles"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_CircleSize("Size", Range(0,1)) = 0.5
_Circles("Amount", Range(1,64)) = 8
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows vertex:vert
#pragma target 3.0
struct Input
{
float2 texcoord : TEXCOORD0;
};
sampler2D _MainTex;
float _Circles;
float _CircleSize;
half _Glossiness;
half _Metallic;
fixed4 _Color;
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_INSTANCING_BUFFER_END(Props)
// https://thebookofshaders.com/09/
float2 tile(float2 _st, float _zoom)
{
_st *= _zoom;
return frac(_st);
}
// https://thebookofshaders.com/07/
float Circle(float2 _st, float _radius)
{
float2 dist = _st - float2(0.5, 0.5);
return 1. - smoothstep(_radius - (_radius * 0.01), _radius + (_radius * 0.01), dot(dist, dist) * 4.0);
}
void vert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o);
o.texcoord = v.texcoord;
}
void surf (Input IN, inout SurfaceOutputStandard o)
{
float2 st = IN.texcoord.xy;
float c = Circle(tile(st, round(_Circles)), _CircleSize);
o.Albedo = c.rrr* _Color;
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.r;
}
ENDCG
}
FallBack "Diffuse"
}