Пример #1
0
    void GuiWindowContent(int windowID)
    {
        GUILayout.BeginHorizontal();
        GUILayout.BeginVertical();
        GUILayout.BeginHorizontal();
        GUILayout.EndHorizontal();

        S3DEnabled = GUILayout.Toggle(S3DEnabled, " Enable S3D");

        string[] modeStrings = { "Interleaved", "Side By Side", "Over Under", "Anaglyph" };
        method = (_3DMethod)GUILayout.SelectionGrid((int)method, modeStrings, 1, GUILayout.Width(100));

        GUILayout.EndVertical();
        GUILayout.BeginVertical();
        GUILayout.BeginHorizontal();

        swapLR = GUILayout.Toggle(swapLR, " Swap Left-Right Cameras");

        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();

        string[] interleavedTypeStrings = { "Horizontal", "Vertical", "Checkerboard" };
        interleavedType = (InterleavedType)GUILayout.Toolbar((int)interleavedType, interleavedTypeStrings, GUILayout.Width(298));

        GUILayout.FlexibleSpace();
        GUILayout.Label("PPI", GUILayout.Width(30));

        if (GUILayout.Button("-", GUILayout.Width(20)))
        {
            PPI -= 1;
        }

        string PPIString   = StringCheck(PPI.ToString());
        string fieldString = GUILayout.TextField(PPIString, 5, GUILayout.Width(40));

        if (fieldString != PPIString)
        {
            PPI = System.Convert.ToSingle(fieldString);
        }

        if (GUILayout.Button("+", GUILayout.Width(20)))
        {
            PPI += 1;
        }

        GUILayout.Label(" pix");
        GUILayout.Space(20);

        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();

        GUILayout.FlexibleSpace();
        GUILayout.Label("Pixel pitch", GUILayout.Width(70));

        if (GUILayout.Button("-", GUILayout.Width(20)))
        {
            pixelPitch -= .001f;
        }

        string pixelPitchString = StringCheck(pixelPitch.ToString());

        fieldString = GUILayout.TextField(pixelPitchString, 5, GUILayout.Width(40));

        if (fieldString != pixelPitchString)
        {
            pixelPitch = System.Convert.ToSingle(fieldString);
        }


        if (GUILayout.Button("+", GUILayout.Width(20)))
        {
            pixelPitch += .001f;
        }

        GUILayout.Label(" mm");
        GUILayout.Space(15);

        GUILayout.EndHorizontal();
        GUILayout.EndVertical();
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        GUILayout.Space(4);
        GUILayout.BeginVertical();

        GUILayout.Label("          User IPD", GUILayout.Width(100));
        GUILayout.Label("        Virtual IPD", GUILayout.Width(100));
        GUILayout.Label("  Horizontal FOV", GUILayout.Width(100));
        GUILayout.Label("     Vertical FOV", GUILayout.Width(100));
        GUILayout.Label("Screen distance", GUILayout.Width(100));

        GUILayout.EndVertical();
        GUILayout.Space(4);
        GUILayout.BeginVertical();

        GUILayout.Space(10);
        userIPD = GUILayout.HorizontalSlider(userIPD, 0, 100, GUILayout.Width(300));

        GUILayout.Space(9);
        virtualIPD = GUILayout.HorizontalSlider(virtualIPD, 0, 1000, GUILayout.Width(300));

        GUILayout.Space(9);
        //hFOV = GUILayout.HorizontalSlider(hFOV, .1f, 179.9f, GUILayout.Width(300)); //179.9f will cause the slider stuck in the standalone player but OK in the editor
        hFOV = GUILayout.HorizontalSlider(hFOV, 1, 179, GUILayout.Width(300));

        GUILayout.EndVertical();
        GUILayout.BeginVertical();
        GUILayout.BeginHorizontal();

        if (GUILayout.Button("-", GUILayout.Width(20)))
        {
            userIPD -= .1f;
        }

        string userIPDString = StringCheck(userIPD.ToString());

        fieldString = GUILayout.TextField(userIPDString, 5, GUILayout.Width(40));

        if (fieldString != userIPDString)
        {
            userIPD = System.Convert.ToSingle(fieldString);
        }

        if (GUILayout.Button("+", GUILayout.Width(20)))
        {
            userIPD += .1f;
        }

        GUILayout.Label(" mm");

        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();

        if (GUILayout.Button("-", GUILayout.Width(20)))
        {
            virtualIPD -= 1f;
        }

        string virtualIPDString = StringCheck(virtualIPD.ToString());

        fieldString = GUILayout.TextField(virtualIPDString, 5, GUILayout.Width(40));

        if (fieldString != virtualIPDString)
        {
            virtualIPD = System.Convert.ToSingle(fieldString);
        }

        if (GUILayout.Button("+", GUILayout.Width(20)))
        {
            virtualIPD += 1f;
        }

        GUILayout.Label(" mm");

        matchUserIPD = GUILayout.Toggle(matchUserIPD, " Match User IPD");

        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();

        if (GUILayout.Button("-", GUILayout.Width(20)))
        {
            hFOV -= .1f;
        }

        string hFOVString = StringCheck(hFOV.ToString());

        fieldString = GUILayout.TextField(hFOVString, 5, GUILayout.Width(40));

        if (fieldString != hFOVString)
        {
            hFOV = System.Convert.ToSingle(fieldString);
        }

        if (GUILayout.Button("+", GUILayout.Width(20)))
        {
            hFOV += .1f;
        }

        GUILayout.Label(" deg");

        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();

        GUILayout.Space(28);
        GUILayout.TextField(vFOV.ToString(), 5, GUILayout.Width(40));

        GUILayout.Label(" deg");

        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();

        GUILayout.Space(28);
        GUILayout.TextField(screenDistance.ToString(), 5, GUILayout.Width(40));

        GUILayout.Label(" mm");

        GUILayout.EndHorizontal();
        GUILayout.EndVertical();
        GUILayout.EndHorizontal();

        GUI.DragWindow(new Rect(0, 0, 640, 20)); //make GUI window draggable by top
    }
Пример #2
0
    void OnEnable()
    {
        if (GraphicsSettings.renderPipelineAsset == null)
        {
            defaultRender = true;
        }

        S3DMaterial = new Material(Shader.Find("Stereo3D Screen Quad"));
        S3DMaterial.SetColor("_LeftCol", anaglyphLeftColor);
        S3DMaterial.SetColor("_RightCol", anaglyphRightColor);

        cam = GetComponent <Camera>();
        cam.stereoTargetEye = StereoTargetEyeMask.None;

#if UNITY_POST_PROCESSING_STACK_V2
        if (GetComponent <PostProcessLayer>())
        {
            PPLayer       = GetComponent <PostProcessLayer>();
            PPLayerStatus = PPLayer.enabled;

            if (PPLayerStatus)
            {
                setMatrixDirectly = false;
            }
        }
#endif


        cullingMask = cam.cullingMask;
        nearClip    = cam.nearClipPlane;

        if (cameraPrefab)
        {
            leftCam       = Instantiate(cameraPrefab, transform.position, transform.rotation).GetComponent <Camera>();
            leftCam.name  = "leftCam";
            rightCam      = Instantiate(cameraPrefab, transform.position, transform.rotation).GetComponent <Camera>();
            rightCam.name = "rightCam";
        }
        else
        {
            leftCam  = new GameObject("leftCam").AddComponent <Camera>();
            rightCam = new GameObject("rightCam").AddComponent <Camera>();
            leftCam.CopyFrom(cam);
            rightCam.CopyFrom(cam);
            leftCam.rect = rightCam.rect = Rect.MinMaxRect(0, 0, 1, 1);
        }

        leftCam.depth            = rightCam.depth = cam.depth;
        leftCam.transform.parent = rightCam.transform.parent = transform;
        leftCam.stereoTargetEye  = StereoTargetEyeMask.Left;
        rightCam.stereoTargetEye = StereoTargetEyeMask.Right;

        if (Screen.dpi != 0)
        {
            PPI = Screen.dpi;
        }

        PPISet();
        UserIPDSet();
        VirtualIPDSet();
        HFOVSet();
        CamSet();
        RTSet();

        lastS3DEnabled         = S3DEnabled;
        lastSwapLR             = swapLR;
        lastUserIPD            = userIPD;
        lastVirtualIPD         = virtualIPD;
        lastMatchUserIPD       = matchUserIPD;
        lastPPI                = PPI;
        lastPixelPitch         = pixelPitch;
        lastHFOV               = hFOV;
        lastMethod             = method;
        lastInterleavedType    = interleavedType;
        lastAnaglyphLeftColor  = anaglyphLeftColor;
        lastAnaglyphRightColor = anaglyphRightColor;
        lastCamRect            = cam.rect;
    }
Пример #3
0
    void Update()
    {
        if (Input.GetKeyDown(GuiKey))
        {
            GuiVisible = !GuiVisible;
        }

        if (Input.GetKeyDown(S3DKey) && !Input.GetKey(KeyCode.LeftControl))
        {
            S3DEnabled = !S3DEnabled;
        }

        if (Input.GetKeyDown(S3DKey) && Input.GetKey(KeyCode.LeftControl))
        {
            swapLR = !swapLR;
        }

        if (Input.GetKey(increaseFovKey) && !Input.GetKey(KeyCode.LeftControl))
        {
            if (Input.GetKey(KeyCode.LeftShift))
            {
                hFOV += 1;
            }
            else
            {
                hFOV += .1f;
            }
        }

        if (Input.GetKey(decreaseFovKey) && !Input.GetKey(KeyCode.LeftControl))
        {
            if (Input.GetKey(KeyCode.LeftShift))
            {
                hFOV -= 1;
            }
            else
            {
                hFOV -= .1f;
            }
        }

        if (Input.GetKey(decreaseFovKey) && Input.GetKey(KeyCode.LeftControl))
        {
            if (Input.GetKey(KeyCode.LeftShift))
            {
                virtualIPD += 10;
            }
            else
            {
                virtualIPD += 1;
            }
        }

        if (Input.GetKey(increaseFovKey) && Input.GetKey(KeyCode.LeftControl))
        {
            if (Input.GetKey(KeyCode.LeftShift))
            {
                virtualIPD -= 10;
            }
            else
            {
                virtualIPD -= 1;
            }
        }

        //check variable changes after Keys pressed
        if (lastS3DEnabled != S3DEnabled)
        {
            lastS3DEnabled = S3DEnabled;
            RTSet();
        }

        if (lastSwapLR != swapLR)
        {
            lastSwapLR = swapLR;
            CamSet();
        }

        if (lastUserIPD != userIPD)
        {
            lastUserIPD = userIPD;
            UserIPDSet();
        }

        if (lastVirtualIPD != virtualIPD)
        {
            lastVirtualIPD = virtualIPD;
            VirtualIPDSet();
        }

        if (lastMatchUserIPD != matchUserIPD)
        {
            lastMatchUserIPD = matchUserIPD;
            VirtualIPDSet();
        }

        if (lastPPI != PPI)
        {
            lastPPI = PPI;
            PPISet();
        }

        if (lastPixelPitch != pixelPitch)
        {
            lastPixelPitch = pixelPitch;
            PixelPitchSet();
        }

        if (cam.fieldOfView != vFOV) //check camera FOV changes to set FOV from other scripts
        {
            hFOV = Mathf.Atan(cam.aspect * Mathf.Tan(cam.fieldOfView * Mathf.PI / 360)) * 360 / Mathf.PI;
        }

        if (lastHFOV != hFOV)
        {
            lastHFOV = hFOV;
            HFOVSet();
        }

        if (lastMethod != method)
        {
            lastMethod = method;
            ViewSet();
            RTSet();
        }

        if (lastInterleavedType != interleavedType)
        {
            lastInterleavedType = interleavedType;
            RTSet();
        }

        if (lastAnaglyphLeftColor != anaglyphLeftColor)
        {
            lastAnaglyphLeftColor = anaglyphLeftColor;
            S3DMaterial.SetColor("_LeftCol", anaglyphLeftColor);
        }

        if (lastAnaglyphRightColor != anaglyphRightColor)
        {
            lastAnaglyphRightColor = anaglyphRightColor;
            S3DMaterial.SetColor("_RightCol", anaglyphRightColor);
        }

        if (lastCamRect != cam.rect)
        {
            lastCamRect = cam.rect;
            ViewSet();
            RTSet();
        }
    }