GetSceneTexture() public static method

public static GetSceneTexture ( bool hdr ) : RenderTexture
hdr bool
return RenderTexture
Beispiel #1
0
    void RenderEye(SteamVR vr, Hmd_Eye eye, LayerMask mask)
    {
        int i = (int)eye;

        SteamVR_Render.eye = eye;

        if (cameraMask != null)
        {
            cameraMask.Set(vr, eye);
        }

        foreach (var c in cameras)
        {
            c.transform.localPosition = vr.eyes[i].pos;
            c.transform.localRotation = vr.eyes[i].rot;

            // Update position to keep from getting culled
            cameraMask.transform.position = c.transform.position;

            var camera = c.GetComponent <Camera>();
            camera.targetTexture = SteamVR_Camera.GetSceneTexture(camera.hdr);
            int cullingMask = camera.cullingMask;
            camera.cullingMask |= mask;
            camera.Render();
            camera.cullingMask = cullingMask;
        }
    }
Beispiel #2
0
    private IEnumerator RenderLoop()
    {
        while (true)
        {
            yield return(new WaitForEndOfFrame());

            var vr = SteamVR.instance;

            if (vr.compositor.CanRenderScene())
            {
                vr.compositor.SetTrackingSpace(trackingSpace);
                vr.compositor.WaitGetPoses(poses, gamePoses);
                SteamVR_Utils.Event.Send("new_poses", poses);
            }

            GL.IssuePluginEvent(20150313);                                                                // Fire off render event to perform our compositor sync
            SteamVR_Camera.GetSceneTexture(cameras[0].GetComponent <Camera>().hdr).GetNativeTexturePtr(); // flush render event

            var overlay = SteamVR_Overlay.instance;
            if (overlay != null)
            {
                overlay.UpdateOverlay(vr);
            }

            RenderEye(vr, Hmd_Eye.Eye_Left, leftMask);
            RenderEye(vr, Hmd_Eye.Eye_Right, rightMask);

            if (cameraMask != null)
            {
                cameraMask.Clear();
            }

            GL.IssuePluginEvent(20150213);             // Fire off render event for in-process present hook
        }
    }
Beispiel #3
0
    private IEnumerator RenderLoop()
    {
        while (Application.isPlaying)
        {
            yield return(waitForEndOfFrame);

            if (pauseRendering)
            {
                continue;
            }

            var compositor = OpenVR.Compositor;
            if (compositor != null)
            {
                if (!compositor.CanRenderScene())
                {
                    continue;
                }

                compositor.SetTrackingSpace(trackingSpace);



                //SteamVR_Utils.QueueEventOnRenderThread(SteamVR.Unity.k_nRenderEventID_WaitGetPoses);
                //This is what the above commented out line does:
                GL.IssuePluginEvent(201510020);

                // Hack to flush render event that was queued in Update (this ensures WaitGetPoses has returned before we grab the new values).
                SteamVR_Camera.GetSceneTexture(cameras[0].GetComponent <Camera>().hdr).GetNativeTexturePtr();

                compositor.GetLastPoses(poses, gamePoses);

                SteamVR_Events.NewPoses.Send(poses);
                SteamVR_Events.NewPosesApplied.Send();
            }

            var overlay = SteamVR_Overlay.instance;
            if (overlay != null)
            {
                overlay.UpdateOverlay();
            }

            var vr = SteamVR.instance;
            RenderEye(vr, EVREye.Eye_Left);
            RenderEye(vr, EVREye.Eye_Right);

            // Move cameras back to head position so they can be tracked reliably
            foreach (var c in cameras)
            {
                c.transform.localPosition = Vector3.zero;
                c.transform.localRotation = Quaternion.identity;
            }

            if (cameraMask != null)
            {
                cameraMask.Clear();
            }
        }
    }
Beispiel #4
0
    void OnPostRender()
    {
        var vr     = SteamVR.instance;
        var camera = GetComponent <Camera>();
        var aspect = scale * camera.aspect / vr.aspect;

        var x0 = -scale;
        var x1 = scale;
        var y0 = aspect;
        var y1 = -aspect;

        var blitMaterial = SteamVR_Camera.blitMaterial;

        blitMaterial.mainTexture = SteamVR_Camera.GetSceneTexture(camera.hdr);

        GL.PushMatrix();
        GL.LoadOrtho();
#if !(UNITY_5_0)
        blitMaterial.SetPass(0);
#else
        blitMaterial.SetPass(QualitySettings.activeColorSpace == ColorSpace.Linear ? 1 : 0);
#endif
        GL.Begin(GL.QUADS);
        GL.TexCoord2(0.0f, 0.0f); GL.Vertex3(x0, y0, 0);
        GL.TexCoord2(1.0f, 0.0f); GL.Vertex3(x1, y0, 0);
        GL.TexCoord2(1.0f, 1.0f); GL.Vertex3(x1, y1, 0);
        GL.TexCoord2(0.0f, 1.0f); GL.Vertex3(x0, y1, 0);
        GL.End();
        GL.PopMatrix();

        var overlay = SteamVR_Overlay.instance;
        if (overlay && overlay.texture && overlayMaterial && drawOverlay)
        {
            var texture = overlay.texture;
            overlayMaterial.mainTexture = texture;

            var u0 = 0.0f;
            var v0 = 1.0f - (float)Screen.height / texture.height;
            var u1 = (float)Screen.width / texture.width;
            var v1 = 1.0f;

            GL.PushMatrix();
            GL.LoadOrtho();
#if !(UNITY_5_0)
            overlayMaterial.SetPass(QualitySettings.activeColorSpace == ColorSpace.Linear ? 1 : 0);
#else
            overlayMaterial.SetPass(0);
#endif
            GL.Begin(GL.QUADS);
            GL.TexCoord2(u0, v0); GL.Vertex3(-1, -1, 0);
            GL.TexCoord2(u1, v0); GL.Vertex3(1, -1, 0);
            GL.TexCoord2(u1, v1); GL.Vertex3(1, 1, 0);
            GL.TexCoord2(u0, v1); GL.Vertex3(-1, 1, 0);
            GL.End();
            GL.PopMatrix();
        }
    }
Beispiel #5
0
    private void OnPostRender()
    {
        SteamVR  instance     = SteamVR.instance;
        Camera   component    = base.GetComponent <Camera>();
        float    num          = this.scale * component.aspect / instance.aspect;
        float    x            = -this.scale;
        float    x2           = this.scale;
        float    y            = num;
        float    y2           = -num;
        Material blitMaterial = SteamVR_Camera.blitMaterial;

        blitMaterial.mainTexture = SteamVR_Camera.GetSceneTexture(component.hdr);
        GL.PushMatrix();
        GL.LoadOrtho();
        blitMaterial.SetPass(0);
        GL.Begin(7);
        GL.TexCoord2(0f, 0f);
        GL.Vertex3(x, y, 0f);
        GL.TexCoord2(1f, 0f);
        GL.Vertex3(x2, y, 0f);
        GL.TexCoord2(1f, 1f);
        GL.Vertex3(x2, y2, 0f);
        GL.TexCoord2(0f, 1f);
        GL.Vertex3(x, y2, 0f);
        GL.End();
        GL.PopMatrix();
        SteamVR_Overlay instance2 = SteamVR_Overlay.instance;

        if (instance2 && instance2.texture && SteamVR_GameView.overlayMaterial && this.drawOverlay)
        {
            Texture texture = instance2.texture;
            SteamVR_GameView.overlayMaterial.mainTexture = texture;
            float x3 = 0f;
            float y3 = 1f - (float)Screen.height / (float)texture.height;
            float x4 = (float)Screen.width / (float)texture.width;
            float y4 = 1f;
            GL.PushMatrix();
            GL.LoadOrtho();
            SteamVR_GameView.overlayMaterial.SetPass((QualitySettings.activeColorSpace != ColorSpace.Linear) ? 0 : 1);
            GL.Begin(7);
            GL.TexCoord2(x3, y3);
            GL.Vertex3(-1f, -1f, 0f);
            GL.TexCoord2(x4, y3);
            GL.Vertex3(1f, -1f, 0f);
            GL.TexCoord2(x4, y4);
            GL.Vertex3(1f, 1f, 0f);
            GL.TexCoord2(x3, y4);
            GL.Vertex3(-1f, 1f, 0f);
            GL.End();
            GL.PopMatrix();
        }
    }
Beispiel #6
0
    private IEnumerator RenderLoop()
    {
        while (true)
        {
            yield return(new WaitForEndOfFrame());

            if (pauseRendering)
            {
                continue;
            }

            var vr = SteamVR.instance;

            if (!vr.compositor.CanRenderScene())
            {
                continue;
            }

            vr.compositor.SetTrackingSpace(trackingSpace);
            SteamVR_Utils.QueueEventOnRenderThread(Unity.k_nRenderEventID_WaitGetPoses);

            // Hack to flush render event that was queued in Update (this ensures WaitGetPoses has returned before we grab the new values).
            Unity.EventWriteString("[UnityMain] GetNativeTexturePtr - Begin");
            SteamVR_Camera.GetSceneTexture(cameras[0].GetComponent <Camera>().hdr).GetNativeTexturePtr();
            Unity.EventWriteString("[UnityMain] GetNativeTexturePtr - End");

            vr.compositor.GetLastPoses(poses, gamePoses);
            SteamVR_Utils.Event.Send("new_poses", poses);

            var overlay = SteamVR_Overlay.instance;
            if (overlay != null)
            {
                overlay.UpdateOverlay(vr);
            }

            RenderEye(vr, EVREye.Eye_Left);
            RenderEye(vr, EVREye.Eye_Right);

            // Move cameras back to head position so they can be tracked reliably
            foreach (var c in cameras)
            {
                c.transform.localPosition = Vector3.zero;
                c.transform.localRotation = Quaternion.identity;
            }

            if (cameraMask != null)
            {
                cameraMask.Clear();
            }
        }
    }
    private IEnumerator RenderLoop()
    {
        while (true)
        {
            yield return(new WaitForEndOfFrame());

            var vr = SteamVR.instance;

            if (vr.compositor.CanRenderScene())
            {
                vr.compositor.SetTrackingSpace(trackingSpace);
                vr.compositor.WaitGetPoses(poses, gamePoses);
                SteamVR_Utils.Event.Send("new_poses", poses);
            }

            GL.IssuePluginEvent(20150313);                                                                // Fire off render event to perform our compositor sync
            SteamVR_Camera.GetSceneTexture(cameras[0].GetComponent <Camera>().hdr).GetNativeTexturePtr(); // flush render event

            var overlay = SteamVR_Overlay.instance;
            if (overlay != null)
            {
                overlay.UpdateOverlay(vr);
            }

            RenderEye(vr, Hmd_Eye.Eye_Left, leftMask);
            RenderEye(vr, Hmd_Eye.Eye_Right, rightMask);

            // Move cameras back to head position so they can be tracked reliably
            foreach (var c in cameras)
            {
                c.transform.localPosition = Vector3.zero;
                c.transform.localRotation = Quaternion.identity;
            }

            if (cameraMask != null)
            {
                cameraMask.Clear();
            }

            GL.IssuePluginEvent(20150213);             // Fire off render event for in-process present hook
        }
    }
    void RenderEye(SteamVR vr, EVREye eye)
    {
        try
        {
            int i = (int)eye;
            SteamVR_Render.eye = eye;

            if (cameraMask != null)
            {
                cameraMask.Set(vr, eye);
            }

            foreach (var c in cameras)
            {
                c.transform.localPosition = vr.eyes[i].pos;
                c.transform.localRotation = vr.eyes[i].rot;

                // Update position to keep from getting culled
                cameraMask.transform.position = c.transform.position;

                var camera = c.GetComponent <Camera>();
                camera.targetTexture = SteamVR_Camera.GetSceneTexture(camera.hdr);
                int cullingMask = camera.cullingMask;
                if (eye == EVREye.Eye_Left)
                {
                    camera.cullingMask &= ~rightMask;
                    camera.cullingMask |= leftMask;
                }
                else
                {
                    camera.cullingMask &= ~leftMask;
                    camera.cullingMask |= rightMask;
                }
                camera.Render();
                camera.cullingMask = cullingMask;
            }
        } catch (Exception e)
        {
            Console.WriteLine(e);
        }
    }