diff --git a/Assets/CameraFade.cs b/Assets/CameraFade.cs index 739495e..f2bcf2f 100755 --- a/Assets/CameraFade.cs +++ b/Assets/CameraFade.cs @@ -1,12 +1,21 @@ using UnityEngine; using System.Collections; +using Valve.VR; public class CameraFade : MonoBehaviour { + public RenderTexture BlendTextureLeft; + public RenderTexture BlendTextureRight; + private float alpha = 0.0F; + static Material blitMaterial; + // Use this for initialization void Start () { + if (!blitMaterial) { + blitMaterial = new Material(Shader.Find("Custom/TransparencyBitch")); + } } // Update is called once per frame @@ -16,6 +25,12 @@ public class CameraFade : MonoBehaviour { } void OnRenderImage(RenderTexture src, RenderTexture dest) { - + blitMaterial.SetFloat("_Ratio", alpha); + if (SteamVR_Render.eye == EVREye.Eye_Left) { + blitMaterial.SetTexture("_BlendTex", BlendTextureLeft); + } else { + blitMaterial.SetTexture("_BlendTex", BlendTextureRight); + } + Graphics.Blit(src, dest, blitMaterial); } } diff --git a/Assets/LeftEyeRenderTexture.renderTexture b/Assets/LeftEyeRenderTexture.renderTexture new file mode 100755 index 0000000..08af3ba Binary files /dev/null and b/Assets/LeftEyeRenderTexture.renderTexture differ diff --git a/Assets/LeftEyeRenderTexture.renderTexture.meta b/Assets/LeftEyeRenderTexture.renderTexture.meta new file mode 100755 index 0000000..358bee2 --- /dev/null +++ b/Assets/LeftEyeRenderTexture.renderTexture.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 15863de937343d84e9dc21fc4dea787c +timeCreated: 1463604762 +licenseType: Free +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RightEyeRenderTexture.renderTexture b/Assets/RightEyeRenderTexture.renderTexture new file mode 100755 index 0000000..ab93276 Binary files /dev/null and b/Assets/RightEyeRenderTexture.renderTexture differ diff --git a/Assets/RightEyeRenderTexture.renderTexture.meta b/Assets/RightEyeRenderTexture.renderTexture.meta new file mode 100755 index 0000000..c3ec74b --- /dev/null +++ b/Assets/RightEyeRenderTexture.renderTexture.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bb6fbe54b99bc0e46bc79e09c5fa111d +timeCreated: 1463605078 +licenseType: Free +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SteamVR/Editor/SteamVR_Editor.cs b/Assets/SteamVR/Editor/SteamVR_Editor.cs index f347231..79cd0ae 100755 --- a/Assets/SteamVR/Editor/SteamVR_Editor.cs +++ b/Assets/SteamVR/Editor/SteamVR_Editor.cs @@ -14,7 +14,7 @@ public class SteamVR_Editor : Editor int bannerHeight = 150; Texture logo; - SerializedProperty script, wireframe; + SerializedProperty script, wireframe, RightEyeRenderTexture, LeftEyeRenderTexture; string GetResourcePath() { @@ -36,6 +36,9 @@ public class SteamVR_Editor : Editor wireframe = serializedObject.FindProperty("wireframe"); + RightEyeRenderTexture = serializedObject.FindProperty("RightEyeRenderTexture"); + LeftEyeRenderTexture = serializedObject.FindProperty("LeftEyeRenderTexture"); + foreach (SteamVR_Camera target in targets) target.ForceLast(); } @@ -105,6 +108,8 @@ public class SteamVR_Editor : Editor EditorGUILayout.PropertyField(script); EditorGUILayout.PropertyField(wireframe); + EditorGUILayout.PropertyField(LeftEyeRenderTexture); + EditorGUILayout.PropertyField(RightEyeRenderTexture); serializedObject.ApplyModifiedProperties(); } diff --git a/Assets/SteamVR/Scripts/SteamVR_Camera.cs b/Assets/SteamVR/Scripts/SteamVR_Camera.cs index 0e8141f..05b03d2 100755 --- a/Assets/SteamVR/Scripts/SteamVR_Camera.cs +++ b/Assets/SteamVR/Scripts/SteamVR_Camera.cs @@ -28,6 +28,8 @@ public class SteamVR_Camera : MonoBehaviour } public bool wireframe = false; + public RenderTexture LeftEyeRenderTexture; + public RenderTexture RightEyeRenderTexture; [SerializeField] private SteamVR_CameraFlip flip; @@ -229,8 +231,8 @@ public class SteamVR_Camera : MonoBehaviour #else if (this != components[components.Length - 1] || flip == null) { - if (flip == null) - flip = gameObject.AddComponent(); + //if (flip == null) + // flip = gameObject.AddComponent(); #endif // Store off values to be restored on new instance values = new Hashtable(); @@ -385,8 +387,8 @@ public class SteamVR_Camera : MonoBehaviour void OnPreRender() { - if (flip) - flip.enabled = (SteamVR_Render.Top() == this && SteamVR.instance.graphicsAPI == EGraphicsAPIConvention.API_DirectX); + //if (flip) + // flip.enabled = (SteamVR_Render.Top() == this && SteamVR.instance.graphicsAPI == EGraphicsAPIConvention.API_DirectX); var headCam = head.GetComponent(); if (headCam != null) @@ -402,44 +404,49 @@ public class SteamVR_Camera : MonoBehaviour GL.wireframe = false; } - void OnRenderImage(RenderTexture src, RenderTexture dest) - { - if (SteamVR_Render.Top() == this) - { - int eventID; - if (SteamVR_Render.eye == EVREye.Eye_Left) - { - // Get gpu started on work early to avoid bubbles at the top of the frame. - SteamVR_Utils.QueueEventOnRenderThread(SteamVR.Unity.k_nRenderEventID_Flush); + void OnRenderImage(RenderTexture src, RenderTexture dest) { + if (LeftEyeRenderTexture == null) { + //if (SteamVR_Render.Top() == this) { + int eventID; + if (SteamVR_Render.eye == EVREye.Eye_Left) { + // Get gpu started on work early to avoid bubbles at the top of the frame. + SteamVR_Utils.QueueEventOnRenderThread(SteamVR.Unity.k_nRenderEventID_Flush); - eventID = SteamVR.Unity.k_nRenderEventID_SubmitL; - } - else - { - eventID = SteamVR.Unity.k_nRenderEventID_SubmitR; - } + eventID = SteamVR.Unity.k_nRenderEventID_SubmitL; + } + else { + eventID = SteamVR.Unity.k_nRenderEventID_SubmitR; + } - // Queue up a call on the render thread to Submit our render target to the compositor. - SteamVR_Utils.QueueEventOnRenderThread(eventID); - } + // Queue up a call on the render thread to Submit our render target to the compositor. + SteamVR_Utils.QueueEventOnRenderThread(eventID); + //} + } else { + if (SteamVR_Render.eye == EVREye.Eye_Right) { + Graphics.Blit(src, RightEyeRenderTexture); + } + else { + Graphics.Blit(src, LeftEyeRenderTexture); + } + } - Graphics.SetRenderTarget(dest); - SteamVR_Camera.blitMaterial.mainTexture = src; + //Graphics.SetRenderTarget(dest); + //SteamVR_Camera.blitMaterial.mainTexture = src; - GL.PushMatrix(); - GL.LoadOrtho(); - SteamVR_Camera.blitMaterial.SetPass(0); - GL.Begin(GL.QUADS); - GL.TexCoord2(0.0f, 0.0f); GL.Vertex3(-1, 1, 0); - GL.TexCoord2(1.0f, 0.0f); GL.Vertex3(1, 1, 0); - GL.TexCoord2(1.0f, 1.0f); GL.Vertex3(1, -1, 0); - GL.TexCoord2(0.0f, 1.0f); GL.Vertex3(-1, -1, 0); - GL.End(); - GL.PopMatrix(); + //GL.PushMatrix(); + //GL.LoadOrtho(); + //SteamVR_Camera.blitMaterial.SetPass(0); + //GL.Begin(GL.QUADS); + //GL.TexCoord2(0.0f, 0.0f); GL.Vertex3(-1, 1, 0); + //GL.TexCoord2(1.0f, 0.0f); GL.Vertex3(1, 1, 0); + //GL.TexCoord2(1.0f, 1.0f); GL.Vertex3(1, -1, 0); + //GL.TexCoord2(0.0f, 1.0f); GL.Vertex3(-1, -1, 0); + //GL.End(); + //GL.PopMatrix(); - Graphics.SetRenderTarget(null); - } + //Graphics.SetRenderTarget(null); + } #endregion diff --git a/Assets/SteamVR/Scripts/SteamVR_PlayArea.cs b/Assets/SteamVR/Scripts/SteamVR_PlayArea.cs index 1165850..550b932 100755 --- a/Assets/SteamVR/Scripts/SteamVR_PlayArea.cs +++ b/Assets/SteamVR/Scripts/SteamVR_PlayArea.cs @@ -261,7 +261,7 @@ public class SteamVR_PlayArea : MonoBehaviour // No need to remain enabled at runtime. // Anyone that wants to change properties at runtime // should call BuildMesh themselves. - //enabled = false; + enabled = false; // If we want the configured bounds of the user, // we need to wait for tracking. diff --git a/Assets/Test.unity b/Assets/Test.unity index a3b5259..a21f798 100755 Binary files a/Assets/Test.unity and b/Assets/Test.unity differ diff --git a/Assets/TransparencyBitch.shader b/Assets/TransparencyBitch.shader new file mode 100755 index 0000000..ba97070 --- /dev/null +++ b/Assets/TransparencyBitch.shader @@ -0,0 +1,47 @@ +Shader "Custom/TransparencyBitch" { + Properties { + _MainTex ("Base (RGB)", 2D) = "white" {} + _BlendTex ("Overlay", 2D) = "white" {} + _Ratio ("Ratio", Float) = 0 + } + + CGINCLUDE + + #include "UnityCG.cginc" + + uniform sampler2D _MainTex; + uniform sampler2D _BlendTex; + uniform float _Ratio; + + struct v2f { + float4 pos : SV_POSITION; + float2 tex : TEXCOORD0; + }; + + v2f vert(appdata_base v) { + v2f o; + o.pos = mul(UNITY_MATRIX_MVP, v.vertex); + o.tex = v.texcoord; + return o; + } + + float4 frag(v2f i) : COLOR { + float4 color = tex2D(_MainTex, i.tex); + float4 color2 = tex2D(_BlendTex, i.tex); + return float4(color.rgb * (1 - _Ratio) + color2.rgb * (_Ratio), 1); + } + + ENDCG + + SubShader { + Pass { + ZTest Always Cull Off ZWrite Off + Fog { Mode Off } + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + ENDCG + } + } +} diff --git a/Assets/TransparencyBitch.shader.meta b/Assets/TransparencyBitch.shader.meta new file mode 100755 index 0000000..5b30b56 --- /dev/null +++ b/Assets/TransparencyBitch.shader.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b34e75cfff6508b4db83d740a420b0e9 +timeCreated: 1463603082 +licenseType: Free +ShaderImporter: + defaultTextures: + - _MainTex: {instanceID: 0} + - _BlendTex: {fileID: 2800000, guid: 6a329c6c386d4994d8eb9a05534ed2fc, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 47e2ce3..20a158c 100755 Binary files a/ProjectSettings/ProjectSettings.asset and b/ProjectSettings/ProjectSettings.asset differ