Feb
17
2015

Leap Motion PassThrough Threshold Shader

leap_motion_threshold_shader_unity

You can add adjustable threshold to Leap Motion passthrough shader, so that your hands are more visible (less transparent) in the overlay image.

TUTORIAL
– Download unity examples package, https://developer.leapmotion.com/downloads/unity
– Import package to Unity
– Open “PassthroughWithTracking.scene”
– Select “Quad” from hierarchy
– Enable [x] Overlay image (in LeapImageRetriever script component)
– Edit shader file: “LeapIRUndistorted_foreground.shader”
Add these customisations to the shader:


// FIND LINE
_MainTex ("Base (A=Opacity)", 2D) = ""
// INSERT AFTER IT
_Threshold ("Threshold", Float) = 0.1

// FIND LINE
uniform float4 _Color;
// INSERT AFTER IT
uniform float _Threshold;

// FIND LINE
color.a *= a;
// REPLACE WITH
color = float4(a,a,a,step(_Threshold,a)) * _Color;

– Save, now test the scene and adjust threshold value from inspector if needed (try adjusting material color value also).

Notes:
– LeapImageRetriever script re-assigns the shader at start, so your inspector threshold value might resets to default..?
– Adjust material color for skincolor in the inspector

More info:
– step() : http://http.developer.nvidia.com/Cg/step.html
– Leap+Oculus : https://www.leapmotion.com/product/vr
– [x] Allow images must be enabled in Leap Control panel : https://developer.leapmotion.com/gallery/oculus-passthrough 

 


1 Comment + Add Comment

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Github Join Discord Twitch Instagram BlueSky

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.