Skip to content

Commit 3245181

Browse files
authored
Create CirclesPattern.shader
1 parent 7a5919d commit 3245181

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// draws circle pattern
2+
Shader "UnityLibrary/2D/Patterns/Circles"
3+
{
4+
Properties
5+
{
6+
_Color ("Color", Color) = (1,1,1,1)
7+
_CircleSize("Size", Range(0,1)) = 0.5
8+
_Circles("Amount", Range(1,64)) = 8
9+
}
10+
11+
SubShader
12+
{
13+
Tags { "RenderType"="Opaque" }
14+
LOD 200
15+
16+
CGPROGRAM
17+
#pragma surface surf Standard fullforwardshadows vertex:vert
18+
#pragma target 3.0
19+
20+
struct Input
21+
{
22+
float2 texcoord : TEXCOORD0;
23+
};
24+
25+
sampler2D _MainTex;
26+
float _Circles;
27+
float _CircleSize;
28+
29+
half _Glossiness;
30+
half _Metallic;
31+
fixed4 _Color;
32+
33+
UNITY_INSTANCING_BUFFER_START(Props)
34+
UNITY_INSTANCING_BUFFER_END(Props)
35+
36+
// https://thebookofshaders.com/09/
37+
float2 tile(float2 _st, float _zoom)
38+
{
39+
_st *= _zoom;
40+
return frac(_st);
41+
}
42+
43+
// https://thebookofshaders.com/07/
44+
float Circle(float2 _st, float _radius)
45+
{
46+
float2 dist = _st - float2(0.5, 0.5);
47+
return 1. - smoothstep(_radius - (_radius * 0.01), _radius + (_radius * 0.01), dot(dist, dist) * 4.0);
48+
}
49+
50+
void vert(inout appdata_full v, out Input o)
51+
{
52+
UNITY_INITIALIZE_OUTPUT(Input, o);
53+
o.texcoord = v.texcoord;
54+
}
55+
56+
void surf (Input IN, inout SurfaceOutputStandard o)
57+
{
58+
float2 st = IN.texcoord.xy;
59+
float c = Circle(tile(st, round(_Circles)), _CircleSize);
60+
o.Albedo = c.rrr* _Color;
61+
o.Metallic = _Metallic;
62+
o.Smoothness = _Glossiness;
63+
o.Alpha = c.r;
64+
}
65+
ENDCG
66+
}
67+
FallBack "Diffuse"
68+
}

0 commit comments

Comments
 (0)