static public void SetOverride(
            Texture front  = null,
            Texture back   = null,
            Texture left   = null,
            Texture right  = null,
            Texture top    = null,
            Texture bottom = null)
        {
            var compositor = OpenVR.Compositor;

            if (compositor != null)
            {
                var handles  = new Texture[] { front, back, left, right, top, bottom };
                var textures = new Texture_t[6];
                for (int i = 0; i < 6; i++)
                {
                    textures[i].handle      = (handles[i] != null) ? handles[i].GetNativeTexturePtr() : System.IntPtr.Zero;
                    textures[i].eType       = SteamVR.instance.textureType;
                    textures[i].eColorSpace = EColorSpace.Auto;
                }
                var error = compositor.SetSkyboxOverride(textures);
                if (error != EVRCompositorError.None)
                {
                    Debug.LogError("<b>[SteamVR_Standalone]</b> Failed to set skybox override with error: " + error);
                    if (error == EVRCompositorError.TextureIsOnWrongDevice)
                    {
                        Debug.Log("<b>[SteamVR_Standalone]</b> Set your graphics driver to use the same video card as the headset is plugged into for Unity.");
                    }
                    else if (error == EVRCompositorError.TextureUsesUnsupportedFormat)
                    {
                        Debug.Log("<b>[SteamVR_Standalone]</b> Ensure skybox textures are not compressed and have no mipmaps.");
                    }
                }
            }
        }
Esempio n. 2
0
	static public void SetOverride(
		Texture front = null,
		Texture back = null,
		Texture left = null,
		Texture right = null,
		Texture top = null,
		Texture bottom = null )
	{
		var compositor = OpenVR.Compositor;
		if (compositor != null)
		{
			var handles = new Texture[] { front, back, left, right, top, bottom };
			var textures = new Texture_t[6];
			for (int i = 0; i < 6; i++)
			{
				textures[i].handle = (handles[i] != null) ? handles[i].GetNativeTexturePtr() : System.IntPtr.Zero;
				textures[i].eType = SteamVR.instance.graphicsAPI;
				textures[i].eColorSpace = EColorSpace.Auto;
			}
			var error = compositor.SetSkyboxOverride(textures);
			if (error != EVRCompositorError.None)
			{
				Debug.LogError("Failed to set skybox override with error: " + error);
				if (error == EVRCompositorError.TextureIsOnWrongDevice)
					Debug.Log("Set your graphics driver to use the same video card as the headset is plugged into for Unity.");
				else if (error == EVRCompositorError.TextureUsesUnsupportedFormat)
					Debug.Log("Ensure skybox textures are not compressed and have no mipmaps.");
			}
		}
	}
Esempio n. 3
0
        public EyeTextures RenderToTextures(Matrix4 leftViewProj, Matrix4 rightViewProj, Vector3 leftEyePos, Vector3 rightEyePos, params IVRDrawable[] drawables)
        {
            // left eye
            GL.Enable(EnableCap.Multisample);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, leftEyeFrameBuffer.RenderFrameBufferID);
            GL.Viewport(0, 0, renderWidth, renderHeight);
            RenderEye(leftViewProj, leftEyePos, drawables);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            GL.Disable(EnableCap.Multisample);

            GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, leftEyeFrameBuffer.RenderFrameBufferID);
            GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, leftEyeFrameBuffer.ResolveFrameBufferID);
            GL.BlitFramebuffer(0, 0, renderWidth, renderHeight, 0, 0, renderWidth, renderHeight, ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Linear);

            GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, 0);
            GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, 0);

            // right eye
            GL.Enable(EnableCap.Multisample);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, rightEyeFrameBuffer.RenderFrameBufferID);
            GL.Viewport(0, 0, renderWidth, renderHeight);
            RenderEye(rightViewProj, rightEyePos, drawables);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            GL.Disable(EnableCap.Multisample);

            GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, rightEyeFrameBuffer.RenderFrameBufferID);
            GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, rightEyeFrameBuffer.ResolveFrameBufferID);
            GL.BlitFramebuffer(0, 0, renderWidth, renderHeight, 0, 0, renderWidth, renderHeight, ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Linear);

            GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, 0);
            GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, 0);

            // convert opengl textures to openvr textures  
            Texture_t leftEyeTexture = new Texture_t { handle = new IntPtr(leftEyeFrameBuffer.ResolveFrameBufferID), eType = EGraphicsAPIConvention.API_OpenGL, eColorSpace = EColorSpace.Gamma };
            Texture_t rightEyeTexture = new Texture_t { handle = new IntPtr(rightEyeFrameBuffer.ResolveFrameBufferID), eType = EGraphicsAPIConvention.API_OpenGL, eColorSpace = EColorSpace.Gamma };

            return new EyeTextures(leftEyeTexture, rightEyeTexture);
        }
Esempio n. 4
0
	public override EVRCompositorError Submit(EVREye eEye,ref Texture_t pTexture,ref VRTextureBounds_t pBounds,EVRSubmitFlags nSubmitFlags)
	{
		CheckIfUsable();
		EVRCompositorError result = VRNativeEntrypoints.VR_IVRCompositor_Submit(m_pVRCompositor,eEye,ref pTexture,ref pBounds,nSubmitFlags);
		return result;
	}
        // Corourtine to handle all the steps across loading boundaries.
        IEnumerator LoadLevel()
        {
            // Optionally rotate loading screen transform around the camera into view.
            // We assume here that the loading screen is already facing toward the origin,
            // and that the progress bar transform (if any) is a child and will follow along.
            if (loadingScreen != null && loadingScreenDistance > 0.0f)
            {
                Transform hmd = this.transform;
                if (Camera.main != null)
                {
                    hmd = Camera.main.transform;
                }

                Quaternion rot = Quaternion.Euler(0.0f, hmd.eulerAngles.y, 0.0f);
                Vector3    pos = hmd.position + (rot * new Vector3(0.0f, 0.0f, loadingScreenDistance));

                var t = loadingScreenTransform != null ? loadingScreenTransform : transform;
                t.position = pos;
                t.rotation = rot;
            }

            _active = this;

            SteamVR_Events.Loading.Send(true);

            // Calculate rate for fading in loading screen and progress bar.
            if (loadingScreenFadeInTime > 0.0f)
            {
                fadeRate = 1.0f / loadingScreenFadeInTime;
            }
            else
            {
                alpha = 1.0f;
            }

            var overlay = OpenVR.Overlay;

            // Optionally create our loading screen overlay.
            if (loadingScreen != null && overlay != null)
            {
                loadingScreenOverlayHandle = GetOverlayHandle("loadingScreen", loadingScreenTransform != null ? loadingScreenTransform : transform, loadingScreenWidthInMeters);
                if (loadingScreenOverlayHandle != OpenVR.k_ulOverlayHandleInvalid)
                {
                    var texture = new Texture_t();
                    texture.handle      = loadingScreen.GetNativeTexturePtr();
                    texture.eType       = SteamVR.instance.textureType;
                    texture.eColorSpace = EColorSpace.Auto;
                    overlay.SetOverlayTexture(loadingScreenOverlayHandle, ref texture);
                }
            }

            bool fadedForeground = false;

            // Fade out to compositor
            SteamVR_Events.LoadingFadeOut.Send(fadeOutTime);

            // Optionally set a skybox to use as a backdrop in the compositor.
            var compositor = OpenVR.Compositor;

            if (compositor != null)
            {
                if (front != null)
                {
                    SteamVR_Skybox.SetOverride(front, back, left, right, top, bottom);

                    // Explicitly fade to the compositor since loading will cause us to stop rendering.
                    compositor.FadeGrid(fadeOutTime, true);
                    yield return(new WaitForSeconds(fadeOutTime));
                }
                else if (backgroundColor != Color.clear)
                {
                    // Otherwise, use the specified background color.
                    if (showGrid)
                    {
                        // Set compositor background color immediately, and start fading to it.
                        compositor.FadeToColor(0.0f, backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a, true);
                        compositor.FadeGrid(fadeOutTime, true);
                        yield return(new WaitForSeconds(fadeOutTime));
                    }
                    else
                    {
                        // Fade the foreground color in (which will blend on top of the scene), and then cut to the compositor.
                        compositor.FadeToColor(fadeOutTime, backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a, false);
                        yield return(new WaitForSeconds(fadeOutTime + 0.1f));

                        compositor.FadeGrid(0.0f, true);
                        fadedForeground = true;
                    }
                }
            }

            // Now that we're fully faded out, we can stop submitting frames to the compositor.
            SteamVR_Render.pauseRendering = true;

            // Continue waiting for the overlays to fully fade in before continuing.
            while (alpha < 1.0f)
            {
                yield return(null);
            }

            // Keep us from getting destroyed when loading the new level, otherwise this coroutine will get stopped prematurely.
            transform.parent = null;
            DontDestroyOnLoad(gameObject);

            if (!string.IsNullOrEmpty(internalProcessPath))
            {
                Debug.Log("<b>[SteamVR]</b> Launching external application...");
                var applications = OpenVR.Applications;
                if (applications == null)
                {
                    Debug.Log("<b>[SteamVR]</b> Failed to get OpenVR.Applications interface!");
                }
                else
                {
                    var workingDirectory = Directory.GetCurrentDirectory();
                    var fullPath         = Path.Combine(workingDirectory, internalProcessPath);
                    Debug.Log("<b>[SteamVR]</b> LaunchingInternalProcess");
                    Debug.Log("<b>[SteamVR]</b> ExternalAppPath = " + internalProcessPath);
                    Debug.Log("<b>[SteamVR]</b> FullPath = " + fullPath);
                    Debug.Log("<b>[SteamVR]</b> ExternalAppArgs = " + internalProcessArgs);
                    Debug.Log("<b>[SteamVR]</b> WorkingDirectory = " + workingDirectory);
                    var error = applications.LaunchInternalProcess(fullPath, internalProcessArgs, workingDirectory);
                    Debug.Log("<b>[SteamVR]</b> LaunchInternalProcessError: " + error);
#if UNITY_EDITOR
                    EditorApplication.isPlaying = false;
#elif !UNITY_METRO
                    System.Diagnostics.Process.GetCurrentProcess().Kill();
#endif
                }
            }
            else
            {
                var mode = loadAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single;
                if (loadAsync)
                {
                    Application.backgroundLoadingPriority = ThreadPriority.Low;
                    async = SceneManager.LoadSceneAsync(levelName, mode);

                    // Performing this in a while loop instead seems to help smooth things out.
                    //yield return async;
                    while (!async.isDone)
                    {
                        yield return(null);
                    }
                }
                else
                {
                    SceneManager.LoadScene(levelName, mode);
                }
            }

            yield return(null);

            GC.Collect();

            yield return(null);

            Shader.WarmupAllShaders();

            // Optionally wait a short period of time after loading everything back in, but before we start rendering again
            // in order to give everything a change to settle down to avoid any hitching at the start of the new level.
            yield return(new WaitForSeconds(postLoadSettleTime));

            SteamVR_Render.pauseRendering = false;

            // Fade out loading screen.
            if (loadingScreenFadeOutTime > 0.0f)
            {
                fadeRate = -1.0f / loadingScreenFadeOutTime;
            }
            else
            {
                alpha = 0.0f;
            }

            // Fade out to compositor
            SteamVR_Events.LoadingFadeIn.Send(fadeInTime);

            // Refresh compositor reference since loading scenes might have invalidated it.
            compositor = OpenVR.Compositor;
            if (compositor != null)
            {
                // Fade out foreground color if necessary.
                if (fadedForeground)
                {
                    compositor.FadeGrid(0.0f, false);
                    compositor.FadeToColor(fadeInTime, 0.0f, 0.0f, 0.0f, 0.0f, false);
                    yield return(new WaitForSeconds(fadeInTime));
                }
                else
                {
                    // Fade scene back in, and reset skybox once no longer visible.
                    compositor.FadeGrid(fadeInTime, false);
                    yield return(new WaitForSeconds(fadeInTime));

                    if (front != null)
                    {
                        SteamVR_Skybox.ClearOverride();
                    }
                }
            }

            // Finally, stick around long enough for our overlays to fully fade out.
            while (alpha > 0.0f)
            {
                yield return(null);
            }

            if (overlay != null)
            {
                if (progressBarOverlayHandle != OpenVR.k_ulOverlayHandleInvalid)
                {
                    overlay.HideOverlay(progressBarOverlayHandle);
                }
                if (loadingScreenOverlayHandle != OpenVR.k_ulOverlayHandleInvalid)
                {
                    overlay.HideOverlay(loadingScreenOverlayHandle);
                }
            }

            Destroy(gameObject);

            _active = null;

            SteamVR_Events.Loading.Send(false);
        }
        // Updates progress bar.
        void OnGUI()
        {
            if (_active != this)
            {
                return;
            }

            // Optionally create an overlay for our progress bar to use, separate from the loading screen.
            if (progressBarEmpty != null && progressBarFull != null)
            {
                if (progressBarOverlayHandle == OpenVR.k_ulOverlayHandleInvalid)
                {
                    progressBarOverlayHandle = GetOverlayHandle("progressBar", progressBarTransform != null ? progressBarTransform : transform, progressBarWidthInMeters);
                }

                if (progressBarOverlayHandle != OpenVR.k_ulOverlayHandleInvalid)
                {
                    var progress = (async != null) ? async.progress : 0.0f;

                    // Use the full bar size for everything.
                    var w = progressBarFull.width;
                    var h = progressBarFull.height;

                    // Create a separate render texture so we can composite the full image on top of the empty one.
                    if (renderTexture == null)
                    {
                        renderTexture = new RenderTexture(w, h, 0);
                        renderTexture.Create();
                    }

                    var prevActive = RenderTexture.active;
                    RenderTexture.active = renderTexture;

                    if (Event.current.type == EventType.Repaint)
                    {
                        GL.Clear(false, true, Color.clear);
                    }

                    GUILayout.BeginArea(new Rect(0, 0, w, h));

                    GUI.DrawTexture(new Rect(0, 0, w, h), progressBarEmpty);

                    // Reveal the full bar texture based on progress.
                    GUI.DrawTextureWithTexCoords(new Rect(0, 0, progress * w, h), progressBarFull, new Rect(0.0f, 0.0f, progress, 1.0f));

                    GUILayout.EndArea();

                    RenderTexture.active = prevActive;

                    // Texture needs to be set every frame after it is updated since SteamVR makes a copy internally to a shared texture.
                    var overlay = OpenVR.Overlay;
                    if (overlay != null)
                    {
                        var texture = new Texture_t();
                        texture.handle      = renderTexture.GetNativeTexturePtr();
                        texture.eType       = SteamVR.instance.textureType;
                        texture.eColorSpace = EColorSpace.Auto;
                        overlay.SetOverlayTexture(progressBarOverlayHandle, ref texture);
                    }
                }
            }

#if false
            // Draw loading screen and progress bar to 2d companion window as well.
            if (loadingScreen != null)
            {
                var screenAspect  = (float)Screen.width / Screen.height;
                var textureAspect = (float)loadingScreen.width / loadingScreen.height;

                float w, h;
                if (screenAspect < textureAspect)
                {
                    // Clamp horizontally
                    w = Screen.width * 0.9f;
                    h = w / textureAspect;
                }
                else
                {
                    // Clamp vertically
                    h = Screen.height * 0.9f;
                    w = h * textureAspect;
                }

                GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height));

                var x = Screen.width / 2 - w / 2;
                var y = Screen.height / 2 - h / 2;
                GUI.DrawTexture(new Rect(x, y, w, h), loadingScreen);

                GUILayout.EndArea();
            }

            if (renderTexture != null)
            {
                var x = Screen.width / 2 - renderTexture.width / 2;
                var y = Screen.height * 0.9f - renderTexture.height;
                GUI.DrawTexture(new Rect(x, y, renderTexture.width, renderTexture.height), renderTexture);
            }
#endif
        }
    // Updates progress bar.
    void OnGUI()
    {
        if (_active != this)
            return;

        // Optionally create an overlay for our progress bar to use, separate from the loading screen.
        if (progressBarEmpty != null && progressBarFull != null)
        {
            if (progressBarOverlayHandle == OpenVR.k_ulOverlayHandleInvalid)
                progressBarOverlayHandle = GetOverlayHandle("progressBar", progressBarTransform != null ? progressBarTransform : transform, progressBarWidthInMeters);

            if (progressBarOverlayHandle != OpenVR.k_ulOverlayHandleInvalid)
            {
                var progress = (async != null) ? async.progress : 0.0f;

                // Use the full bar size for everything.
                var w = progressBarFull.width;
                var h = progressBarFull.height;

                // Create a separate render texture so we can composite the full image on top of the empty one.
                if (renderTexture == null)
                {
                    renderTexture = new RenderTexture(w, h, 0);
                    renderTexture.Create();
                }

                var prevActive = RenderTexture.active;
                RenderTexture.active = renderTexture;

                if (Event.current.type == EventType.Repaint)
                    GL.Clear(false, true, Color.clear);

                GUILayout.BeginArea(new Rect(0, 0, w, h));

                GUI.DrawTexture(new Rect(0, 0, w, h), progressBarEmpty);

                // Reveal the full bar texture based on progress.
                GUI.DrawTextureWithTexCoords(new Rect(0, 0, progress * w, h), progressBarFull, new Rect(0.0f, 0.0f, progress, 1.0f));

                GUILayout.EndArea();

                RenderTexture.active = prevActive;

                // Texture needs to be set every frame after it is updated since SteamVR makes a copy internally to a shared texture.
                var overlay = OpenVR.Overlay;
                if (overlay != null)
                {
                    var texture = new Texture_t();
                    texture.handle = renderTexture.GetNativeTexturePtr();
                    texture.eType = SteamVR.instance.graphicsAPI;
                    texture.eColorSpace = EColorSpace.Auto;
                    overlay.SetOverlayTexture(progressBarOverlayHandle, ref texture);
                }
            }
        }

        #if false
        // Draw loading screen and progress bar to 2d companion window as well.
        if (loadingScreen != null)
        {
            var screenAspect = (float)Screen.width / Screen.height;
            var textureAspect = (float)loadingScreen.width / loadingScreen.height;

            float w, h;
            if (screenAspect < textureAspect)
            {
                // Clamp horizontally
                w = Screen.width * 0.9f;
                h = w / textureAspect;
            }
            else
            {
                // Clamp vertically
                h = Screen.height * 0.9f;
                w = h * textureAspect;
            }

            GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height));

            var x = Screen.width / 2 - w / 2;
            var y = Screen.height / 2 - h / 2;
            GUI.DrawTexture(new Rect(x, y, w, h), loadingScreen);

            GUILayout.EndArea();
        }

        if (renderTexture != null)
        {
            var x = Screen.width / 2 - renderTexture.width / 2;
            var y = Screen.height * 0.9f - renderTexture.height;
            GUI.DrawTexture(new Rect(x, y, renderTexture.width, renderTexture.height), renderTexture);
        }
        #endif
    }
Esempio n. 8
0
	internal static extern EVRCompositorError VR_IVRCompositor_Submit(IntPtr instancePtr, EVREye eEye, ref Texture_t pTexture, ref VRTextureBounds_t pBounds, EVRSubmitFlags nSubmitFlags);
Esempio n. 9
0
 public EVRCompositorError SetSkyboxOverride(Texture_t[] pTextures)
 {
     return this.FnTable.SetSkyboxOverride(pTextures, (uint)pTextures.Length);
 }
Esempio n. 10
0
	public EVROverlayError SetOverlayTexture(ulong ulOverlayHandle,ref Texture_t pTexture)
	{
		EVROverlayError result = FnTable.SetOverlayTexture(ulOverlayHandle,ref pTexture);
		return result;
	}
Esempio n. 11
0
 public EVROverlayError SetOverlayTexture(ulong ulOverlayHandle, ref Texture_t pTexture)
 {
     return(this.FnTable.SetOverlayTexture(ulOverlayHandle, ref pTexture));
 }
Esempio n. 12
0
	public EVRCompositorError Submit(EVREye eEye,ref Texture_t pTexture,ref VRTextureBounds_t pBounds,EVRSubmitFlags nSubmitFlags)
	{
		EVRCompositorError result = FnTable.Submit(eEye,ref pTexture,ref pBounds,nSubmitFlags);
		return result;
	}
Esempio n. 13
0
	public EVRCompositorError SetSkyboxOverride(Texture_t [] pTextures)
	{
		EVRCompositorError result = FnTable.SetSkyboxOverride(pTextures,(uint) pTextures.Length);
		return result;
	}
Esempio n. 14
0
	// Corourtine to handle all the steps across loading boundaries.
	IEnumerator LoadLevel()
	{
		var vr = SteamVR.instance;

		// Optionally rotate loading screen transform around the camera into view.
		// We assume here that the loading screen is already facing toward the origin,
		// and that the progress bar transform (if any) is a child and will follow along.
		if (loadingScreen != null && loadingScreenDistance > 0.0f)
		{
			// Wait until we have tracking.
			var hmd = SteamVR_Controller.Input((int)OpenVR.k_unTrackedDeviceIndex_Hmd);
			while (!hmd.hasTracking)
				yield return null;

			var tloading = hmd.transform;
			tloading.rot = Quaternion.Euler(0.0f, tloading.rot.eulerAngles.y, 0.0f);
			tloading.pos += tloading.rot * new Vector3(0.0f, 0.0f, loadingScreenDistance);

			var t = loadingScreenTransform != null ? loadingScreenTransform : transform;
			t.position = tloading.pos;
			t.rotation = tloading.rot;
		}

		_active = this;

		SteamVR_Utils.Event.Send("loading", true);

		// Calculate rate for fading in loading screen and progress bar.
		if (loadingScreenFadeInTime > 0.0f)
		{
			fadeRate = 1.0f / loadingScreenFadeInTime;
		}
		else
		{
			alpha = 1.0f;
		}

		// Optionally create our loading screen overlay.
		if (loadingScreen != null)
		{
			loadingScreenOverlayHandle = GetOverlayHandle("loadingScreen", loadingScreenTransform != null ? loadingScreenTransform : transform, loadingScreenWidthInMeters);
			if (loadingScreenOverlayHandle != OpenVR.k_ulOverlayHandleInvalid)
			{
				vr.overlay.SetHighQualityOverlay(loadingScreenOverlayHandle);
				vr.overlay.SetOverlayFlag(loadingScreenOverlayHandle, VROverlayFlags.Curved, false);
				vr.overlay.SetOverlayFlag(loadingScreenOverlayHandle, VROverlayFlags.RGSS4X, true);

				var texture = new Texture_t();
				texture.handle = loadingScreen.GetNativeTexturePtr();
				texture.eType = vr.graphicsAPI;
				texture.eColorSpace = EColorSpace.Auto;
				vr.overlay.SetOverlayTexture(loadingScreenOverlayHandle, ref texture);
			}
		}

		bool fadedForeground = false;

		// Optionally set a skybox to use as a backdrop in the compositor.
		if (front != null)
		{
			SteamVR_Skybox.SetOverride(front, back, left, right, top, bottom);

			// Explicitly fade to the compositor since loading will cause us to stop rendering.
			vr.compositor.FadeGrid(fadeOutTime, true);
			yield return new WaitForSeconds(fadeOutTime);
		}
		else if (backgroundColor != Color.clear)
		{
			// Otherwise, use the specified background color.
			if (showGrid)
			{
				// Set compositor background color immediately, and start fading to it.
				vr.compositor.FadeToColor(0.0f, backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a, true);
				vr.compositor.FadeGrid(fadeOutTime, true);
				yield return new WaitForSeconds(fadeOutTime);
			}
			else
			{
				// Fade the foreground color in (which will blend on top of the scene), and then cut to the compositor.
				vr.compositor.FadeToColor(fadeOutTime, backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a, false);
				yield return new WaitForSeconds(fadeOutTime + 0.1f);
				vr.compositor.FadeGrid(0.0f, true);
				fadedForeground = true;
			}
		}

		// Now that we're fully faded out, we can stop submitting frames to the compositor.
		SteamVR_Render.pauseRendering = true;

		// Continue waiting for the overlays to fully fade in before continuing.
		while (alpha < 1.0f)
			yield return null;

		// Keep us from getting destroyed when loading the new level, otherwise this coroutine will get stopped prematurely.
		transform.parent = null;
		DontDestroyOnLoad(gameObject);

		// Loading asynchronously so we can update the progress bar above.
		async = loadAdditive ? Application.LoadLevelAdditiveAsync(levelName) : Application.LoadLevelAsync(levelName);
		yield return async;

		System.GC.Collect();

		// Optionally wait a short period of time after loading everything back in, but before we start rendering again
		// in order to give everything a change to settle down to avoid any hitching at the start of the new level.
		yield return new WaitForSeconds(postLoadSettleTime);

		SteamVR_Render.pauseRendering = false;

		// Fade out loading screen.
		if (loadingScreenFadeOutTime > 0.0f)
		{
			fadeRate = -1.0f / loadingScreenFadeOutTime;
		}
		else
		{
			alpha = 0.0f;
		}

		// Fade out foreground color if necessary.
		if (fadedForeground)
		{
			vr.compositor.FadeGrid(0.0f, false);
			vr.compositor.FadeToColor(fadeInTime, 0.0f, 0.0f, 0.0f, 0.0f, false);
			yield return new WaitForSeconds(fadeInTime);
		}
		else
		{
			// Fade scene back in, and reset skybox once no longer visible.
			vr.compositor.FadeGrid(fadeInTime, false);
			yield return new WaitForSeconds(fadeInTime);

			if (front != null)
			{
				SteamVR_Skybox.ClearOverride();
			}
		}

		// Finally, stick around long enough for our overlays to fully fade out.
		while (alpha > 0.0f)
			yield return null;

		Destroy(gameObject);

		_active = null;

		SteamVR_Utils.Event.Send("loading", false);
	}
Esempio n. 15
0
	public void UpdateOverlay()
	{
		var overlay = OpenVR.Overlay;
		if (overlay == null)
			return;

		if (texture != null)
		{
			var error = overlay.ShowOverlay(handle);
			if (error == EVROverlayError.InvalidHandle || error == EVROverlayError.UnknownOverlay)
			{
				if (overlay.FindOverlay(key, ref handle) != EVROverlayError.None)
					return;
			}

			var tex = new Texture_t();
			tex.handle = texture.GetNativeTexturePtr();
			tex.eType = SteamVR.instance.graphicsAPI;
			tex.eColorSpace = EColorSpace.Auto;
            overlay.SetOverlayTexture(handle, ref tex);

			overlay.SetOverlayAlpha(handle, alpha);
			overlay.SetOverlayWidthInMeters(handle, scale);
			overlay.SetOverlayAutoCurveDistanceRangeInMeters(handle, curvedRange.x, curvedRange.y);

			var textureBounds = new VRTextureBounds_t();
			textureBounds.uMin = (0 + uvOffset.x) * uvOffset.z;
			textureBounds.vMin = (1 + uvOffset.y) * uvOffset.w;
			textureBounds.uMax = (1 + uvOffset.x) * uvOffset.z;
			textureBounds.vMax = (0 + uvOffset.y) * uvOffset.w;
			overlay.SetOverlayTextureBounds(handle, ref textureBounds);

			var vecMouseScale = new HmdVector2_t();
			vecMouseScale.v0 = mouseScale.x;
			vecMouseScale.v1 = mouseScale.y;
			overlay.SetOverlayMouseScale(handle, ref vecMouseScale);

			var vrcam = SteamVR_Render.Top();
			if (vrcam != null && vrcam.origin != null)
			{
				var offset = new SteamVR_Utils.RigidTransform(vrcam.origin, transform);
				offset.pos.x /= vrcam.origin.localScale.x;
				offset.pos.y /= vrcam.origin.localScale.y;
				offset.pos.z /= vrcam.origin.localScale.z;

				offset.pos.z += distance;

				var t = offset.ToHmdMatrix34();
				overlay.SetOverlayTransformAbsolute(handle, SteamVR_Render.instance.trackingSpace, ref t);
			}

			overlay.SetOverlayInputMethod(handle, inputMethod);

			if (curved || antialias)
				highquality = true;

			if (highquality)
			{
				overlay.SetHighQualityOverlay(handle);
				overlay.SetOverlayFlag(handle, VROverlayFlags.Curved, curved);
				overlay.SetOverlayFlag(handle, VROverlayFlags.RGSS4X, antialias);
			}
			else if (overlay.GetHighQualityOverlay() == handle)
			{
				overlay.SetHighQualityOverlay(OpenVR.k_ulOverlayHandleInvalid);
			}
		}
		else
		{
			overlay.HideOverlay(handle);
		}
	}
Esempio n. 16
0
 public EVRCompositorError Submit(EVREye eEye, ref Texture_t pTexture, ref VRTextureBounds_t pBounds, EVRSubmitFlags nSubmitFlags)
 {
     return this.FnTable.Submit(eEye, ref pTexture, ref pBounds, nSubmitFlags);
 }
Esempio n. 17
0
	public override EVRCompositorError SetSkyboxOverride(Texture_t [] pTextures)
	{
		CheckIfUsable();
		EVRCompositorError result = VRNativeEntrypoints.VR_IVRCompositor_SetSkyboxOverride(m_pVRCompositor,pTextures,(uint) pTextures.Length);
		return result;
	}
Esempio n. 18
0
	public abstract EVRCompositorError Submit(EVREye eEye,ref Texture_t pTexture,ref VRTextureBounds_t pBounds,EVRSubmitFlags nSubmitFlags);
Esempio n. 19
0
	public override EVROverlayError SetOverlayTexture(ulong ulOverlayHandle,ref Texture_t pTexture)
	{
		CheckIfUsable();
		EVROverlayError result = VRNativeEntrypoints.VR_IVROverlay_SetOverlayTexture(m_pVROverlay,ulOverlayHandle,ref pTexture);
		return result;
	}
Esempio n. 20
0
	public abstract EVROverlayError SetOverlayTexture(ulong ulOverlayHandle,ref Texture_t pTexture);
Esempio n. 21
0
	internal static extern EVROverlayError VR_IVROverlay_SetOverlayTexture(IntPtr instancePtr, ulong ulOverlayHandle, ref Texture_t pTexture);
Esempio n. 22
0
 public EyeTextures(Texture_t left, Texture_t right)
 {
     LeftEye = left;
     RightEye = right;
 }
Esempio n. 23
0
	public abstract EVRCompositorError SetSkyboxOverride(Texture_t [] pTextures);
Esempio n. 24
0
 public EVROverlayError MoveGamepadFocusToNeighbor(EOverlayDirection eDirection, ulong ulFrom) => default;                                                                                                                                                                                       // 0x00000001811DE8B0-0x00000001811DE8E0
 public EVROverlayError SetOverlayTexture(ulong ulOverlayHandle, ref Texture_t pTexture) => default;                                                                                                                                                                                             // 0x00000001811DEEA0-0x00000001811DEED0
    // Corourtine to handle all the steps across loading boundaries.
    IEnumerator LoadLevel()
    {
        // Optionally rotate loading screen transform around the camera into view.
        // We assume here that the loading screen is already facing toward the origin,
        // and that the progress bar transform (if any) is a child and will follow along.
        if (loadingScreen != null && loadingScreenDistance > 0.0f)
        {
            // Wait until we have tracking.
            var hmd = SteamVR_Controller.Input((int)OpenVR.k_unTrackedDeviceIndex_Hmd);
            while (!hmd.hasTracking)
                yield return null;

            var tloading = hmd.transform;
            tloading.rot = Quaternion.Euler(0.0f, tloading.rot.eulerAngles.y, 0.0f);
            tloading.pos += tloading.rot * new Vector3(0.0f, 0.0f, loadingScreenDistance);

            var t = loadingScreenTransform != null ? loadingScreenTransform : transform;
            t.position = tloading.pos;
            t.rotation = tloading.rot;
        }

        _active = this;

        SteamVR_Utils.Event.Send("loading", true);

        // Calculate rate for fading in loading screen and progress bar.
        if (loadingScreenFadeInTime > 0.0f)
        {
            fadeRate = 1.0f / loadingScreenFadeInTime;
        }
        else
        {
            alpha = 1.0f;
        }

        var overlay = OpenVR.Overlay;

        // Optionally create our loading screen overlay.
        if (loadingScreen != null && overlay != null)
        {
            loadingScreenOverlayHandle = GetOverlayHandle("loadingScreen", loadingScreenTransform != null ? loadingScreenTransform : transform, loadingScreenWidthInMeters);
            if (loadingScreenOverlayHandle != OpenVR.k_ulOverlayHandleInvalid)
            {
                var texture = new Texture_t();
                texture.handle = loadingScreen.GetNativeTexturePtr();
                texture.eType = SteamVR.instance.graphicsAPI;
                texture.eColorSpace = EColorSpace.Auto;
                overlay.SetOverlayTexture(loadingScreenOverlayHandle, ref texture);
            }
        }

        bool fadedForeground = false;

        // Fade out to compositor
        SteamVR_Utils.Event.Send("loading_fade_out", fadeOutTime);

        // Optionally set a skybox to use as a backdrop in the compositor.
        var compositor = OpenVR.Compositor;
        if (compositor != null)
        {
            if (front != null)
            {
                SteamVR_Skybox.SetOverride(front, back, left, right, top, bottom);

                // Explicitly fade to the compositor since loading will cause us to stop rendering.
                compositor.FadeGrid(fadeOutTime, true);
                yield return new WaitForSeconds(fadeOutTime);
            }
            else if (backgroundColor != Color.clear)
            {
                // Otherwise, use the specified background color.
                if (showGrid)
                {
                    // Set compositor background color immediately, and start fading to it.
                    compositor.FadeToColor(0.0f, backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a, true);
                    compositor.FadeGrid(fadeOutTime, true);
                    yield return new WaitForSeconds(fadeOutTime);
                }
                else
                {
                    // Fade the foreground color in (which will blend on top of the scene), and then cut to the compositor.
                    compositor.FadeToColor(fadeOutTime, backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a, false);
                    yield return new WaitForSeconds(fadeOutTime + 0.1f);
                    compositor.FadeGrid(0.0f, true);
                    fadedForeground = true;
                }
            }
        }

        // Now that we're fully faded out, we can stop submitting frames to the compositor.
        SteamVR_Render.pauseRendering = true;

        // Continue waiting for the overlays to fully fade in before continuing.
        while (alpha < 1.0f)
            yield return null;

        // Keep us from getting destroyed when loading the new level, otherwise this coroutine will get stopped prematurely.
        transform.parent = null;
        DontDestroyOnLoad(gameObject);

        if (loadExternalApp)
        {
            Debug.Log("Launching external application...");
            var applications = OpenVR.Applications;
            if (applications == null)
            {
                Debug.Log("Failed to get OpenVR.Applications interface!");
            }
            else
            {
                var workingDirectory = Directory.GetCurrentDirectory();
                var fullPath = Path.Combine( workingDirectory, externalAppPath );
                Debug.Log("LaunchingInternalProcess");
                Debug.Log("ExternalAppPath = " + externalAppPath);
                Debug.Log("FullPath = " + fullPath);
                Debug.Log("ExternalAppArgs = " + externalAppArgs);
                Debug.Log("WorkingDirectory = " + workingDirectory);
                var error = applications.LaunchInternalProcess(fullPath, externalAppArgs, workingDirectory);
                Debug.Log("LaunchInternalProcessError: " + error);
        #if UNITY_EDITOR
                UnityEditor.EditorApplication.isPlaying = false;
        #else
                Process.GetCurrentProcess().Kill();
        #endif
            }
        }
        else
        {
        #if !(UNITY_5_2 || UNITY_5_1 || UNITY_5_0)
            var mode = loadAdditive ? UnityEngine.SceneManagement.LoadSceneMode.Additive : UnityEngine.SceneManagement.LoadSceneMode.Single;
            if (loadAsync)
            {
                Application.backgroundLoadingPriority = ThreadPriority.Low;
                async = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(levelName, mode);

                // Performing this in a while loop instead seems to help smooth things out.
                //yield return async;
                while (!async.isDone)
                {
                    yield return null;
                }
            }
            else
            {
                UnityEngine.SceneManagement.SceneManager.LoadScene(levelName, mode);
            }
        #else
            if (loadAsync)
            {
                async = loadAdditive ? Application.LoadLevelAdditiveAsync(levelName) : Application.LoadLevelAsync(levelName);

                // Performing this in a while loop instead seems to help smooth things out.
                //yield return async;
                while (!async.isDone)
                {
                    yield return null;
                }
            }
            else if (loadAdditive)
            {
                Application.LoadLevelAdditive(levelName);
            }
            else
            {
                Application.LoadLevel(levelName);
            }
        #endif
        }

        yield return null;

        System.GC.Collect();

        yield return null;

        Shader.WarmupAllShaders();

        // Optionally wait a short period of time after loading everything back in, but before we start rendering again
        // in order to give everything a change to settle down to avoid any hitching at the start of the new level.
        yield return new WaitForSeconds(postLoadSettleTime);

        SteamVR_Render.pauseRendering = false;

        // Fade out loading screen.
        if (loadingScreenFadeOutTime > 0.0f)
        {
            fadeRate = -1.0f / loadingScreenFadeOutTime;
        }
        else
        {
            alpha = 0.0f;
        }

        // Fade out to compositor
        SteamVR_Utils.Event.Send("loading_fade_in", fadeInTime);

        if (compositor != null)
        {
            // Fade out foreground color if necessary.
            if (fadedForeground)
            {
                compositor.FadeGrid(0.0f, false);
                compositor.FadeToColor(fadeInTime, 0.0f, 0.0f, 0.0f, 0.0f, false);
                yield return new WaitForSeconds(fadeInTime);
            }
            else
            {
                // Fade scene back in, and reset skybox once no longer visible.
                compositor.FadeGrid(fadeInTime, false);
                yield return new WaitForSeconds(fadeInTime);

                if (front != null)
                {
                    SteamVR_Skybox.ClearOverride();
                }
            }
        }

        // Finally, stick around long enough for our overlays to fully fade out.
        while (alpha > 0.0f)
            yield return null;

        if (overlay != null)
        {
            if (progressBarOverlayHandle != OpenVR.k_ulOverlayHandleInvalid)
                overlay.HideOverlay(progressBarOverlayHandle);
            if (loadingScreenOverlayHandle != OpenVR.k_ulOverlayHandleInvalid)
                overlay.HideOverlay(loadingScreenOverlayHandle);
        }

        Destroy(gameObject);

        _active = null;

        SteamVR_Utils.Event.Send("loading", false);
    }
Esempio n. 26
0
 // Token: 0x06001F58 RID: 8024 RVA: 0x0009D5C7 File Offset: 0x0009B7C7
 public EVRCompositorError Submit(EVREye eEye, ref Texture_t pTexture, ref VRTextureBounds_t pBounds, EVRSubmitFlags nSubmitFlags)
 {
     return(this.FnTable.Submit(eEye, ref pTexture, ref pBounds, nSubmitFlags));
 }
Esempio n. 27
0
        public void UpdateOverlay()
        {
            var overlay = OpenVR.Overlay;

            if (overlay == null)
            {
                return;
            }

            if (texture != null)
            {
                var error = overlay.ShowOverlay(handle);
                if (error == EVROverlayError.InvalidHandle || error == EVROverlayError.UnknownOverlay)
                {
                    if (overlay.FindOverlay(key, ref handle) != EVROverlayError.None)
                    {
                        return;
                    }
                }

                var tex = new Texture_t();
                tex.handle      = texture.GetNativeTexturePtr();
                tex.eType       = SteamVR.instance.textureType;
                tex.eColorSpace = EColorSpace.Auto;
                overlay.SetOverlayTexture(handle, ref tex);

                overlay.SetOverlayAlpha(handle, alpha);
                overlay.SetOverlayWidthInMeters(handle, scale);
                overlay.SetOverlayAutoCurveDistanceRangeInMeters(handle, curvedRange.x, curvedRange.y);

                var textureBounds = new VRTextureBounds_t();
                textureBounds.uMin = (0 + uvOffset.x) * uvOffset.z;
                textureBounds.vMin = (1 + uvOffset.y) * uvOffset.w;
                textureBounds.uMax = (1 + uvOffset.x) * uvOffset.z;
                textureBounds.vMax = (0 + uvOffset.y) * uvOffset.w;
                overlay.SetOverlayTextureBounds(handle, ref textureBounds);

                var vecMouseScale = new HmdVector2_t();
                vecMouseScale.v0 = mouseScale.x;
                vecMouseScale.v1 = mouseScale.y;
                overlay.SetOverlayMouseScale(handle, ref vecMouseScale);

                var vrcam = SteamVR_Render.Top();
                if (vrcam != null && vrcam.origin != null)
                {
                    var offset = new SteamVR_Utils.RigidTransform(vrcam.origin, transform);
                    offset.pos.x /= vrcam.origin.localScale.x;
                    offset.pos.y /= vrcam.origin.localScale.y;
                    offset.pos.z /= vrcam.origin.localScale.z;

                    offset.pos.z += distance;

                    var t = offset.ToHmdMatrix34();
                    overlay.SetOverlayTransformAbsolute(handle, SteamVR.settings.trackingSpace, ref t);
                }

                overlay.SetOverlayInputMethod(handle, inputMethod);

                if (curved || antialias)
                {
                    highquality = true;
                }

                if (highquality)
                {
                    overlay.SetHighQualityOverlay(handle);
                    overlay.SetOverlayFlag(handle, VROverlayFlags.Curved, curved);
                    overlay.SetOverlayFlag(handle, VROverlayFlags.RGSS4X, antialias);
                }
                else if (overlay.GetHighQualityOverlay() == handle)
                {
                    overlay.SetHighQualityOverlay(OpenVR.k_ulOverlayHandleInvalid);
                }
            }
            else
            {
                overlay.HideOverlay(handle);
            }
        }
Esempio n. 28
0
 public EVRCompositorError GetLastPoseForTrackedDeviceIndex(uint unDeviceIndex, ref TrackedDevicePose_t pOutputPose, ref TrackedDevicePose_t pOutputGamePose) => default; // 0x00000001811DD660-0x00000001811DD690
 public EVRCompositorError Submit(EVREye eEye, ref Texture_t pTexture, ref VRTextureBounds_t pBounds, EVRSubmitFlags nSubmitFlags) => default;                            // 0x00000001811DD9A0-0x00000001811DD9D0