/// <summary> /// Render with a try catch for all exception. /// /// If an exception occurs during the <see cref="PostProcessEffectRenderer.Render"/> call, it will be logged /// and returned. /// /// Use this method instead of <see cref="PostProcessEffectRenderer.Render"/> in critical contexts /// to avoid entering the exception flow. /// </summary> /// <param name="self">The renderer to render.</param> /// <param name="context">A context object</param> /// <returns></returns> public static Exception RenderOrLog(this PostProcessEffectRenderer self, PostProcessRenderContext context) { try { self.Render(context); } catch (Exception e) { Debug.LogException(e); return(e); } return(null); }
private void BuildCommandBuffers() { PostProcessRenderContext currentContext = m_CurrentContext; RenderTextureFormat renderTextureFormat = (!m_Camera.allowHDR) ? RenderTextureFormat.Default : RuntimeUtilities.defaultHDRRenderTextureFormat; if (!RuntimeUtilities.isFloatingPointFormat(renderTextureFormat)) { m_NaNKilled = true; } currentContext.Reset(); currentContext.camera = m_Camera; currentContext.sourceFormat = renderTextureFormat; m_LegacyCmdBufferBeforeReflections.Clear(); m_LegacyCmdBufferBeforeLighting.Clear(); m_LegacyCmdBufferOpaque.Clear(); m_LegacyCmdBuffer.Clear(); SetupContext(currentContext); currentContext.command = m_LegacyCmdBufferOpaque; TextureLerper.instance.BeginFrame(currentContext); UpdateSettingsIfNeeded(currentContext); PostProcessBundle bundle = GetBundle <AmbientOcclusion>(); AmbientOcclusion ambientOcclusion = bundle.CastSettings <AmbientOcclusion>(); AmbientOcclusionRenderer ambientOcclusionRenderer = bundle.CastRenderer <AmbientOcclusionRenderer>(); bool flag = ambientOcclusion.IsEnabledAndSupported(currentContext); bool flag2 = ambientOcclusionRenderer.IsAmbientOnly(currentContext); bool flag3 = flag && flag2; bool flag4 = flag && !flag2; PostProcessBundle bundle2 = GetBundle <ScreenSpaceReflections>(); PostProcessEffectSettings settings = bundle2.settings; PostProcessEffectRenderer renderer = bundle2.renderer; bool flag5 = settings.IsEnabledAndSupported(currentContext); if (flag3) { IAmbientOcclusionMethod ambientOcclusionMethod = ambientOcclusionRenderer.Get(); currentContext.command = m_LegacyCmdBufferBeforeReflections; ambientOcclusionMethod.RenderAmbientOnly(currentContext); currentContext.command = m_LegacyCmdBufferBeforeLighting; ambientOcclusionMethod.CompositeAmbientOnly(currentContext); } else if (flag4) { currentContext.command = m_LegacyCmdBufferOpaque; ambientOcclusionRenderer.Get().RenderAfterOpaque(currentContext); } bool flag6 = fog.IsEnabledAndSupported(currentContext); bool flag7 = HasOpaqueOnlyEffects(currentContext); int num = 0; num += (flag5 ? 1 : 0); num += (flag6 ? 1 : 0); num += (flag7 ? 1 : 0); RenderTargetIdentifier renderTargetIdentifier = new RenderTargetIdentifier(BuiltinRenderTextureType.CameraTarget); if (num > 0) { CommandBuffer commandBuffer = currentContext.command = m_LegacyCmdBufferOpaque; int nameID = m_TargetPool.Get(); currentContext.GetScreenSpaceTemporaryRT(commandBuffer, nameID, 0, renderTextureFormat); commandBuffer.BuiltinBlit(renderTargetIdentifier, nameID, RuntimeUtilities.copyStdMaterial, stopNaNPropagation ? 1 : 0); currentContext.source = nameID; int nameID2 = -1; if (num > 1) { nameID2 = m_TargetPool.Get(); currentContext.GetScreenSpaceTemporaryRT(commandBuffer, nameID2, 0, renderTextureFormat); currentContext.destination = nameID2; } else { currentContext.destination = renderTargetIdentifier; } if (flag5) { renderer.Render(currentContext); num--; RenderTargetIdentifier source = currentContext.source; currentContext.source = currentContext.destination; currentContext.destination = ((num != 1) ? source : renderTargetIdentifier); } if (flag6) { fog.Render(currentContext); num--; RenderTargetIdentifier source2 = currentContext.source; currentContext.source = currentContext.destination; currentContext.destination = ((num != 1) ? source2 : renderTargetIdentifier); } if (flag7) { RenderOpaqueOnly(currentContext); } if (num > 1) { commandBuffer.ReleaseTemporaryRT(nameID2); } commandBuffer.ReleaseTemporaryRT(nameID); } int nameID3 = m_TargetPool.Get(); currentContext.GetScreenSpaceTemporaryRT(m_LegacyCmdBuffer, nameID3, 0, renderTextureFormat, RenderTextureReadWrite.sRGB); m_LegacyCmdBuffer.BuiltinBlit(renderTargetIdentifier, nameID3, RuntimeUtilities.copyStdMaterial, stopNaNPropagation ? 1 : 0); if (!m_NaNKilled) { m_NaNKilled = stopNaNPropagation; } currentContext.command = m_LegacyCmdBuffer; currentContext.source = nameID3; currentContext.destination = renderTargetIdentifier; Render(currentContext); m_LegacyCmdBuffer.ReleaseTemporaryRT(nameID3); }