Exemple #1
0
        private bool enableReticule;                 // Will be set true if there is both a texture and material present.


        //(De)Initialization:
        private void OnEnable()
        {
            cameraInitialPosition = m_camera.transform.localPosition;

            var leftEyeRenderTexture  = CreateNewRenderTexure();
            var rightEyeRenderTexture = CreateNewRenderTexure();

            var renderer = eyePieceLens.GetComponent <MeshRenderer> ();

            renderer.material = new Material(eyePieceShader);
            renderer.material.SetTexture("_LeftEyeTexture", leftEyeRenderTexture);
            renderer.material.SetTexture("_RightEyeTexture", rightEyeRenderTexture);


            // Setup the postprocessing stack (initialization order matters!!).
            if (!m_camera.gameObject.GetComponent <PostProcessingBehaviour> ())
            {
                InitializePostProcessingProfile();
            }

            if (reticleMaterial != null && reticleTexture != null)
            {
                InitializeReticle();
            }

            vignetteRight = InitializeVignette(rightEyeRenderTexture);
            vignetteLeft  = InitializeVignette(leftEyeRenderTexture);

            m_camera.enabled       = true;
            m_camera.targetTexture = leftEyeRenderTexture;             //just set this so OpenVR doesn't take the camera away.

            //playerCameraParent = GameObject.FindGameObjectWithTag ("MainCamera").transform.parent;

            // Precompute the constants for the linear equation:
            //    m   = (PT2_Y -    PT1_Y      ) / (    PT2_X      -      PT1_X    )
            slopeProx = (1.0f - eyeMinIntensity) / (eyeMaxDistance - eyeMinDistance);             // Precomputed slope: m = (y2-y1) / (x2-x1)

            //    b        =     PT1_Y       - (    m     *     PT1_X     )
            yInterceptProx = eyeMinIntensity - (slopeProx * eyeMinDistance);             // Given the slope, substitue a value for PT1 and solve for Y.

            //Debug and print the constants for the linear equation:
            //Debug.Log("y2=" + 1 + " y1=" + eyeMinIntensity + " x2=" + eyeMaxDistance + " x1=" + eyeMinDistance);
            //Debug.Log("m=" + slopeProx + " b=" + yInterceptProx);
        }
Exemple #2
0
 private void DoLensEffect(SniperScopeVignetting vignette, float eyeProxmity)
 {
     vignette.center.x  = vignetteCenter.x;
     vignette.center.y  = vignetteCenter.y;
     vignette.intensity = Mathf.Abs(eyeProxmity);
 }