private void initImageBasedMaterial (LeapImageBasedMaterial imageBasedMaterial)
  {
    Material material = imageBasedMaterial.GetComponent<Renderer> ().material;

    switch (_currentFormat) {
    case Image.FormatType.INFRARED:
      material.EnableKeyword (IR_SHADER_VARIANT_NAME);
      material.DisableKeyword (RGB_SHADER_VARIANT_NAME);
      break;
    case (Image.FormatType)4:
      material.EnableKeyword (RGB_SHADER_VARIANT_NAME);
      material.DisableKeyword (IR_SHADER_VARIANT_NAME);
      break;
    default:
      Debug.LogWarning ("Unexpected format type " + _currentFormat);
      break;
    }

    if (SystemInfo.SupportsRenderTextureFormat (RenderTextureFormat.Depth)) {
      material.EnableKeyword (DEPTH_TEXTURE_VARIANT_NAME);
    } else {
      material.DisableKeyword (DEPTH_TEXTURE_VARIANT_NAME);
    }

    imageBasedMaterial.GetComponent<Renderer> ().material.SetFloat ("_LeapGammaCorrectionExponent", 1.0f / gammaCorrection);
  }
    private void initImageBasedMaterial(LeapImageBasedMaterial imageBasedMaterial)
    {
        Material material = imageBasedMaterial.GetComponent <Renderer> ().material;

        switch (_currentFormat)
        {
        case Image.FormatType.INFRARED:
            material.EnableKeyword(IR_SHADER_VARIANT_NAME);
            material.DisableKeyword(RGB_SHADER_VARIANT_NAME);
            break;

        case (Image.FormatType) 4:
            material.EnableKeyword(RGB_SHADER_VARIANT_NAME);
            material.DisableKeyword(IR_SHADER_VARIANT_NAME);
            break;

        default:
            Debug.LogWarning("Unexpected format type " + _currentFormat);
            break;
        }

        if (SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Depth))
        {
            material.EnableKeyword(DEPTH_TEXTURE_VARIANT_NAME);
        }
        else
        {
            material.DisableKeyword(DEPTH_TEXTURE_VARIANT_NAME);
        }

        imageBasedMaterial.GetComponent <Renderer> ().material.SetFloat("_LeapGammaCorrectionExponent", 1.0f / gammaCorrection);
    }
Exemplo n.º 3
0
    private void updateImageBasedMaterial(LeapImageBasedMaterial imageBasedMaterial, ref Image image)
    {
        imageBasedMaterial.GetComponent <Renderer>().material.SetTexture("_LeapTexture", _mainTexture);

        Vector4 projection = new Vector4();

        projection.x = GetComponent <Camera>().projectionMatrix[0, 2];
        projection.z = GetComponent <Camera>().projectionMatrix[0, 0];
        projection.w = GetComponent <Camera>().projectionMatrix[1, 1];
        imageBasedMaterial.GetComponent <Renderer>().material.SetVector("_LeapProjection", projection);

        if (_distortion == null)
        {
            initDistortion(image);
            loadDistortion(image);
            _forceDistortionRecalc = false;
        }

        if (_forceDistortionRecalc || (_requestDistortionRecalc && _controller.Frame().Hands.Count != 0))
        {
            loadDistortion(image);
            _requestDistortionRecalc = false;
            _forceDistortionRecalc   = false;
        }

        imageBasedMaterial.GetComponent <Renderer>().material.SetTexture("_LeapDistortion", _distortion);
    }
Exemplo n.º 4
0
    private void initImageBasedMaterial(LeapImageBasedMaterial imageBasedMaterial)
    {
        Material material = imageBasedMaterial.GetComponent <Renderer>().material;

        foreach (string keyword in material.shaderKeywords)
        {
            material.DisableKeyword(keyword);
        }

        switch (_currentFormat)
        {
        case Image.FormatType.INFRARED:
            material.EnableKeyword("LEAP_FORMAT_IR");
            break;

        case (Image.FormatType) 4:
            material.EnableKeyword("LEAP_FORMAT_RGB");
            break;

        default:
            Debug.LogWarning("Unexpected format type " + _currentFormat);
            break;
        }

        imageBasedMaterial.GetComponent <Renderer>().material.SetFloat("_LeapGammaCorrectionExponent", 1.0f / gammaCorrection);
    }
Exemplo n.º 5
0
    void OnPreRender()
    {
        if (syncMode == SYNC_MODE.LOW_LATENCY)
        {
            _imageList = _controller.Images;
        }

        Image referenceImage = _imageList[(int)eye];

        if (referenceImage.Width == 0 || referenceImage.Height == 0)
        {
            _missedImages++;
            if (_missedImages == IMAGE_WARNING_WAIT)
            {
                Debug.LogWarning("Can't find any images. " +
                                 "Make sure you enabled 'Allow Images' in the Leap Motion Settings, " +
                                 "you are on tracking version 2.1+ and " +
                                 "your Leap Motion device is plugged in.");
            }
            return;
        }

        if (referenceImage.Height != _currentHeight || referenceImage.Width != _currentWidth || referenceImage.Format != _currentFormat)
        {
            initMainTexture(referenceImage);

            _currentHeight = referenceImage.Height;
            _currentWidth  = referenceImage.Width;
            _currentFormat = referenceImage.Format;

            _imageBasedMaterialsToInit.Clear();
            _imageBasedMaterialsToInit.AddRange(_registeredImageBasedMaterials);

            _forceDistortionRecalc = true;
        }

        loadMainTexture(referenceImage);

        for (int i = _imageBasedMaterialsToInit.Count - 1; i >= 0; i--)
        {
            LeapImageBasedMaterial material = _imageBasedMaterialsToInit[i];
            initImageBasedMaterial(material);
            _imageBasedMaterialsToInit.RemoveAt(i);
        }

        foreach (LeapImageBasedMaterial material in _registeredImageBasedMaterials)
        {
            if (material.imageMode == LeapImageBasedMaterial.ImageMode.STEREO ||
                (material.imageMode == LeapImageBasedMaterial.ImageMode.LEFT_ONLY && eye == EYE.LEFT) ||
                (material.imageMode == LeapImageBasedMaterial.ImageMode.RIGHT_ONLY && eye == EYE.RIGHT))
            {
                updateImageBasedMaterial(material, ref referenceImage);
            }
        }
    }
Exemplo n.º 6
0
    private void setBackgroundQuadEnabled(bool enabled)
    {
        Renderer backgroundQuadRenderer = _backgroundQuad.GetComponent <Renderer>();
        LeapImageBasedMaterial backgroundQuadMatrialScript = _backgroundQuad.GetComponent <LeapImageBasedMaterial>();

        if (backgroundQuadRenderer == null)
        {
            throw new UnityEngine.MissingComponentException("The object " + _backgroundQuad.gameObject.name + " is missing a " + backgroundQuadRenderer.GetType().ToString() + " component.");
        }

        if (backgroundQuadMatrialScript == null)
        {
            throw new UnityEngine.MissingComponentException("The object " + _backgroundQuad.gameObject.name + " is missing a " + backgroundQuadMatrialScript.GetType().ToString() + " component.");
        }

        _backgroundQuad.GetComponent <Renderer>().enabled = enabled;
        _backgroundQuad.GetComponent <LeapImageBasedMaterial>().enabled = enabled;

        EditorUtility.SetDirty(_backgroundQuad);
    }
Exemplo n.º 7
0
    private void initImageBasedMaterial(LeapImageBasedMaterial imageBasedMaterial) {
        Material material = imageBasedMaterial.GetComponent<Renderer>().material;

        foreach (string keyword in material.shaderKeywords) {
            material.DisableKeyword(keyword);
        }

        switch(_currentFormat){
            case Image.FormatType.INFRARED:
                material.EnableKeyword("LEAP_FORMAT_IR");
                break;
            case (Image.FormatType)4:
                material.EnableKeyword("LEAP_FORMAT_RGB");
                break;
            default:
                Debug.LogWarning("Unexpected format type " + _currentFormat);
                break;
        }

        imageBasedMaterial.GetComponent<Renderer>().material.SetFloat("_LeapGammaCorrectionExponent", 1.0f / gammaCorrection);
    }
Exemplo n.º 8
0
    // Use this for initialization
    void Start()
    {
        OVRCameraRig OculusCamera = gameObject.GetComponent <OVRCameraRig>();

        _handController = gameObject.AddComponent <HandController> ();
        _handController.isHeadMounted = true;
        _handController.destroyHands  = true;


        LeapImageRetriever.EYE[] eyes = new LeapImageRetriever.EYE[] { LeapImageRetriever.EYE.RIGHT, IsStereo? LeapImageRetriever.EYE.LEFT:LeapImageRetriever.EYE.RIGHT };
        if (OculusCamera != null)
        {
            Camera[] cams = new Camera[] { OculusCamera.rightEyeCamera, OculusCamera.leftEyeCamera };

            for (int i = 0; i < cams.Length; ++i)
            {
                LeapImageRetriever lret = cams[i].gameObject.AddComponent <LeapImageRetriever>();
                lret.eye             = eyes[i];
                lret.syncMode        = LeapImageRetriever.SYNC_MODE.LOW_LATENCY;
                lret.gammaCorrection = 1.0f;

                _retrivals[i] = lret;

                cams[i].gameObject.AddComponent <EnableDepthBuffer>();
            }

            //OculusCamera.centerEyeAnchor.gameObject;

            GameObject HandsRenderer = GameObject.CreatePrimitive(PrimitiveType.Quad);
            HandsRenderer.name                    = "LeapMotionHandsRenderer";
            HandsRenderer.transform.parent        = OculusCamera.centerEyeAnchor.transform;
            HandsRenderer.transform.localPosition = new Vector3(0, 0, 0.137f);
            HandsRenderer.transform.localRotation = Quaternion.identity;
            LeapImageBasedMaterial lmat = HandsRenderer.AddComponent <LeapImageBasedMaterial>();
            lmat.imageMode = IsStereo?LeapImageBasedMaterial.ImageMode.STEREO:LeapImageBasedMaterial.ImageMode.RIGHT_ONLY;
            HandsRenderer.GetComponent <MeshRenderer>().material = HandsMaterial;
            _Hands = HandsRenderer;
            _Hands.GetComponent <MeshRenderer>().enabled = IsActive;
        }
    }
    private void updateImageBasedMaterial(LeapImageBasedMaterial imageBasedMaterial, ref Image image)
    {
        Camera   camera   = GetComponent <Camera> ();
        Material material = imageBasedMaterial.GetComponent <Renderer> ().material;

        material.SetTexture("_LeapTexture", _mainTexture);

        Vector4 projection = new Vector4();

        projection.x = camera.projectionMatrix [0, 2];
        projection.y = 0f;
        projection.z = camera.projectionMatrix [0, 0];
        projection.w = camera.projectionMatrix [1, 1];
        material.SetVector("_LeapProjection", projection);

        if (_distortion == null)
        {
            initDistortion(image);
            loadDistortion(image);
            _forceDistortionRecalc = false;
        }

        if (_forceDistortionRecalc || (_requestDistortionRecalc && _controller.Frame().Hands.Count != 0))
        {
            loadDistortion(image);
            _requestDistortionRecalc = false;
            _forceDistortionRecalc   = false;
        }

        material.SetTexture("_LeapDistortion", _distortion);

        // Set camera parameters
        material.SetFloat("_VirtualCameraV", camera.fieldOfView);
        material.SetFloat("_VirtualCameraH", Mathf.Rad2Deg * Mathf.Atan(Mathf.Tan(Mathf.Deg2Rad * camera.fieldOfView / 2f) * camera.aspect) * 2f);
        material.SetMatrix("_InverseView", camera.worldToCameraMatrix.inverse);
    }
Exemplo n.º 10
0
 public static void unregisterImageBasedMaterial (LeapImageBasedMaterial imageBasedMaterial)
 {
   _registeredImageBasedMaterials.Remove (imageBasedMaterial);
 }
Exemplo n.º 11
0
 public static void registerImageBasedMaterial (LeapImageBasedMaterial imageBasedMaterial)
 {
   _registeredImageBasedMaterials.Add (imageBasedMaterial);
   _imageBasedMaterialsToInit.Add (imageBasedMaterial);
 }
Exemplo n.º 12
0
  private void updateImageBasedMaterial (LeapImageBasedMaterial imageBasedMaterial, ref Image image)
  {
    Camera camera = GetComponent<Camera> ();
    Material material = imageBasedMaterial.GetComponent<Renderer> ().material;
    material.SetTexture ("_LeapTexture", _mainTexture);

    Vector4 projection = new Vector4 ();
    projection.x = camera.projectionMatrix [0, 2];
    projection.y = 0f;
    projection.z = camera.projectionMatrix [0, 0];
    projection.w = camera.projectionMatrix [1, 1];
    material.SetVector ("_LeapProjection", projection);

    if (_distortion == null) {
      initDistortion (image);
      loadDistortion (image);
      _forceDistortionRecalc = false;
    }

    if (_forceDistortionRecalc || (_requestDistortionRecalc && _controller.Frame ().Hands.Count != 0)) {
      loadDistortion (image);
      _requestDistortionRecalc = false;
      _forceDistortionRecalc = false;
    }

    material.SetTexture ("_LeapDistortion", _distortion);

    // Set camera parameters
    material.SetFloat ("_VirtualCameraV", camera.fieldOfView);
    material.SetFloat ("_VirtualCameraH", Mathf.Rad2Deg * Mathf.Atan (Mathf.Tan (Mathf.Deg2Rad * camera.fieldOfView / 2f) * camera.aspect) * 2f);
    material.SetMatrix ("_InverseView", camera.worldToCameraMatrix.inverse);
  }
Exemplo n.º 13
0
 public static void unregisterImageBasedMaterial(LeapImageBasedMaterial imageBasedMaterial)
 {
     _registeredImageBasedMaterials.Remove(imageBasedMaterial);
 }
Exemplo n.º 14
0
 public static void registerImageBasedMaterial(LeapImageBasedMaterial imageBasedMaterial)
 {
     _registeredImageBasedMaterials.Add(imageBasedMaterial);
     _imageBasedMaterialsToInit.Add(imageBasedMaterial);
 }
Exemplo n.º 15
0
    void OnPreRender()
    {
        if (syncMode == SYNC_MODE.LOW_LATENCY)
        {
            _imageList = _controller.Images;

            /*if (!_imageList.IsEmpty) {
             * Debug.Log (name + " LOW_LATENCY: controller.Now(): " + _controller.Now() + " - imageList.Timestamp: " + _imageList[0].Timestamp + " = " + (_controller.Now() - _imageList[0].Timestamp));
             * } else {
             * Debug.LogWarning(name + " LOW_LATENCY -> NO FRAMES");
             * }*/
        }

        int imageEye = frameEye;

        switch (retrievedEye)
        {
        case EYE.LEFT:
            imageEye = 0;
            break;

        case EYE.RIGHT:
            imageEye = 1;
            break;

        case EYE.RIGHT_TO_LEFT:
            imageEye = 1 - imageEye;
            break;

        default:
            break;
        }

        Image referenceImage = _imageList [imageEye];

        if (referenceImage.Width == 0 || referenceImage.Height == 0)
        {
            _missedImages++;
            if (_missedImages == IMAGE_WARNING_WAIT)
            {
                Debug.LogWarning("Can't find any images. " +
                                 "Make sure you enabled 'Allow Images' in the Leap Motion Settings, " +
                                 "you are on tracking version 2.1+ and " +
                                 "your Leap Motion device is plugged in.");
            }
            return;
        }

        if (referenceImage.Height != _currentHeight || referenceImage.Width != _currentWidth || referenceImage.Format != _currentFormat)
        {
            initMainTexture(referenceImage);

            _currentHeight = referenceImage.Height;
            _currentWidth  = referenceImage.Width;
            _currentFormat = referenceImage.Format;

            _imageBasedMaterialsToInit.Clear();
            _imageBasedMaterialsToInit.AddRange(_registeredImageBasedMaterials);

            _forceDistortionRecalc = true;
        }

        loadMainTexture(referenceImage);

        for (int i = _imageBasedMaterialsToInit.Count - 1; i >= 0; i--)
        {
            LeapImageBasedMaterial material = _imageBasedMaterialsToInit [i];
            initImageBasedMaterial(material);
            _imageBasedMaterialsToInit.RemoveAt(i);
        }

        foreach (LeapImageBasedMaterial material in _registeredImageBasedMaterials)
        {
            if (material.imageMode == LeapImageBasedMaterial.ImageMode.STEREO ||
                (material.imageMode == LeapImageBasedMaterial.ImageMode.LEFT_ONLY && imageEye == 0) ||
                (material.imageMode == LeapImageBasedMaterial.ImageMode.RIGHT_ONLY && imageEye == 1))
            {
                updateImageBasedMaterial(material, ref referenceImage);
            }
        }

        frameEye++;
    }
Exemplo n.º 16
0
    private void updateImageBasedMaterial(LeapImageBasedMaterial imageBasedMaterial, ref Image image) {
        imageBasedMaterial.GetComponent<Renderer>().material.SetTexture("_LeapTexture", _mainTexture);

        Vector4 projection = new Vector4();
        projection.x = GetComponent<Camera>().projectionMatrix[0, 2];
        projection.z = GetComponent<Camera>().projectionMatrix[0, 0];
        projection.w = GetComponent<Camera>().projectionMatrix[1, 1];
        imageBasedMaterial.GetComponent<Renderer>().material.SetVector("_LeapProjection", projection);

        if (_distortion == null) {
            initDistortion(image);
            loadDistortion(image);
            _forceDistortionRecalc = false;
        }

        if (_forceDistortionRecalc || (_requestDistortionRecalc && _controller.Frame().Hands.Count != 0)) {
            loadDistortion(image);
            _requestDistortionRecalc = false;
            _forceDistortionRecalc = false;
        }

        imageBasedMaterial.GetComponent<Renderer>().material.SetTexture("_LeapDistortion", _distortion);
    }