Skip to content

Commit a6cbc19

Browse files
committed
Initial commit of shader that draws a ring around a location in space
1 parent 0705899 commit a6cbc19

File tree

6 files changed

+688
-0
lines changed

6 files changed

+688
-0
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!21 &2100000
4+
Material:
5+
serializedVersion: 6
6+
m_ObjectHideFlags: 0
7+
m_PrefabParentObject: {fileID: 0}
8+
m_PrefabInternal: {fileID: 0}
9+
m_Name: SpatialMappingTap
10+
m_Shader: {fileID: 4800000, guid: 23beda61782381042848d512379b9e11, type: 3}
11+
m_ShaderKeywords: _EMISSION _USEWIREFRAME_ON
12+
m_LightmapFlags: 1
13+
m_CustomRenderQueue: -1
14+
stringTagMap: {}
15+
m_SavedProperties:
16+
serializedVersion: 2
17+
m_TexEnvs:
18+
- first:
19+
name: _BumpMap
20+
second:
21+
m_Texture: {fileID: 0}
22+
m_Scale: {x: 1, y: 1}
23+
m_Offset: {x: 0, y: 0}
24+
- first:
25+
name: _DetailAlbedoMap
26+
second:
27+
m_Texture: {fileID: 0}
28+
m_Scale: {x: 1, y: 1}
29+
m_Offset: {x: 0, y: 0}
30+
- first:
31+
name: _DetailMask
32+
second:
33+
m_Texture: {fileID: 0}
34+
m_Scale: {x: 1, y: 1}
35+
m_Offset: {x: 0, y: 0}
36+
- first:
37+
name: _DetailNormalMap
38+
second:
39+
m_Texture: {fileID: 0}
40+
m_Scale: {x: 1, y: 1}
41+
m_Offset: {x: 0, y: 0}
42+
- first:
43+
name: _EmissionMap
44+
second:
45+
m_Texture: {fileID: 0}
46+
m_Scale: {x: 1, y: 1}
47+
m_Offset: {x: 0, y: 0}
48+
- first:
49+
name: _MainTex
50+
second:
51+
m_Texture: {fileID: 0}
52+
m_Scale: {x: 1, y: 1}
53+
m_Offset: {x: 0, y: 0}
54+
- first:
55+
name: _MetallicGlossMap
56+
second:
57+
m_Texture: {fileID: 0}
58+
m_Scale: {x: 1, y: 1}
59+
m_Offset: {x: 0, y: 0}
60+
- first:
61+
name: _OcclusionMap
62+
second:
63+
m_Texture: {fileID: 0}
64+
m_Scale: {x: 1, y: 1}
65+
m_Offset: {x: 0, y: 0}
66+
- first:
67+
name: _ParallaxMap
68+
second:
69+
m_Texture: {fileID: 0}
70+
m_Scale: {x: 1, y: 1}
71+
m_Offset: {x: 0, y: 0}
72+
m_Floats:
73+
- first:
74+
name: _BumpScale
75+
second: 1
76+
- first:
77+
name: _Cutoff
78+
second: 0.5
79+
- first:
80+
name: _DetailNormalMapScale
81+
second: 1
82+
- first:
83+
name: _DstBlend
84+
second: 0
85+
- first:
86+
name: _GlossMapScale
87+
second: 1
88+
- first:
89+
name: _Glossiness
90+
second: 0.5
91+
- first:
92+
name: _GlossyReflections
93+
second: 1
94+
- first:
95+
name: _Metallic
96+
second: 0
97+
- first:
98+
name: _Mode
99+
second: 0
100+
- first:
101+
name: _OcclusionStrength
102+
second: 1
103+
- first:
104+
name: _Parallax
105+
second: 0.02
106+
- first:
107+
name: _PulseWidth
108+
second: 0.99
109+
- first:
110+
name: _Radius
111+
second: 4.55
112+
- first:
113+
name: _SmoothnessTextureChannel
114+
second: 0
115+
- first:
116+
name: _SpecularHighlights
117+
second: 1
118+
- first:
119+
name: _SrcBlend
120+
second: 1
121+
- first:
122+
name: _UVSec
123+
second: 0
124+
- first:
125+
name: _UseWireframe
126+
second: 1
127+
- first:
128+
name: _WireframeFill
129+
second: 0.13
130+
- first:
131+
name: _WireframeThick
132+
second: 0
133+
- first:
134+
name: _ZWrite
135+
second: 1
136+
m_Colors:
137+
- first:
138+
name: _Center
139+
second: {r: 0, g: 0, b: 0, a: -1}
140+
- first:
141+
name: _Color
142+
second: {r: 1, g: 1, b: 1, a: 1}
143+
- first:
144+
name: _EmissionColor
145+
second: {r: 0, g: 0, b: 0, a: 1}
146+
- first:
147+
name: _PulseColor
148+
second: {r: 0.6544118, g: 0.7887331, b: 1, a: 1}
149+
- first:
150+
name: _WireframeColor
151+
second: {r: 0.5514706, g: 0.20274653, b: 0.20274653, a: 1}

Assets/HoloToolkit/SpatialMapping/Materials/SpatialMappingTap.mat.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
Shader "Spatial Mapping/Spatial Mappping Tap"
2+
{
3+
Properties
4+
{
5+
// Main knobs
6+
_Center ("Center", Vector) = (0, 0, 0, -1) // world space position
7+
_Radius ("Radius", Range(0, 10)) = 1 // grows the pulse
8+
9+
// Pulse knobs
10+
_PulseColor ("Pulse Color", Color) = (.145, .447, .922)
11+
_PulseWidth ("Pulse Width", Float) = 1
12+
13+
// Wireframe knobs
14+
[MaterialToggle] _UseWireframe ("Use Wireframe", Int) = 1
15+
_WireframeColor ("Wireframe Color", Color) = (.5, .5, .5)
16+
_WireframeFill ("Wireframe Fill", Range(0, 1)) = .1
17+
}
18+
19+
SubShader
20+
{
21+
Tags { "RenderType" = "Opaque" }
22+
23+
Pass
24+
{
25+
Offset 50, 100
26+
27+
CGPROGRAM
28+
29+
#pragma vertex vert
30+
#pragma geometry geom
31+
#pragma fragment frag
32+
33+
#include "UnityCG.cginc"
34+
35+
half _Radius;
36+
half3 _Center;
37+
half3 _PulseColor;
38+
half _PulseWidth;
39+
half3 _WireframeColor;
40+
half _WireframeFill;
41+
int _UseWireframe;
42+
43+
// http://www.iquilezles.org/www/articles/functions/functions.htm
44+
half cubicPulse(half c, half w, half x)
45+
{
46+
x = abs(x - c);
47+
if ( x > w )
48+
return 0;
49+
x /= w;
50+
return 1 - x * x * (3 - 2 * x);
51+
}
52+
53+
struct v2g
54+
{
55+
half4 viewPos : SV_POSITION;
56+
half pulse : COLOR;
57+
};
58+
59+
v2g vert(appdata_base v)
60+
{
61+
v2g o;
62+
63+
o.viewPos = mul(UNITY_MATRIX_MVP, v.vertex);
64+
65+
float4 worldPos = mul(unity_ObjectToWorld, v.vertex);
66+
half distToCenter = distance(_Center, worldPos.xyz);
67+
half pulse = cubicPulse(_Radius, _PulseWidth, distToCenter);
68+
69+
o.pulse = pulse;
70+
71+
return o;
72+
}
73+
74+
struct g2f
75+
{
76+
float4 viewPos : SV_POSITION;
77+
half3 bary : COLOR;
78+
half pulse : COLOR1;
79+
};
80+
81+
[maxvertexcount(3)]
82+
void geom(triangle v2g i[3], inout TriangleStream<g2f> triStream)
83+
{
84+
// For wireframe
85+
half3 barys[3] = {
86+
half3(1, 0, 0),
87+
half3(0, 1, 0),
88+
half3(0, 0, 1)
89+
};
90+
91+
g2f o;
92+
93+
[unroll]
94+
for (uint idx = 0; idx < 3; ++idx)
95+
{
96+
o.viewPos = i[idx].viewPos;
97+
o.bary = barys[idx];
98+
o.pulse = i[idx].pulse;
99+
triStream.Append(o);
100+
}
101+
}
102+
103+
half4 frag(g2f i) : COLOR
104+
{
105+
half3 result = i.pulse * _PulseColor;
106+
107+
if (!_UseWireframe)
108+
return half4(result, 1);
109+
110+
half triBary = min( min(i.bary.x, i.bary.y), i.bary.z) * 3;
111+
half fwt = fwidth(triBary);
112+
half w = smoothstep(fwt, 0, triBary - _WireframeFill);
113+
114+
result += w * _WireframeColor * i.pulse;
115+
116+
return half4(result, 1);
117+
}
118+
119+
ENDCG
120+
}
121+
}
122+
123+
FallBack "Diffuse"
124+
}
125+

Assets/HoloToolkit/SpatialMapping/Shaders/SpatialMappingTap.shader.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)