comparison Orchestland/Assets/LeapMotion/Resources/ImageHandHighlight.shader @ 1:f7675884f2a1

Add Orchestland project
author Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
date Fri, 17 Jul 2015 23:09:20 +0900
parents
children
comparison
equal deleted inserted replaced
0:347d21cdfc22 1:f7675884f2a1
1 Shader "LeapMotion/Passthrough/ImageHandHighlight" {
2 Properties {
3 _Color ("Color", Color) = (0.165,0.337,0.578,1.0)
4 _Fade ("Fade", Range(0, 1)) = 0.0
5 _Extrude ("Extrude", Float) = 0.008
6 _Intersection ("Intersection Threshold", Float) = 0.035
7 _IntersectionEffectBrightness ("Intersection Brightness", Range (0, 2000)) = 100
8
9 _MinThreshold ("Min Threshold", Float) = 0.1
10 _MaxThreshold ("Max Threshold", Float) = 0.2
11 _GlowThreshold ("Glow Threshold", Float) = 0.5
12 _GlowPower ("Glow Power", Float) = 10.0
13
14 _ColorSpaceGamma ("Color Space Gamma", Float) = 1.0
15 }
16
17
18 CGINCLUDE
19 #pragma multi_compile LEAP_FORMAT_IR LEAP_FORMAT_RGB
20 #pragma multi_compile _ USE_DEPTH_TEXTURE
21 #include "LeapCG.cginc"
22 #include "UnityCG.cginc"
23
24 #pragma target 3.0
25
26 uniform float4 _Color;
27 uniform float _Fade;
28 uniform float _Extrude;
29 uniform float _Intersection;
30 uniform float _IntersectionEffectBrightness;
31 uniform float _MinThreshold;
32 uniform float _MaxThreshold;
33 uniform float _GlowThreshold;
34 uniform float _GlowPower;
35 uniform float _ColorSpaceGamma;
36
37 #ifdef USE_DEPTH_TEXTURE
38 uniform sampler2D _CameraDepthTexture;
39 #endif
40
41 struct appdata {
42 float4 vertex : POSITION;
43 float3 normal : NORMAL;
44 };
45
46 struct frag_in {
47 float4 vertex : POSITION;
48 float4 screenPos : TEXCOORD0;
49 #ifdef USE_DEPTH_TEXTURE
50 float4 projPos : TEXCOORD1;
51 #endif
52 };
53
54 frag_in vert(appdata v) {
55 frag_in o;
56 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
57
58 float3 norm = mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal);
59 o.vertex.xy += TransformViewToProjection(norm.xy) * _Extrude;
60
61 o.screenPos = ComputeScreenPos(o.vertex);
62
63 #ifdef USE_DEPTH_TEXTURE
64 o.projPos = o.screenPos;
65 COMPUTE_EYEDEPTH(o.projPos.z);
66 #endif
67
68 return o;
69 }
70
71 float4 trackingGlow(float4 screenPos) {
72 // Map leap image to linear color space
73 float4 leapRawColor = LeapRawColorBrightness(screenPos);
74 clip(leapRawColor.a - _MinThreshold);
75 float3 leapLinearColor = pow(pow(leapRawColor.rgb, _LeapGammaCorrectionExponent), 1/_ColorSpaceGamma);
76 // Apply edge glow and interior shading
77 float brightness = smoothstep(_MinThreshold, _MaxThreshold, leapRawColor.a) * _Fade;
78 float glow = smoothstep(_GlowThreshold, _MinThreshold, leapRawColor.a) * brightness;
79 float4 linearColor = pow(_Color, _ColorSpaceGamma) * glow * _GlowPower;
80 return float4(leapLinearColor + linearColor, brightness);
81 }
82
83 #ifdef USE_DEPTH_TEXTURE
84 float4 intersectionGlow(float4 handGlow, float4 projPos) {
85 // Apply intersection highlight
86 float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(projPos)));
87 float partZ = projPos.z;
88 float diff = smoothstep(_Intersection, 0, sceneZ - partZ);
89 float4 linearColor = pow(_Color, _ColorSpaceGamma) * _IntersectionEffectBrightness;
90 return float4(lerp(handGlow.rgb, linearColor.rgb, diff), handGlow.a * (1 - diff));
91 }
92 #endif
93
94 float4 frag(frag_in i) : COLOR {
95 float4 handGlow = trackingGlow(i.screenPos);
96
97 #ifdef USE_DEPTH_TEXTURE
98 handGlow = intersectionGlow(handGlow, i.projPos);
99 #endif
100
101 return float4(handGlow.rgb, _Fade * handGlow.a);
102 }
103
104 float4 alphaFrag(frag_in i) : COLOR {
105 float4 leapRawColor = LeapRawColorBrightness(i.screenPos);
106 clip(leapRawColor.a - _MinThreshold);
107 return float4(0,0,0,0);
108 }
109
110 ENDCG
111
112 SubShader {
113 Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="Transparent"}
114
115 Blend SrcAlpha OneMinusSrcAlpha
116
117 Pass{
118 ZWrite On
119 ColorMask 0
120
121 CGPROGRAM
122 #pragma vertex vert
123 #pragma fragment alphaFrag
124 ENDCG
125 }
126
127 Pass{
128 ZWrite Off
129
130 CGPROGRAM
131 #pragma vertex vert
132 #pragma fragment frag
133 ENDCG
134 }
135
136 }
137 Fallback "Unlit/Texture"
138 }