private void UpdateCommand()
        {
            MaterialCurrent.SetFloat("_ResizeWidth", Screen.width);
            MaterialCurrent.SetFloat("_ResizeHeight", Screen.height);
            MaterialCurrent.SetFloat("_Sharpness", Sharpness);
            MaterialCurrent.SetFloat("_SampleDistance", SampleDistance);

            // --- Fix for deferred stacking
            // Layers with skyboxes or solid color clearflags should alwasy render opaque to avoid
            // alpha testing issues on deferred
            if (Current.clearFlags == CameraClearFlags.Color || Current.clearFlags == CameraClearFlags.Skybox)
            {
                MaterialCurrent.SetOverrideTag("RenderType", "Opaque");
                MaterialCurrent.SetInt("_SrcBlend", (int)BlendMode.One);
                MaterialCurrent.SetInt("_DstBlend", (int)BlendMode.Zero);
                MaterialCurrent.SetInt("_ZWrite", 1);
                MaterialCurrent.renderQueue = -1;
            }
            else
            {
                MaterialCurrent.SetOverrideTag("RenderType", "Transparent");
                MaterialCurrent.SetInt("_SrcBlend", (int)BlendMode.SrcAlpha);
                MaterialCurrent.SetInt("_DstBlend", (int)BlendMode.OneMinusSrcAlpha);
                MaterialCurrent.SetInt("_ZWrite", 0);
                MaterialCurrent.renderQueue = 3000;
            }
        }
Esempio n. 2
0
        protected void UpdateDownsamplerCommandBuffer()
        {
            RtDownsampler.Release();

#if UNITY_2017_2_OR_NEWER
            if (UnityEngine.XR.XRSettings.eyeTextureWidth > 0 && UnityEngine.XR.XRSettings.eyeTextureHeight != 0)
            {
                if (RtDownsampler.width != UnityEngine.XR.XRSettings.eyeTextureWidth * 2 ||
                    RtDownsampler.height != UnityEngine.XR.XRSettings.eyeTextureHeight)
                {
                    RtDownsampler.Release();
                    RtDownsampler.width  = UnityEngine.XR.XRSettings.eyeTextureWidth * 2;
                    RtDownsampler.height = UnityEngine.XR.XRSettings.eyeTextureHeight;
                    RtDownsampler.Create();
                }
            }
#else
            if (UnityEngine.XR.XRSettings.eyeTextureWidth > 0 && UnityEngine.XR.XRSettings.eyeTextureHeight > 0)
            {
                if (RtDownsampler.width != UnityEngine.VR.VRSettings.eyeTextureWidth ||
                    RtDownsampler.height != UnityEngine.VR.VRSettings.eyeTextureHeight)
                {
                    RtDownsampler.Release();
                    RtDownsampler.width  = UnityEngine.VR.VRSettings.eyeTextureWidth;
                    RtDownsampler.height = UnityEngine.VR.VRSettings.eyeTextureHeight;
                    RtDownsampler.Create();
                }
            }
#endif

            // fix for VR black screen
            MaterialCurrent.SetOverrideTag("RenderType", "Opaque");
            MaterialCurrent.SetInt("_SrcBlend", (int)BlendMode.One);
            MaterialCurrent.SetInt("_DstBlend", (int)BlendMode.Zero);
            MaterialCurrent.SetInt("_ZWrite", 1);
            MaterialCurrent.renderQueue = -1;

            MaterialDefault.SetOverrideTag("RenderType", "Opaque");
            MaterialDefault.SetInt("_SrcBlend", (int)BlendMode.One);
            MaterialDefault.SetInt("_DstBlend", (int)BlendMode.Zero);
            MaterialDefault.SetInt("_ZWrite", 1);
            MaterialDefault.renderQueue = -1;

#if UNITY_2017_2_OR_NEWER
            MaterialCurrent.SetFloat("_ResizeWidth", UnityEngine.XR.XRSettings.eyeTextureWidth);
            MaterialCurrent.SetFloat("_ResizeHeight", UnityEngine.XR.XRSettings.eyeTextureHeight);
#else
            MaterialCurrent.SetFloat("_ResizeWidth", UnityEngine.VR.VRSettings.eyeTextureWidth);
            MaterialCurrent.SetFloat("_ResizeHeight", UnityEngine.VR.VRSettings.eyeTextureHeight);
#endif
            MaterialCurrent.SetFloat("_Sharpness", DownsamplerSharpness);
            MaterialCurrent.SetFloat("_SampleDistance", DownsamplerDistance);

            MaterialFXAA.SetVector("_QualitySettings", new Vector3(1.0f, 0.063f, 0.0312f));
            MaterialFXAA.SetVector("_ConsoleSettings", new Vector4(0.5f, 2.0f, 0.125f, 0.04f));
            MaterialFXAA.SetFloat("_Intensity", 1);
        }