forked from microsoft/MixedRealityToolkit-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpatialMappingTap.shader
More file actions
125 lines (98 loc) · 2.39 KB
/
SpatialMappingTap.shader
File metadata and controls
125 lines (98 loc) · 2.39 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
Shader "Spatial Mapping/Spatial Mappping Tap"
{
Properties
{
// Main knobs
_Center ("Center", Vector) = (0, 0, 0, -1) // world space position
_Radius ("Radius", Range(0, 10)) = 1 // grows the pulse
// Pulse knobs
_PulseColor ("Pulse Color", Color) = (.145, .447, .922)
_PulseWidth ("Pulse Width", Float) = 1
// Wireframe knobs
[MaterialToggle] _UseWireframe ("Use Wireframe", Int) = 1
_WireframeColor ("Wireframe Color", Color) = (.5, .5, .5)
_WireframeFill ("Wireframe Fill", Range(0, 1)) = .1
}
SubShader
{
Tags { "RenderType" = "Opaque" }
Pass
{
Offset 50, 100
CGPROGRAM
#pragma vertex vert
#pragma geometry geom
#pragma fragment frag
#include "UnityCG.cginc"
half _Radius;
half3 _Center;
half3 _PulseColor;
half _PulseWidth;
half3 _WireframeColor;
half _WireframeFill;
int _UseWireframe;
// http://www.iquilezles.org/www/articles/functions/functions.htm
half cubicPulse(half c, half w, half x)
{
x = abs(x - c);
if ( x > w )
return 0;
x /= w;
return 1 - x * x * (3 - 2 * x);
}
struct v2g
{
half4 viewPos : SV_POSITION;
half pulse : COLOR;
};
v2g vert(appdata_base v)
{
v2g o;
o.viewPos = mul(UNITY_MATRIX_MVP, v.vertex);
float4 worldPos = mul(unity_ObjectToWorld, v.vertex);
half distToCenter = distance(_Center, worldPos.xyz);
half pulse = cubicPulse(_Radius, _PulseWidth, distToCenter);
o.pulse = pulse;
return o;
}
struct g2f
{
float4 viewPos : SV_POSITION;
half3 bary : COLOR;
half pulse : COLOR1;
};
[maxvertexcount(3)]
void geom(triangle v2g i[3], inout TriangleStream<g2f> triStream)
{
// For wireframe
half3 barys[3] = {
half3(1, 0, 0),
half3(0, 1, 0),
half3(0, 0, 1)
};
g2f o;
[unroll]
for (uint idx = 0; idx < 3; ++idx)
{
o.viewPos = i[idx].viewPos;
o.bary = barys[idx];
o.pulse = i[idx].pulse;
triStream.Append(o);
}
}
half4 frag(g2f i) : COLOR
{
half3 result = i.pulse * _PulseColor;
if (!_UseWireframe)
return half4(result, 1);
half triBary = min( min(i.bary.x, i.bary.y), i.bary.z) * 3;
half fwt = fwidth(triBary);
half w = smoothstep(fwt, 0, triBary - _WireframeFill);
result += w * _WireframeColor * i.pulse;
return half4(result, 1);
}
ENDCG
}
}
FallBack "Diffuse"
}