Exemple #1
0
    void Update()
    {
        if (m_targetCamera != null)
        {
            if (m_targetCamera.actualRenderingPath != RenderingPath.DeferredShading)
            {
                if (PerPixelNormals != PerPixelNormalSource.None && PerPixelNormals != PerPixelNormalSource.Camera)
                {
                    m_paramsChanged = true;
                    PerPixelNormals = PerPixelNormalSource.Camera;
                    UnityEngine.Debug.LogWarning("[AmplifyOcclusion] GBuffer Normals only available in Camera Deferred Shading mode. Switched to Camera source.");
                }

                if (ApplyMethod == ApplicationMethod.Deferred)
                {
                    m_paramsChanged = true;
                    ApplyMethod     = ApplicationMethod.PostEffect;
                    UnityEngine.Debug.LogWarning("[AmplifyOcclusion] Deferred Method requires a Deferred Shading path. Switching to Post Effect Method.");
                }
            }
            else
            {
                if (PerPixelNormals == PerPixelNormalSource.Camera)
                {
                    m_paramsChanged = true;
                    PerPixelNormals = PerPixelNormalSource.GBuffer;
                    UnityEngine.Debug.LogWarning("[AmplifyOcclusion] Camera Normals not supported for Deferred Method. Switching to GBuffer Normals.");
                }
            }

            if ((m_targetCamera.depthTextureMode & DepthTextureMode.Depth) == 0)
            {
                m_targetCamera.depthTextureMode |= DepthTextureMode.Depth;
            }

            if ((PerPixelNormals == PerPixelNormalSource.Camera) &&
                (m_targetCamera.depthTextureMode & DepthTextureMode.DepthNormals) == 0)
            {
                m_targetCamera.depthTextureMode |= DepthTextureMode.DepthNormals;
            }

            if ((UsingMotionVectors == true) &&
                (m_targetCamera.depthTextureMode & DepthTextureMode.MotionVectors) == 0)
            {
                m_targetCamera.depthTextureMode |= DepthTextureMode.MotionVectors;
            }
        }
        else
        {
            m_targetCamera = GetComponent <Camera>();
        }
    }
 void UpdateParams()
 {
     prevScreenWidth     = m_camera.pixelWidth;
     prevScreenHeight    = m_camera.pixelHeight;
     prevHDR             = m_camera.hdr;
     prevApplyMethod     = ApplyMethod;
     prevSampleCount     = SampleCount;
     prevPerPixelNormals = PerPixelNormals;
     prevCacheAware      = CacheAware;
     prevDownscale       = Downsample;
     prevBlurEnabled     = BlurEnabled;
     prevBlurRadius      = BlurRadius;
     prevBlurPasses      = BlurPasses;
 }
    void Update()
    {
        if (m_camera.actualRenderingPath != RenderingPath.DeferredShading)
        {
            if (PerPixelNormals != PerPixelNormalSource.None && PerPixelNormals != PerPixelNormalSource.Camera)
            {
                // NOTE: use inspector warning box instead?
                PerPixelNormals = PerPixelNormalSource.Camera;
                UnityEngine.Debug.LogWarning("[AmplifyOcclusion] GBuffer Normals only available in Camera Deferred Shading mode. Switched to Camera source.");
            }

            if (ApplyMethod == ApplicationMethod.Deferred)
            {
                // NOTE: use inspector warning box instead?
                ApplyMethod = ApplicationMethod.PostEffect;
                UnityEngine.Debug.LogWarning("[AmplifyOcclusion] Deferred Method requires a Deferred Shading path. Switching to Post Effect Method.");
            }
        }

        if (ApplyMethod == ApplicationMethod.Deferred && PerPixelNormals == PerPixelNormalSource.Camera)
        {
            // NOTE: use inspector warning box instead?
            PerPixelNormals = PerPixelNormalSource.GBuffer;
            UnityEngine.Debug.LogWarning("[AmplifyOcclusion] Camera Normals not supported for Deferred Method. Switching to GBuffer Normals.");
        }

        if ((m_camera.depthTextureMode & DepthTextureMode.Depth) == 0)
        {
            m_camera.depthTextureMode |= DepthTextureMode.Depth;
        }

        if ((PerPixelNormals == PerPixelNormalSource.Camera) && (m_camera.depthTextureMode & DepthTextureMode.DepthNormals) == 0)
        {
            m_camera.depthTextureMode |= DepthTextureMode.DepthNormals;
        }

        CheckMaterial();
        CheckRandomData();
    }
Exemple #4
0
 void UpdateParams()
 {
     prevScreenWidth  = m_camera.pixelWidth;
     prevScreenHeight = m_camera.pixelHeight;
     #if UNITY_5_6_OR_NEWER
     prevHDR = m_camera.allowHDR;
     #else
     prevHDR = m_camera.hdr;
     #endif
     prevApplyMethod         = ApplyMethod;
     prevSampleCount         = SampleCount;
     prevPerPixelNormals     = PerPixelNormals;
     prevCacheAware          = CacheAware;
     prevDownscale           = Downsample;
     prevFadeEnabled         = FadeEnabled;
     prevFadeToIntensity     = FadeToIntensity;
     prevFadeToRadius        = FadeToRadius;
     prevFadeToPowerExponent = FadeToPowerExponent;
     prevFadeStart           = FadeStart;
     prevFadeLength          = FadeLength;
     prevBlurEnabled         = BlurEnabled;
     prevBlurRadius          = BlurRadius;
     prevBlurPasses          = BlurPasses;
 }
Exemple #5
0
    void OnPreRender()
    {
        Profiler.BeginSample("AO - OnPreRender");

        checkMaterials(true);

        if (m_targetCamera != null)
        {
                        #if UNITY_EDITOR
            if ((m_targetCamera.cameraType == CameraType.SceneView) &&
                (((PerPixelNormals == PerPixelNormalSource.GBuffer) && (m_targetCamera.orthographic == true)) ||
                 (PerPixelNormals == PerPixelNormalSource.Camera) && (SceneView.lastActiveSceneView.m_SceneLighting == false)))
            {
                PerPixelNormals = PerPixelNormalSource.None;
            }
                        #endif

            bool deferredReflections = (GraphicsSettings.GetShaderMode(BuiltinShaderType.DeferredReflections) != BuiltinShaderMode.Disabled);

            if ((m_prevPerPixelNormals != PerPixelNormals) ||
                (m_prevApplyMethod != ApplyMethod) ||
                (m_prevDeferredReflections != deferredReflections) ||
                (m_commandBuffer_Parameters.cmdBuffer == null) ||
                (m_commandBuffer_Occlusion.cmdBuffer == null) ||
                (m_commandBuffer_Apply.cmdBuffer == null)
                )
            {
                CameraEvent cameraStage = CameraEvent.BeforeImageEffectsOpaque;
                if (ApplyMethod == ApplicationMethod.Deferred)
                {
                    cameraStage = deferredReflections ? CameraEvent.BeforeReflections : CameraEvent.BeforeLighting;
                }

                createCommandBuffer(ref m_commandBuffer_Parameters, "AmplifyOcclusion_Parameters_" + m_myIDstring, cameraStage);
                createCommandBuffer(ref m_commandBuffer_Occlusion, "AmplifyOcclusion_Compute_" + m_myIDstring, cameraStage);
                createCommandBuffer(ref m_commandBuffer_Apply, "AmplifyOcclusion_Apply_" + m_myIDstring, cameraStage);

                m_prevPerPixelNormals     = PerPixelNormals;
                m_prevApplyMethod         = ApplyMethod;
                m_prevDeferredReflections = deferredReflections;

                m_paramsChanged = true;
            }

            if ((m_commandBuffer_Parameters.cmdBuffer != null) &&
                (m_commandBuffer_Occlusion.cmdBuffer != null) &&
                (m_commandBuffer_Apply.cmdBuffer != null))
            {
                if (AmplifyOcclusionCommon.IsStereoMultiPassEnabled(m_targetCamera) == true)
                {
                    uint curStepIdx = (m_sampleStep >> 1) & 1;
                    uint curEyeIdx  = (m_sampleStep & 1);
                    m_curTemporalIdx  = (curEyeIdx * 2) + (0 + curStepIdx);
                    m_prevTemporalIdx = (curEyeIdx * 2) + (1 - curStepIdx);
                }
                else
                {
                    uint curStepIdx = m_sampleStep & 1;
                    m_curTemporalIdx  = 0 + curStepIdx;
                    m_prevTemporalIdx = 1 - curStepIdx;
                }

                m_commandBuffer_Parameters.cmdBuffer.Clear();

                UpdateGlobalShaderConstants(m_commandBuffer_Parameters.cmdBuffer);

                UpdateGlobalShaderConstants_Matrices(m_commandBuffer_Parameters.cmdBuffer);

                UpdateGlobalShaderConstants_AmbientOcclusion(m_commandBuffer_Parameters.cmdBuffer);

                checkParamsChanged();

                if (m_paramsChanged)
                {
                    m_commandBuffer_Occlusion.cmdBuffer.Clear();

                    commandBuffer_FillComputeOcclusion(m_commandBuffer_Occlusion.cmdBuffer);
                }

                m_commandBuffer_Apply.cmdBuffer.Clear();

                if (ApplyMethod == ApplicationMethod.Debug)
                {
                    commandBuffer_FillApplyDebug(m_commandBuffer_Apply.cmdBuffer);
                }
                else
                {
                    if (ApplyMethod == ApplicationMethod.PostEffect)
                    {
                        commandBuffer_FillApplyPostEffect(m_commandBuffer_Apply.cmdBuffer);
                    }
                    else
                    {
                        bool logTarget = !m_HDR;

                        commandBuffer_FillApplyDeferred(m_commandBuffer_Apply.cmdBuffer, logTarget);
                    }
                }

                updateParams();

                m_sampleStep++;                 // No clamp, free running counter
            }
        }
        else
        {
            m_targetCamera = GetComponent <Camera>();

            Update();

                        #if UNITY_EDITOR
            if (m_targetCamera.cameraType != CameraType.SceneView)
            {
                System.Type          T     = System.Type.GetType("UnityEditor.GameView,UnityEditor");
                UnityEngine.Object[] array = Resources.FindObjectsOfTypeAll(T);

                if (array.Length > 0)
                {
                    EditorWindow gameView = (EditorWindow)array[0];
                    gameView.Focus();
                }
            }
                        #endif
        }

        Profiler.EndSample();
    }
Exemple #6
0
    void OnPreRender()
    {
        Profiler.BeginSample("AO - OnPreRender");

        checkMaterials(true);

        if (m_targetCamera != null)
        {
            bool deferredReflections = (GraphicsSettings.GetShaderMode(BuiltinShaderType.DeferredReflections) != BuiltinShaderMode.Disabled);

            if ((m_prevPerPixelNormals != PerPixelNormals) ||
                (m_prevApplyMethod != ApplyMethod) ||
                (m_prevDeferredReflections != deferredReflections) ||
                (m_commandBuffer_Occlusion.cmdBuffer == null) ||
                (m_commandBuffer_Apply.cmdBuffer == null)
                )
            {
                CameraEvent cameraStage = CameraEvent.BeforeImageEffectsOpaque;
                if (ApplyMethod == ApplicationMethod.Deferred)
                {
                    cameraStage = deferredReflections ? CameraEvent.BeforeReflections : CameraEvent.BeforeLighting;
                }

                createCommandBuffer(ref m_commandBuffer_Occlusion, "AmplifyOcclusion_Compute", cameraStage);
                createCommandBuffer(ref m_commandBuffer_Apply, "AmplifyOcclusion_Apply", cameraStage);

                m_prevPerPixelNormals     = PerPixelNormals;
                m_prevApplyMethod         = ApplyMethod;
                m_prevDeferredReflections = deferredReflections;

                m_paramsChanged = true;
            }

            if ((m_commandBuffer_Occlusion.cmdBuffer != null) &&
                (m_commandBuffer_Apply.cmdBuffer != null))
            {
                m_curStepIdx = m_sampleStep & 1;

                UpdateGlobalShaderConstants();

                checkParamsChanged();

                UpdateGlobalShaderConstants_AmbientOcclusion();
                UpdateGlobalShaderConstants_Matrices();

                if (m_paramsChanged)
                {
                    m_commandBuffer_Occlusion.cmdBuffer.Clear();

                    commandBuffer_FillComputeOcclusion(m_commandBuffer_Occlusion.cmdBuffer);
                }


                m_commandBuffer_Apply.cmdBuffer.Clear();

                if (ApplyMethod == ApplicationMethod.Debug)
                {
                    commandBuffer_FillApplyDebug(m_commandBuffer_Apply.cmdBuffer);
                }
                else
                {
                    if (ApplyMethod == ApplicationMethod.PostEffect)
                    {
                        commandBuffer_FillApplyPostEffect(m_commandBuffer_Apply.cmdBuffer);
                    }
                    else
                    {
                        bool logTarget = !m_HDR;

                        commandBuffer_FillApplyDeferred(m_commandBuffer_Apply.cmdBuffer, logTarget);
                    }
                }

                updateParams();

                m_sampleStep++;                 // No clamp, free running counter
            }
        }

        Profiler.EndSample();
    }