diff Orchestland/Assets/LeapMotion/Scripts/LeapImageBasedMaterial.cs @ 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Orchestland/Assets/LeapMotion/Scripts/LeapImageBasedMaterial.cs	Fri Jul 17 23:09:20 2015 +0900
@@ -0,0 +1,37 @@
+using UnityEngine;
+using System.Collections;
+using System.Collections.Generic;
+
+public class LeapImageBasedMaterial : MonoBehaviour {
+    public ImageMode imageMode = ImageMode.STEREO;
+
+    public enum ImageMode {
+        STEREO,
+        LEFT_ONLY,
+        RIGHT_ONLY
+    }
+
+    void Awake() {
+        if (FindObjectOfType<LeapImageRetriever>() == null) {
+            Debug.LogWarning("Place a LeapImageRetriever script on a camera to enable Leap image-based materials");
+            enabled = false;
+        }
+    }
+
+    void OnEnable() {
+        LeapImageRetriever.registerImageBasedMaterial(this);
+        // Make shader consistent with settings
+        
+        if (QualitySettings.activeColorSpace == ColorSpace.Linear) {
+          GetComponent<Renderer> ().material.SetFloat ("_ColorSpaceGamma", 1.0f);
+        } else {
+          float gamma = -Mathf.Log10(Mathf.GammaToLinearSpace(0.1f));
+          GetComponent<Renderer> ().material.SetFloat ("_ColorSpaceGamma", gamma);
+          //Debug.Log ("Derived gamma = " + gamma);
+        }
+    }
+
+    void OnDisable() {
+        LeapImageRetriever.unregisterImageBasedMaterial(this);
+    }
+}