view Orchestland/Assets/LeapMotion/Scripts/LeapImageBasedMaterial.cs @ 3:0030a1b971fb default tip

merge
author Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
date Fri, 17 Jul 2015 23:23:43 +0900
parents f7675884f2a1
children
line wrap: on
line source

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);
    }
}