 ﻿Shader "LeapMotion/Passthrough/HandHighlight" {
 	Properties {
 		_Color           ("Color", Color)                  = (0.165,0.337,0.578,1.0)
-		_Fade            ("Fade", Range(0, 1))             = 0
+		_Fade            ("Fade", Range(0, 1))             = 0.0
 		_Extrude         ("Extrude", Float)                = 0.008
 		_Intersection    ("Intersection Threshold", Float) = 0.035
 
 		_MinThreshold    ("Min Threshold", Float)     = 0.1
 		_MaxThreshold    ("Max Threshold", Float)     = 0.2
 		_GlowThreshold   ("Glow Threshold", Float)    = 0.5
-		_GlowPower       ("Glow Power", Float)        = 10
+		_GlowPower       ("Glow Power", Float)        = 10.0
+    
+    _ColorSpaceGamma ("Color Space Gamma", Float) = 1.0
 	}
 
 

	uniform float     _MaxThreshold;
	uniform float     _GlowThreshold;
	uniform float     _GlowPower;

	struct appdata {
		float4 vertex : POSITION;
		float3 normal : NORMAL;
	};

	struct frag_in{
		float4 vertex : POSITION;
		float4 screenPos  : TEXCOORD0;
		float4 projPos  : TEXCOORD1;

		return o;
	}

	float4 getHandColor(float4 screenPos) {
    // Map leap image to linear color space
		float4 rawColor = LeapRawColorBrightness(screenPos);
		float3 linearColor = pow(rawColor.rgb, _LeapGammaCorrectionExponent);
    // Apply edge glow and interior shading
		float brightness = smoothstep(_MinThreshold, _MaxThreshold, rawColor.a);
		float glow = smoothstep(_GlowThreshold, _MinThreshold, rawColor.a) * brightness;
		return float4(linearColor + _Color * glow * _GlowPower, brightness);
	}

	float4 frag(frag_in i) : COLOR {
		float4 handColor = getHandColor(i.screenPos);
    // Apply intersection highlight
		float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
		float partZ = i.projPos.z;
		float diff = smoothstep(_Intersection, 0, sceneZ - partZ);
    
    float4 handLinear = float4(lerp(handColor.rgb, _Color.rgb * 20, diff), _Fade * handColor.a * (1 - diff));
		return pow(handLinear, _ColorSpaceGamma);
	}

	float4 alphaFrag(frag_in i) : COLOR {
