forked from przemyslawzaworski/Unity3D-CG-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DrawCircles.shader
46 lines (41 loc) · 1.11 KB
/
DrawCircles.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
Shader "Draw Circles"
{
Subshader
{
Pass
{
Cull Off
CGPROGRAM
#pragma vertex VSMain
#pragma fragment PSMain
#pragma target 5.0
float BufferX[2048];
float BufferY[2048];
float mod(float x, float y)
{
return x - y * floor(x/y);
}
float3 hash(float p)
{
float3 p3 = frac(p.xxx * float3(.1239, .1237, .2367));
p3 += dot(p3, p3.yzx+63.33);
return frac((p3.xxy+p3.yzz)*p3.zyx);
}
float4 VSMain (uint id:SV_VertexID, out float2 uv:TEXCOORD0, inout uint instance:SV_INSTANCEID) : SV_POSITION
{
float3 center = float3(BufferX[instance], 0.0, BufferY[instance]);
float u = mod(float(id),2.0);
float v = sign(mod(126.0,mod(float(id),6.0)+6.0));
uv = float2(u,v);
return UnityObjectToClipPos(float4(float3(sign(u)-0.5, 0.0, sign(v)-0.5) + center,1.0));
}
float4 PSMain (float4 vertex:SV_POSITION, float2 uv:TEXCOORD0, uint instance:SV_INSTANCEID) : SV_Target
{
float2 S = uv*2.0-1.0;
if (dot(S.xy, S.xy) > 1.0) discard;
return float4(hash(float(instance)), 1.0);
}
ENDCG
}
}
}