Ejemplo n.º 1
0
        public FrameRenderingConfiguration SetupFrameRenderingConfiguration(CameraContext cameraContext, ShadowManager shadowManager)
        {
            var configuration = (cameraContext.StereoEnabled) ? FrameRenderingConfiguration.Stereo : FrameRenderingConfiguration.None;

            if (cameraContext.StereoEnabled && XRSettings.eyeTextureDesc.dimension == TextureDimension.Tex2DArray)
            {
                m_IntermediateTextureArray = true;
            }
            else
            {
                m_IntermediateTextureArray = false;
            }

            var  camera              = cameraContext.Camera;
            bool hdrEnabled          = m_Asset.SupportsHDR && camera.allowHDR;
            bool intermediateTexture = camera.targetTexture != null || camera.cameraType == CameraType.SceneView ||
                                       m_Asset.RenderScale < 1.0f || hdrEnabled;

            m_ColorFormat            = hdrEnabled ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default;
            m_RequireCopyColor       = false;
            m_DepthRenderBuffer      = false;
            m_CameraPostProcessLayer = camera.GetComponent <PostProcessLayer>();

            bool msaaEnabled = camera.allowMSAA && m_Asset.MSAASampleCount > 1 && (camera.targetTexture == null || camera.targetTexture.antiAliasing > 1);

            // TODO: PostProcessing and SoftParticles are currently not support for VR
            bool postProcessEnabled = m_CameraPostProcessLayer != null && m_CameraPostProcessLayer.enabled && !cameraContext.StereoEnabled;

            m_RequireDepthTexture = m_Asset.RequireDepthTexture && !cameraContext.StereoEnabled;
            if (postProcessEnabled)
            {
                m_RequireDepthTexture = true;
                intermediateTexture   = true;

                configuration |= FrameRenderingConfiguration.PostProcess;
                if (m_CameraPostProcessLayer.HasOpaqueOnlyEffects(m_PostProcessRenderContext))
                {
                    configuration |= FrameRenderingConfiguration.BeforeTransparentPostProcess;
                    if (m_CameraPostProcessLayer.sortedBundles[PostProcessEvent.BeforeTransparent].Count == 1)
                    {
                        m_RequireCopyColor = true;
                    }
                }
            }

            if (cameraContext.SceneViewCamera)
            {
                m_RequireDepthTexture = true;
            }

            if (shadowManager.Shadows)
            {
                m_RequireDepthTexture = shadowManager.IsScreenSpace;

                if (!msaaEnabled)
                {
                    intermediateTexture = true;
                }
            }

            if (msaaEnabled)
            {
                configuration      |= FrameRenderingConfiguration.Msaa;
                intermediateTexture = intermediateTexture || !LightweightUtils.PlatformSupportsMSAABackBuffer();
            }

            if (m_RequireDepthTexture)
            {
                // If msaa is enabled we don't use a depth renderbuffer as we might not have support to Texture2DMS to resolve depth.
                // Instead we use a depth prepass and whenever depth is needed we use the 1 sample depth from prepass.
                // Screen space shadows require depth before opaque shading.
                if (!msaaEnabled && !shadowManager.Shadows)
                {
                    bool supportsDepthCopy = m_CopyTextureSupport != CopyTextureSupport.None && m_Asset.CopyDepthShader.isSupported;
                    m_DepthRenderBuffer = true;
                    intermediateTexture = true;

                    // If requiring a camera depth texture we need separate depth as it reads/write to depth at same time
                    // Post process doesn't need the copy
                    if (!m_Asset.RequireDepthTexture && postProcessEnabled)
                    {
                        configuration |= (supportsDepthCopy) ? FrameRenderingConfiguration.DepthCopy : FrameRenderingConfiguration.DepthPrePass;
                    }
                }
                else
                {
                    configuration |= FrameRenderingConfiguration.DepthPrePass;
                }
            }

            Rect cameraRect = camera.rect;

            if (!(Math.Abs(cameraRect.x) > 0.0f || Math.Abs(cameraRect.y) > 0.0f || Math.Abs(cameraRect.width) < 1.0f || Math.Abs(cameraRect.height) < 1.0f))
            {
                configuration |= FrameRenderingConfiguration.DefaultViewport;
            }
            else
            {
                intermediateTexture = true;
            }

            if (intermediateTexture)
            {
                configuration |= FrameRenderingConfiguration.IntermediateTexture;
            }

            return(configuration);
        }