-
Notifications
You must be signed in to change notification settings - Fork 13
/
HandVisuallizer.shader
83 lines (66 loc) · 2.06 KB
/
HandVisuallizer.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
78
79
80
81
82
83
Shader "Hidden/HolisticBarracuda/HandVisuallizer"
{
CGINCLUDE
#include "UnityCG.cginc"
#define VERTEX_COUNT 21
float2 _uiScale;
float4 _pointColor;
float _handScoreThreshold;
StructuredBuffer<float4> _vertices;
void VertexKeys(uint vid : SV_VertexID,
uint iid : SV_InstanceID,
out float4 position : SV_Position,
out float4 color : COLOR)
{
float3 p = _vertices[iid].xyz;
uint fan = vid / 3;
uint segment = vid % 3;
float theta = (fan + segment - 1) * UNITY_PI / 16;
float radius = (segment > 0) * 0.008;
p.xy += float2(cos(theta), sin(theta)) * radius;
p.xy = (2 * p.xy - 1) * _uiScale / _ScreenParams.xy;
float score = _vertices[VERTEX_COUNT].x;
position = float4(p.xy, 0, 1);
color = (score >= _handScoreThreshold) ? _pointColor : float4(0, 0, 1, 1);
}
void VertexBones(uint vid : SV_VertexID,
uint iid : SV_InstanceID,
out float4 position : SV_Position,
out float4 color : COLOR)
{
uint finger = iid / 4;
uint segment = iid % 4;
uint i = min(4, finger) * 4 + segment + vid;
uint root = finger > 1 && finger < 5 ? i - 3 : 0;
i = max(segment, vid) == 0 ? root : i;
float3 p = _vertices[i].xyz;
p.xy = (2 * p.xy - 1) * _uiScale / _ScreenParams.xy;
position = float4(p.xy, 0, 1);
color = float4(1, 1, 1, 1);
}
float4 Fragment(float4 position : SV_Position,
float4 color : COLOR) : SV_Target
{
return color;
}
ENDCG
SubShader
{
ZWrite Off ZTest Always Cull Off
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex VertexKeys
#pragma fragment Fragment
ENDCG
}
Pass
{
CGPROGRAM
#pragma vertex VertexBones
#pragma fragment Fragment
ENDCG
}
}
}