Skip to content

Commit 28950ad

Browse files
NeerajWkeveleigh
authored andcommitted
HoloToolkit Input model: Adding simple test scene for gaze and air tap (#455)
* HoloToolkit Input model: Adding simple test scene for gaze and air tap These simple scripts and scenes should help developers easily migrate existing code to the new model. * Adding the event system to the test scene Managers object. Adding the event system to the test scene Managers object. * Added missing copyright headers for test files Added missing copyright headers for test files
1 parent 4e20a8e commit 28950ad

File tree

11 files changed

+907
-0
lines changed

11 files changed

+907
-0
lines changed

Assets/HoloToolkit/Input/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,14 @@ In this particular implementation, selected object color it toggled on selecting
245245
A grid of dynamic objects to illustrate sending messages to prefab instances created at runtime as opposed
246246
to only static objects that already exist in the scene.
247247

248+
#### GazeResponder.cs
249+
This class implements IFocusable to respond to gaze changes.
250+
It highlights the object being gazed at.
251+
252+
#### TapResponder.cs
253+
This class implements IInputClickHandler to handle the tap gesture.
254+
It increases the scale of the object when tapped.
255+
248256
### [Tests](Tests)
249257
Tests related to the input features. To use the scene:
250258

@@ -267,6 +275,10 @@ Shows the cursor hugging the test sphere in the scene and displays hand detected
267275
Example on how to send keyword messages to currently focused dynamically instantiated object.
268276
Gazing on an object and saying "Make Smaller" and "Make Bigger" will adjust object size.
269277

278+
#### InputTapTest.unity
279+
Test scene shows you in a simple way, how to respond to user's gaze using the Input module.
280+
It also shows you how to respond to the user's tap gesture.
281+
270282
#### KeywordManager.unity
271283
Shows how to use the KeywordManager.cs script to add keywords to your scene.
272284

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
//
2+
// Copyright (C) Microsoft. All rights reserved.
3+
//
4+
5+
Shader "HoloToolkit/SpecularHighlight"
6+
{
7+
Properties
8+
{
9+
_Color("Main Color", Color) = (1,1,1,1)
10+
_HighlightColor("Highlight Color", Color) = (1,1,1,1)
11+
_MainTex1("Albedo", 2D) = "white" { }
12+
_Specular("Specular", Color) = (0.08,0.075,0.065,1)
13+
_Shininess("Shininess", float) = 3.0
14+
_Highlight("Highlight", float) = 0.0
15+
}
16+
17+
CGINCLUDE
18+
#include "UnityCG.cginc"
19+
#include "AutoLight.cginc"
20+
#include "Lighting.cginc"
21+
ENDCG
22+
23+
SubShader
24+
{
25+
Tags { "RenderType" = "Opaque" }
26+
LOD 200
27+
Pass
28+
{
29+
Lighting On
30+
Tags {"LightMode" = "ForwardBase"}
31+
32+
CGPROGRAM
33+
34+
#pragma exclude_renderers gles
35+
#pragma vertex vert
36+
#pragma fragment frag
37+
#pragma multi_compile_fwdbase
38+
#pragma target 5.0
39+
#pragma only_renderers d3d11
40+
41+
// Low precision floating point types
42+
#define lowp min16float
43+
#define lowp2 min16float2
44+
#define lowp3 min16float3
45+
#define lowp4 min16float4
46+
#define WORLD_NORMAL(vertexNormal) lowp4((normalize((lowp3)mul(vertexNormal, (float3x3)unity_WorldToObject))), 1.0f)
47+
48+
#define SPECULAR_ON 1
49+
#define REFLECTION_ON 0
50+
51+
float3 _Color;
52+
float3 _HighlightColor;
53+
sampler2D _MainTex1;
54+
float4 _Specular;
55+
float _Shininess;
56+
float _Highlight;
57+
58+
sampler2D _SimpleShadow;
59+
uniform float4x4 _World2SimpleShadow;
60+
61+
float _CubeContribution;
62+
float _FresnelPower;
63+
samplerCUBE _Cube;
64+
65+
struct appdata_t
66+
{
67+
float4 vertex : POSITION;
68+
float3 normal : NORMAL;
69+
float4 texcoord : TEXCOORD0;
70+
lowp4 color : COLOR;
71+
};
72+
73+
struct v2f
74+
{
75+
float4 pos : POSITION;
76+
lowp2 uv : TEXCOORD0;
77+
lowp3 color : COLOR;
78+
lowp3 diffuse : TEXCOORD2;
79+
80+
#if SPECULAR_ON
81+
lowp3 specular : TEXCOORD4;
82+
#endif
83+
84+
#if REFLECTION_ON
85+
lowp3 worldViewDir : TEXCOORD5;
86+
lowp3 worldNormal : TEXCOORD6;
87+
lowp3 reflection : TEXCOORD7;
88+
#endif
89+
90+
};
91+
92+
v2f vert(appdata_t v)
93+
{
94+
v2f o;
95+
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
96+
o.uv = v.texcoord;
97+
98+
//Setup vectors for light probe contribution, w = 1.
99+
lowp4 worldNormal = WORLD_NORMAL(v.normal);
100+
101+
//Calculate light probe contribution
102+
lowp3 x1;
103+
// Linear + constant polynomial terms
104+
x1.r = dot(unity_SHAr, worldNormal);
105+
x1.g = dot(unity_SHAg, worldNormal);
106+
x1.b = dot(unity_SHAb, worldNormal);
107+
108+
//transfering color to pixel shader for use in diffuse output
109+
o.color = v.color * _Color;
110+
111+
lowp nDotL = saturate(dot((lowp3)_WorldSpaceLightPos0.xyz, worldNormal.xyz));
112+
lowp3 halfLightColor = _LightColor0.rgb * (lowp).5f;
113+
114+
// Store half the color of the light as diffuse and half as ambient
115+
o.diffuse = halfLightColor * nDotL;
116+
117+
#if SPECULAR_ON || REFLECTION_ON
118+
lowp3 worldViewDir = normalize(WorldSpaceViewDir(v.vertex));
119+
#endif
120+
121+
#if SPECULAR_ON
122+
// Calculate specular
123+
// TODO WorldLightDir is constant each frame. Normalize this on the CPU instead.
124+
lowp3 worldLightDir = normalize(_WorldSpaceLightPos0.xyz);
125+
lowp3 halfVector = normalize(worldLightDir + worldViewDir);
126+
127+
lowp3 specNormal = normalize(worldNormal);
128+
lowp specDot = saturate(dot(specNormal, halfVector));
129+
130+
// Pre-adding specular into ambient so we don't
131+
// have to do it in the fragment shader
132+
o.specular = _Specular * saturate(pow(specDot, _Shininess)) * 5;
133+
#endif
134+
135+
#if REFLECTION_ON
136+
o.worldNormal = worldNormal;
137+
o.worldViewDir = worldViewDir;
138+
o.reflection = reflect(-worldViewDir, worldNormal.xyz * 1.0);
139+
#endif
140+
return o;
141+
}
142+
143+
144+
lowp4 frag(v2f i) : COLOR
145+
{
146+
lowp attenuation = 1.0f;
147+
lowp3 albedo;
148+
{
149+
albedo = (lowp3)tex2D(_MainTex1, i.uv) * i.color;
150+
#if SPECULAR_ON
151+
albedo += i.specular;
152+
#endif
153+
154+
#if REFLECTION_ON
155+
lowp fresnel = saturate(dot(i.worldNormal, i.worldViewDir));
156+
// Try and sneak a MAD in there
157+
lowp fresnelRatio = (fresnel * fresnel) * (-(lowp)_FresnelPower) + (lowp)1.0;
158+
albedo += texCUBE(_Cube, i.reflection) * _CubeContribution * fresnelRatio;
159+
#endif
160+
}
161+
162+
lowp3 irradiance;
163+
{
164+
irradiance = i.diffuse;
165+
irradiance = irradiance * attenuation + albedo;
166+
}
167+
168+
lowp3 exitantRadiance = albedo * irradiance + _HighlightColor * _Highlight;
169+
170+
lowp alpha = 1.0f;
171+
return lowp4(exitantRadiance, alpha);
172+
}
173+
ENDCG
174+
}
175+
}
176+
Fallback "VertexLit"
177+
}

Assets/HoloToolkit/Input/Shaders/SpecularHighlight.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.
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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: HoloToolkit_Focusable
10+
m_Shader: {fileID: 4800000, guid: f326278a838e87c499393f30a8e72127, type: 3}
11+
m_ShaderKeywords: _EMISSION
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: _MainTex1
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: _MetallicGlossMap
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: _OcclusionMap
68+
second:
69+
m_Texture: {fileID: 0}
70+
m_Scale: {x: 1, y: 1}
71+
m_Offset: {x: 0, y: 0}
72+
- first:
73+
name: _ParallaxMap
74+
second:
75+
m_Texture: {fileID: 0}
76+
m_Scale: {x: 1, y: 1}
77+
m_Offset: {x: 0, y: 0}
78+
m_Floats:
79+
- first:
80+
name: _BumpScale
81+
second: 1
82+
- first:
83+
name: _Cutoff
84+
second: 0.5
85+
- first:
86+
name: _DetailNormalMapScale
87+
second: 1
88+
- first:
89+
name: _DstBlend
90+
second: 0
91+
- first:
92+
name: _GlossMapScale
93+
second: 1
94+
- first:
95+
name: _Glossiness
96+
second: 0.5
97+
- first:
98+
name: _GlossyReflections
99+
second: 1
100+
- first:
101+
name: _Highlight
102+
second: 0
103+
- first:
104+
name: _Metallic
105+
second: 0
106+
- first:
107+
name: _Mode
108+
second: 0
109+
- first:
110+
name: _OcclusionStrength
111+
second: 1
112+
- first:
113+
name: _Parallax
114+
second: 0.02
115+
- first:
116+
name: _Shininess
117+
second: 3
118+
- first:
119+
name: _SmoothnessTextureChannel
120+
second: 0
121+
- first:
122+
name: _SpecularHighlights
123+
second: 1
124+
- first:
125+
name: _SrcBlend
126+
second: 1
127+
- first:
128+
name: _UVSec
129+
second: 0
130+
- first:
131+
name: _ZWrite
132+
second: 1
133+
m_Colors:
134+
- first:
135+
name: _Color
136+
second: {r: 0.69225776, g: 0.88096607, b: 0.9705882, a: 1}
137+
- first:
138+
name: _EmissionColor
139+
second: {r: 0, g: 0, b: 0, a: 1}
140+
- first:
141+
name: _HighlightColor
142+
second: {r: 0.6317475, g: 0.5650952, b: 0.9852941, a: 1}
143+
- first:
144+
name: _Specular
145+
second: {r: 0.08, g: 0.075, b: 0.065, a: 1}

Assets/HoloToolkit/Input/Tests/Materials/HoloToolkit_Focusable.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.

0 commit comments

Comments
 (0)