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
138 lines (109 loc) · 2.86 KB
/
Copy pathSpatialMappingTap.shader
File metadata and controls
138 lines (109 loc) · 2.86 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
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
Shader "Spatial Mapping/Spatial Mapping 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;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
v2g vert(appdata_base v)
{
v2g o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_TRANSFER_INSTANCE_ID(v, o);
o.viewPos = UnityObjectToClipPos(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;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
[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)
{
UNITY_SETUP_INSTANCE_ID(i[idx]);
UNITY_TRANSFER_INSTANCE_ID(i[idx], o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.viewPos = i[idx].viewPos;
o.bary = barys[idx];
o.pulse = i[idx].pulse;
triStream.Append(o);
}
}
half4 frag(g2f i) : COLOR
{
UNITY_SETUP_INSTANCE_ID(i);
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"
}