void commandBuffer_FillApplyPostEffect(CommandBuffer cb) { cb.BeginSample("AO 3 - ApplyPostEffect"); if (UsingTemporalFilter) { commandBuffer_TemporalFilter(cb); int tmpMotionIntensityRT = 0; if (UsingMotionVectors == true) { tmpMotionIntensityRT = commandBuffer_NeighborMotionIntensity(cb, m_target.width, m_target.height); } int applyOcclusionRT = 0; if (useMRTBlendingFallback) { applyOcclusionRT = AmplifyOcclusionCommon.SafeAllocateTemporaryRT(cb, "_AO_ApplyOcclusionTexture", m_target.fullWidth, m_target.fullHeight, RenderTextureFormat.ARGB32); applyPostEffectTargetsTemporal[0] = applyOcclusionRT; } else { applyPostEffectTargetsTemporal[0] = BuiltinRenderTextureType.CameraTarget; } applyPostEffectTargetsTemporal[1] = new RenderTargetIdentifier(m_temporalAccumRT[m_curTemporalIdx]); cb.SetRenderTarget(applyPostEffectTargetsTemporal, applyPostEffectTargetsTemporal[0] /* Not used, just to make Unity happy */); PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyPostEffectTemporal + getTemporalPass()); if (useMRTBlendingFallback) { cb.SetGlobalTexture("_AO_ApplyOcclusionTexture", applyOcclusionRT); cb.SetRenderTarget(BuiltinRenderTextureType.CameraTarget); PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyPostEffectTemporalMultiply); AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, applyOcclusionRT); } if (UsingMotionVectors == true) { AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, tmpMotionIntensityRT); } } else { cb.SetGlobalTexture(PropertyID._AO_CurrOcclusionDepth, m_occlusionDepthRT); cb.SetRenderTarget(BuiltinRenderTextureType.CameraTarget); PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyPostEffect); } cb.SetRenderTarget(default(RenderTexture)); cb.EndSample("AO 3 - ApplyPostEffect"); }
private void releaseTemporalRT() { if (m_temporalAccumRT != null) { for (int i = 0; i < m_temporalAccumRT.Length; i++) { AmplifyOcclusionCommon.SafeReleaseRT(ref m_temporalAccumRT[i]); } } m_temporalAccumRT = null; }
void UpdateGlobalShaderConstants_AmbientOcclusion(CommandBuffer cb) { // Ambient Occlusion cb.SetGlobalFloat(PropertyID._AO_Radius, Radius); cb.SetGlobalFloat(PropertyID._AO_PowExponent, PowerExponent); cb.SetGlobalFloat(PropertyID._AO_Bias, Bias * Bias); cb.SetGlobalColor(PropertyID._AO_Levels, new Color(Tint.r, Tint.g, Tint.b, Intensity)); float invThickness = (1.0f - Thickness); cb.SetGlobalFloat(PropertyID._AO_ThicknessDecay, (1.0f - invThickness * invThickness) * 0.98f); if (BlurEnabled == true) { cb.SetGlobalFloat(PropertyID._AO_BlurSharpness, BlurSharpness * 100); } // Distance Fade if (FadeEnabled == true) { FadeStart = Mathf.Max(0.0f, FadeStart); FadeLength = Mathf.Max(0.01f, FadeLength); float rcpFadeLength = 1.0f / FadeLength; cb.SetGlobalVector(PropertyID._AO_FadeParams, new Vector2(FadeStart, rcpFadeLength)); float invFadeThickness = (1.0f - FadeToThickness); cb.SetGlobalVector(PropertyID._AO_FadeValues, new Vector4(FadeToIntensity, FadeToRadius, FadeToPowerExponent, (1.0f - invFadeThickness * invFadeThickness) * 0.98f)); cb.SetGlobalColor(PropertyID._AO_FadeToTint, new Color(FadeToTint.r, FadeToTint.g, FadeToTint.b, 0.0f)); } else { cb.SetGlobalVector(PropertyID._AO_FadeParams, new Vector2(0.0f, 0.0f)); } if (FilterEnabled == true) { AmplifyOcclusionCommon.CommandBuffer_TemporalFilterDirectionsOffsets(cb, m_sampleStep); } else { cb.SetGlobalFloat(PropertyID._AO_TemporalDirections, 0); cb.SetGlobalFloat(PropertyID._AO_TemporalOffsets, 0); } }
int commandBuffer_NeighborMotionIntensity(CommandBuffer cb, int aSourceWidth, int aSourceHeight) { int tmpRT = AmplifyOcclusionCommon.SafeAllocateTemporaryRT(cb, "_AO_IntensityTmp", aSourceWidth / 4, aSourceHeight / 4, m_motionIntensityRTFormat, RenderTextureReadWrite.Linear, FilterMode.Bilinear); cb.SetRenderTarget(tmpRT); cb.SetGlobalVector("_AO_Target_TexelSize", new Vector4(1.0f / (aSourceWidth / 4.0f), 1.0f / (aSourceHeight / 4.0f), aSourceWidth / 4.0f, aSourceHeight / 4.0f)); PerformBlit(cb, m_occlusionMat, ShaderPass.NeighborMotionIntensity); int tmpBlurRT = AmplifyOcclusionCommon.SafeAllocateTemporaryRT(cb, "_AO_BlurIntensityTmp", aSourceWidth / 4, aSourceHeight / 4, m_motionIntensityRTFormat, RenderTextureReadWrite.Linear, FilterMode.Bilinear); // Horizontal cb.SetGlobalTexture(PropertyID._AO_CurrMotionIntensity, tmpRT); cb.SetRenderTarget(tmpBlurRT); PerformBlit(cb, m_blurMat, ShaderPass.BlurHorizontalIntensity); // Vertical cb.SetGlobalTexture(PropertyID._AO_CurrMotionIntensity, tmpBlurRT); cb.SetRenderTarget(tmpRT); PerformBlit(cb, m_blurMat, ShaderPass.BlurVerticalIntensity); AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, tmpBlurRT); cb.SetGlobalTexture(PropertyID._AO_CurrMotionIntensity, tmpRT); return(tmpRT); }
void commandBuffer_Blur(CommandBuffer cb, RenderTargetIdentifier aSourceRT, int aSourceWidth, int aSourceHeight) { cb.BeginSample("AO 2 - Blur"); int tmpBlurRT = AmplifyOcclusionCommon.SafeAllocateTemporaryRT(cb, "_AO_BlurTmp", aSourceWidth, aSourceHeight, m_occlusionRTFormat, RenderTextureReadWrite.Linear, FilterMode.Bilinear); // Apply Cross Bilateral Blur for (int i = 0; i < BlurPasses; i++) { // Horizontal cb.SetGlobalTexture(PropertyID._AO_CurrOcclusionDepth, aSourceRT); int blurHorizontalPass = ShaderPass.BlurHorizontal1 + (BlurRadius - 1) * 2; cb.SetRenderTarget(tmpBlurRT); PerformBlit(cb, m_blurMat, blurHorizontalPass); // Vertical cb.SetGlobalTexture(PropertyID._AO_CurrOcclusionDepth, tmpBlurRT); int blurVerticalPass = ShaderPass.BlurVertical1 + (BlurRadius - 1) * 2; cb.SetRenderTarget(aSourceRT); PerformBlit(cb, m_blurMat, blurVerticalPass); } AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, tmpBlurRT); cb.SetRenderTarget(default(RenderTexture)); cb.EndSample("AO 2 - Blur"); }
void Reset() { if (m_commandBuffer_Parameters.cmdBuffer != null) { cleanupCommandBuffer(ref m_commandBuffer_Parameters); } if (m_commandBuffer_Occlusion.cmdBuffer != null) { cleanupCommandBuffer(ref m_commandBuffer_Occlusion); } if (m_commandBuffer_Apply.cmdBuffer != null) { cleanupCommandBuffer(ref m_commandBuffer_Apply); } AmplifyOcclusionCommon.SafeReleaseRT(ref m_occlusionDepthRT); AmplifyOcclusionCommon.SafeReleaseRT(ref m_depthMipmap); releaseTemporalRT(); m_tmpMipString = null; }
private void checkMaterials(bool aThroughErrorMsg) { if (m_occlusionMat == null) { m_occlusionMat = AmplifyOcclusionCommon.CreateMaterialWithShaderName("Hidden/Amplify Occlusion/Occlusion", aThroughErrorMsg); } if (m_blurMat == null) { m_blurMat = AmplifyOcclusionCommon.CreateMaterialWithShaderName("Hidden/Amplify Occlusion/Blur", aThroughErrorMsg); } if (m_applyOcclusionMat == null) { m_applyOcclusionMat = AmplifyOcclusionCommon.CreateMaterialWithShaderName("Hidden/Amplify Occlusion/Apply", aThroughErrorMsg); if (m_applyOcclusionMat != null) { // some platforms still don't support MRT-blending; provide a fallback, if necessary useMRTBlendingFallback = m_applyOcclusionMat.GetTag("MRTBlending", false).ToUpper() != "TRUE"; } } }
void commandBuffer_FillApplyDebug(CommandBuffer cb) { cb.BeginSample("AO 3 - ApplyDebug"); if (UsingTemporalFilter) { commandBuffer_TemporalFilter(cb); int tmpMotionIntensityRT = 0; if (UsingMotionVectors == true) { tmpMotionIntensityRT = commandBuffer_NeighborMotionIntensity(cb, m_target.width, m_target.height); } applyDebugTargetsTemporal[0] = BuiltinRenderTextureType.CameraTarget; applyDebugTargetsTemporal[1] = new RenderTargetIdentifier(m_temporalAccumRT[m_curTemporalIdx]); cb.SetRenderTarget(applyDebugTargetsTemporal, applyDebugTargetsTemporal[0] /* Not used, just to make Unity happy */); PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyDebugTemporal + getTemporalPass()); if (UsingMotionVectors == true) { AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, tmpMotionIntensityRT); } } else { cb.SetGlobalTexture(PropertyID._AO_CurrOcclusionDepth, m_occlusionDepthRT); cb.SetRenderTarget(BuiltinRenderTextureType.CameraTarget); PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyDebug); } cb.SetRenderTarget(default(RenderTexture)); cb.EndSample("AO 3 - ApplyDebug"); }
void commandBuffer_FillApplyDeferred(CommandBuffer cb, bool logTarget) { cb.BeginSample("AO 3 - ApplyDeferred"); if (!logTarget) { if (UsingTemporalFilter) { commandBuffer_TemporalFilter(cb); int tmpMotionIntensityRT = 0; if (UsingMotionVectors == true) { tmpMotionIntensityRT = commandBuffer_NeighborMotionIntensity(cb, m_target.width, m_target.height); } int applyOcclusionRT = 0; if (useMRTBlendingFallback) { applyOcclusionRT = AmplifyOcclusionCommon.SafeAllocateTemporaryRT(cb, "_AO_ApplyOcclusionTexture", m_target.fullWidth, m_target.fullHeight, RenderTextureFormat.ARGB32); applyOcclusionTemporal[0] = applyOcclusionRT; applyOcclusionTemporal[1] = new RenderTargetIdentifier(m_temporalAccumRT[m_curTemporalIdx]); cb.SetRenderTarget(applyOcclusionTemporal, applyOcclusionTemporal[0] /* Not used, just to make Unity happy */); PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyPostEffectTemporal + getTemporalPass()); // re-use ApplyPostEffectTemporal pass to apply without Blend to the RT. } else { applyDeferredTargetsTemporal[0] = m_applyDeferredTargets[0]; applyDeferredTargetsTemporal[1] = m_applyDeferredTargets[1]; applyDeferredTargetsTemporal[2] = new RenderTargetIdentifier(m_temporalAccumRT[m_curTemporalIdx]); cb.SetRenderTarget(applyDeferredTargetsTemporal, applyDeferredTargetsTemporal[0] /* Not used, just to make Unity happy */); PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyDeferredTemporal + getTemporalPass()); } if (useMRTBlendingFallback) { cb.SetGlobalTexture("_AO_ApplyOcclusionTexture", applyOcclusionRT); applyOcclusionTemporal[0] = m_applyDeferredTargets[0]; applyOcclusionTemporal[1] = m_applyDeferredTargets[1]; cb.SetRenderTarget(applyOcclusionTemporal, applyOcclusionTemporal[0] /* Not used, just to make Unity happy */); PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyDeferredTemporalMultiply); AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, applyOcclusionRT); } if (UsingMotionVectors == true) { AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, tmpMotionIntensityRT); } } else { cb.SetGlobalTexture(PropertyID._AO_CurrOcclusionDepth, m_occlusionDepthRT); // Multiply Occlusion cb.SetRenderTarget(m_applyDeferredTargets, m_applyDeferredTargets[0] /* Not used, just to make Unity happy */); PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyDeferred); } } else { // Copy Albedo and Emission to temporary buffers int gbufferAlbedoRT = AmplifyOcclusionCommon.SafeAllocateTemporaryRT(cb, "_AO_tmpAlbedo", m_target.fullWidth, m_target.fullHeight, RenderTextureFormat.ARGB32); int gbufferEmissionRT = AmplifyOcclusionCommon.SafeAllocateTemporaryRT(cb, "_AO_tmpEmission", m_target.fullWidth, m_target.fullHeight, m_temporaryEmissionRTFormat); cb.Blit(BuiltinRenderTextureType.GBuffer0, gbufferAlbedoRT); cb.Blit(BuiltinRenderTextureType.GBuffer3, gbufferEmissionRT); cb.SetGlobalTexture(PropertyID._AO_GBufferAlbedo, gbufferAlbedoRT); cb.SetGlobalTexture(PropertyID._AO_GBufferEmission, gbufferEmissionRT); if (UsingTemporalFilter) { commandBuffer_TemporalFilter(cb); int tmpMotionIntensityRT = 0; if (UsingMotionVectors == true) { tmpMotionIntensityRT = commandBuffer_NeighborMotionIntensity(cb, m_target.width, m_target.height); } applyDeferredTargets_Log_Temporal[0] = m_applyDeferredTargets_Log[0]; applyDeferredTargets_Log_Temporal[1] = m_applyDeferredTargets_Log[1]; applyDeferredTargets_Log_Temporal[2] = new RenderTargetIdentifier(m_temporalAccumRT[m_curTemporalIdx]); cb.SetRenderTarget(applyDeferredTargets_Log_Temporal, applyDeferredTargets_Log_Temporal[0] /* Not used, just to make Unity happy */); PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyDeferredLogTemporal + getTemporalPass()); if (UsingMotionVectors == true) { AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, tmpMotionIntensityRT); } } else { cb.SetGlobalTexture(PropertyID._AO_CurrOcclusionDepth, m_occlusionDepthRT); cb.SetRenderTarget(m_applyDeferredTargets_Log, m_applyDeferredTargets_Log[0] /* Not used, just to make Unity happy */); PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyDeferredLog); } AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, gbufferAlbedoRT); AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, gbufferEmissionRT); } cb.SetRenderTarget(default(RenderTexture)); cb.EndSample("AO 3 - ApplyDeferred"); }
private void commandBuffer_FillComputeOcclusion(CommandBuffer cb) { cb.BeginSample("AO 1 - ComputeOcclusion"); if ((PerPixelNormals == PerPixelNormalSource.GBuffer) || (PerPixelNormals == PerPixelNormalSource.GBufferOctaEncoded)) { cb.SetGlobalTexture(PropertyID._AO_GBufferNormals, BuiltinRenderTextureType.GBuffer2); } Vector4 oneOverSize_Size = new Vector4(m_target.oneOverWidth, m_target.oneOverHeight, m_target.width, m_target.height); int sampleCountPass = ((int)SampleCount) * AmplifyOcclusionCommon.PerPixelNormalSourceCount; int occlusionPass = (ShaderPass.OcclusionLow_None + sampleCountPass + ((int)PerPixelNormals)); if (CacheAware == true) { occlusionPass += ShaderPass.OcclusionLow_None_UseDynamicDepthMips; // Construct Depth mipmaps int previouslyTmpMipRT = 0; for (int i = 0; i < m_numberMips; i++) { int tmpMipRT; int width = m_target.width >> (i + 1); int height = m_target.height >> (i + 1); tmpMipRT = AmplifyOcclusionCommon.SafeAllocateTemporaryRT(cb, m_tmpMipString[i], width, height, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear, FilterMode.Bilinear); // _AO_CurrDepthSource was previously set cb.SetRenderTarget(tmpMipRT); PerformBlit(cb, m_occlusionMat, ((i == 0)?ShaderPass.ScaleDownCloserDepthEven_CameraDepthTexture:ShaderPass.ScaleDownCloserDepthEven)); cb.CopyTexture(tmpMipRT, 0, 0, m_depthMipmap, 0, i); if (previouslyTmpMipRT != 0) { AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, previouslyTmpMipRT); } previouslyTmpMipRT = tmpMipRT; cb.SetGlobalTexture(PropertyID._AO_CurrDepthSource, tmpMipRT); // Set next MipRT ID } AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, previouslyTmpMipRT); cb.SetGlobalTexture(PropertyID._AO_SourceDepthMipmap, m_depthMipmap); } if (Downsample) { int halfWidth = m_target.width / 2; int halfHeight = m_target.height / 2; int tmpSmallOcclusionRT = AmplifyOcclusionCommon.SafeAllocateTemporaryRT(cb, "_AO_SmallOcclusionTexture", halfWidth, halfHeight, m_occlusionRTFormat, RenderTextureReadWrite.Linear, FilterMode.Bilinear); cb.SetGlobalVector(PropertyID._AO_Source_TexelSize, oneOverSize_Size); cb.SetGlobalVector(PropertyID._AO_Target_TexelSize, new Vector4(1.0f / (m_target.width / 2.0f), 1.0f / (m_target.height / 2.0f), m_target.width / 2.0f, m_target.height / 2.0f)); cb.SetRenderTarget(tmpSmallOcclusionRT); PerformBlit(cb, m_occlusionMat, occlusionPass); cb.SetRenderTarget(default(RenderTexture)); cb.EndSample("AO 1 - ComputeOcclusion"); if (BlurEnabled == true) { commandBuffer_Blur(cb, tmpSmallOcclusionRT, halfWidth, halfHeight); } // Combine cb.BeginSample("AO 2b - Combine"); cb.SetGlobalTexture(PropertyID._AO_CurrOcclusionDepth, tmpSmallOcclusionRT); cb.SetGlobalVector(PropertyID._AO_Target_TexelSize, oneOverSize_Size); cb.SetRenderTarget(m_occlusionDepthRT); PerformBlit(cb, m_occlusionMat, ShaderPass.CombineDownsampledOcclusionDepth); AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, tmpSmallOcclusionRT); cb.SetRenderTarget(default(RenderTexture)); cb.EndSample("AO 2b - Combine"); } else { cb.SetGlobalVector(PropertyID._AO_Source_TexelSize, oneOverSize_Size); cb.SetGlobalVector(PropertyID._AO_Target_TexelSize, oneOverSize_Size); cb.SetRenderTarget(m_occlusionDepthRT); PerformBlit(cb, m_occlusionMat, occlusionPass); cb.SetRenderTarget(default(RenderTexture)); cb.EndSample("AO 1 - ComputeOcclusion"); if (BlurEnabled == true) { commandBuffer_Blur(cb, m_occlusionDepthRT, m_target.width, m_target.height); } } }
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(); }
private void checkParamsChanged() { bool HDR = m_targetCamera.allowHDR; // && tier? bool MSAA = m_targetCamera.allowMSAA && m_targetCamera.actualRenderingPath != RenderingPath.DeferredLighting && m_targetCamera.actualRenderingPath != RenderingPath.DeferredShading && QualitySettings.antiAliasing >= 1; int antiAliasing = MSAA ? QualitySettings.antiAliasing : 1; if (m_occlusionDepthRT != null) { if ((m_occlusionDepthRT.width != m_target.width) || (m_occlusionDepthRT.height != m_target.height) || (m_prevMSAA != MSAA) || (!m_occlusionDepthRT.IsCreated()) || (m_temporalAccumRT != null && (!m_temporalAccumRT[0].IsCreated() || !m_temporalAccumRT[1].IsCreated())) #if UNITY_EDITOR || ((m_prevIsPlaying == true) && (EditorApplication.isPlaying == false)) #endif ) { AmplifyOcclusionCommon.SafeReleaseRT(ref m_occlusionDepthRT); AmplifyOcclusionCommon.SafeReleaseRT(ref m_depthMipmap); releaseTemporalRT(); m_paramsChanged = true; } else { if (m_prevFilterEnabled != FilterEnabled) { releaseTemporalRT(); } } } if (m_temporalAccumRT != null) { if (AmplifyOcclusionCommon.IsStereoMultiPassEnabled(m_targetCamera) == true) { if (m_temporalAccumRT.Length != 4) { m_temporalAccumRT = null; } } else { if (m_temporalAccumRT.Length != 2) { m_temporalAccumRT = null; } } } if (m_occlusionDepthRT == null) { m_occlusionDepthRT = AmplifyOcclusionCommon.SafeAllocateRT("_AO_OcclusionDepthTexture", m_target.width, m_target.height, m_occlusionRTFormat, RenderTextureReadWrite.Linear, FilterMode.Bilinear); } if (m_temporalAccumRT == null && FilterEnabled) { if (AmplifyOcclusionCommon.IsStereoMultiPassEnabled(m_targetCamera) == true) { m_temporalAccumRT = new RenderTexture[4]; } else { m_temporalAccumRT = new RenderTexture[2]; } for (int i = 0; i < m_temporalAccumRT.Length; i++) { m_temporalAccumRT[i] = AmplifyOcclusionCommon.SafeAllocateRT("_AO_TemporalAccum_" + i.ToString(), m_target.width, m_target.height, m_accumTemporalRTFormat, RenderTextureReadWrite.Linear, FilterMode.Bilinear, antiAliasing); } m_clearHistory = true; } if ((CacheAware == true) && (m_depthMipmap == null)) { m_depthMipmap = AmplifyOcclusionCommon.SafeAllocateRT("_AO_DepthMipmap", m_target.width >> 1, m_target.height >> 1, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear, FilterMode.Point, 1, true); int minSize = (int)Mathf.Min(m_target.width, m_target.height); m_numberMips = (int)(Mathf.Log((float)minSize, 2.0f) + 1.0f) - 1; m_tmpMipString = null; m_tmpMipString = new string[m_numberMips]; for (int i = 0; i < m_numberMips; i++) { m_tmpMipString[i] = "_AO_TmpMip_" + i.ToString(); } } else { if ((CacheAware == false) && (m_depthMipmap != null)) { AmplifyOcclusionCommon.SafeReleaseRT(ref m_depthMipmap); m_tmpMipString = null; } } if ((m_prevSampleCount != SampleCount) || (m_prevDownsample != Downsample) || (m_prevCacheAware != CacheAware) || (m_prevBlurEnabled != BlurEnabled) || (((m_prevBlurPasses != BlurPasses) || (m_prevBlurRadius != BlurRadius)) && (BlurEnabled == true)) || (m_prevFilterEnabled != FilterEnabled) || (m_prevHDR != HDR) || (m_prevMSAA != MSAA)) { m_clearHistory |= (m_prevHDR != HDR); m_clearHistory |= (m_prevMSAA != MSAA); m_HDR = HDR; m_MSAA = MSAA; m_paramsChanged = true; } #if UNITY_EDITOR m_prevIsPlaying = EditorApplication.isPlaying; #endif }
void UpdateGlobalShaderConstants(CommandBuffer cb) { AmplifyOcclusionCommon.UpdateGlobalShaderConstants(cb, ref m_target, m_targetCamera, Downsample); }