-
Notifications
You must be signed in to change notification settings - Fork 0
/
gridshader2.shader
77 lines (67 loc) · 1.92 KB
/
gridshader2.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Shader "Custom/gridshader2"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_GridSpacing("Grid Spacing", float) = 16
}
SubShader
{
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
LOD 200
Blend SrcAlpha OneMinusSrcAlpha
//ZWrite Off
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
float3 worldPos : TEXCOORD1;
};
fixed4 _Color;
float _GridSpacing;
v2f vert(appdata_full v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
//o.worldPos = mul(unity_ObjectToWorld, v.vertex);
o.worldPos = v.vertex;
o.uv = o.worldPos.xy / _GridSpacing;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
half4 param = _Color;
float2 st = frac(i.uv);
//suqare params, https://thebookofshaders.com/07/?lan=ru
/*
float2 bl = step( float2(0.1f, 0.1f), st );
float2 tr = step( float2(.1f,.1f), float2(1.0f, 1.0f)-st);
float pct = bl.x * bl.y * tr.x * tr.y;
param.rgb = float3(pct,pct,pct);
*/
//blured, https://thebookofshaders.com/07/?lan=ru
// https://thndl.com/square-shaped-shaders.html
st = st *2.0f - 1.0f;
float d = length(max(abs(st) - .45f, 0.5f)); // calculate distance
float d1 = length(max(abs(float2(.1,.1)) - .45f, 0.5f)); // get color from centear at .1, for trimming this color
//if (d>d1) {
// param = half4(frac(d*10.0f) + param.r, frac(d*10.0f) + param.g, frac(d*10.0f) + param.b, d*param.a);
//} else {
// param = half4(1, 1, 1, 0.);
//}
param = half4(frac(d*10.0f) + param.r, frac(d*10.0f) + param.g, frac(d*10.0f) + param.b, (1.0-step(d, d1))*param.a );
return param;
}
ENDCG
}
}
}