void BuildCommandBuffers() { var context = m_CurrentContext; var sourceFormat = m_Camera.allowHDR ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default; context.Reset(); context.camera = m_Camera; context.sourceFormat = sourceFormat; // TODO: Investigate retaining command buffers on XR multi-pass right eye m_LegacyCmdBufferBeforeReflections.Clear(); m_LegacyCmdBufferBeforeLighting.Clear(); m_LegacyCmdBufferOpaque.Clear(); m_LegacyCmdBuffer.Clear(); SetupContext(context); context.command = m_LegacyCmdBufferOpaque; UpdateSettingsIfNeeded(context); // Lighting & opaque-only effects var aoBundle = GetBundle <AmbientOcclusion>(); var aoSettings = aoBundle.CastSettings <AmbientOcclusion>(); var aoRenderer = aoBundle.CastRenderer <AmbientOcclusionRenderer>(); bool aoSupported = aoSettings.IsEnabledAndSupported(context); bool aoAmbientOnly = aoRenderer.IsAmbientOnly(context); bool isAmbientOcclusionDeferred = aoSupported && aoAmbientOnly; bool isAmbientOcclusionOpaque = aoSupported && !aoAmbientOnly; var ssrBundle = GetBundle <ScreenSpaceReflections>(); var ssrSettings = ssrBundle.settings; var ssrRenderer = ssrBundle.renderer; bool isScreenSpaceReflectionsActive = ssrSettings.IsEnabledAndSupported(context); // Ambient-only AO is a special case and has to be done in separate command buffers if (isAmbientOcclusionDeferred) { var ao = aoRenderer.Get(); // Render as soon as possible - should be done async in SRPs when available context.command = m_LegacyCmdBufferBeforeReflections; ao.RenderAmbientOnly(context); // Composite with GBuffer right before the lighting pass context.command = m_LegacyCmdBufferBeforeLighting; ao.CompositeAmbientOnly(context); } else if (isAmbientOcclusionOpaque) { context.command = m_LegacyCmdBufferOpaque; aoRenderer.Get().RenderAfterOpaque(context); } bool isFogActive = fog.IsEnabledAndSupported(context); bool hasCustomOpaqueOnlyEffects = HasOpaqueOnlyEffects(context); int opaqueOnlyEffects = 0; opaqueOnlyEffects += isScreenSpaceReflectionsActive ? 1 : 0; opaqueOnlyEffects += isFogActive ? 1 : 0; opaqueOnlyEffects += hasCustomOpaqueOnlyEffects ? 1 : 0; // This works on right eye because it is resolved/populated at runtime var cameraTarget = new RenderTargetIdentifier(BuiltinRenderTextureType.CameraTarget); if (opaqueOnlyEffects > 0) { var cmd = m_LegacyCmdBufferOpaque; context.command = cmd; // We need to use the internal Blit method to copy the camera target or it'll fail // on tiled GPU as it won't be able to resolve int tempTarget0 = m_TargetPool.Get(); cmd.GetTemporaryRT(tempTarget0, context.width, context.height, 24, FilterMode.Bilinear, sourceFormat); cmd.Blit(cameraTarget, tempTarget0); context.source = tempTarget0; int tempTarget1 = -1; if (opaqueOnlyEffects > 1) { tempTarget1 = m_TargetPool.Get(); cmd.GetTemporaryRT(tempTarget1, context.width, context.height, 24, FilterMode.Bilinear, sourceFormat); context.destination = tempTarget1; } else { context.destination = cameraTarget; } if (isScreenSpaceReflectionsActive) { ssrRenderer.Render(context); opaqueOnlyEffects--; var prevSource = context.source; context.source = context.destination; context.destination = opaqueOnlyEffects == 1 ? cameraTarget : prevSource; } if (isFogActive) { fog.Render(context); opaqueOnlyEffects--; var prevSource = context.source; context.source = context.destination; context.destination = opaqueOnlyEffects == 1 ? cameraTarget : prevSource; } if (hasCustomOpaqueOnlyEffects) { RenderOpaqueOnly(context); } if (opaqueOnlyEffects > 1) { cmd.ReleaseTemporaryRT(tempTarget1); } cmd.ReleaseTemporaryRT(tempTarget0); } // Post-transparency stack // Same as before, first blit needs to use the builtin Blit command to properly handle // tiled GPUs int tempRt = m_TargetPool.Get(); m_LegacyCmdBuffer.GetTemporaryRT(tempRt, context.width, context.height, 24, FilterMode.Bilinear, sourceFormat); m_LegacyCmdBuffer.Blit(cameraTarget, tempRt, RuntimeUtilities.copyStdMaterial, stopNaNPropagation ? 1 : 0); m_NaNKilled = stopNaNPropagation; context.command = m_LegacyCmdBuffer; context.source = tempRt; context.destination = cameraTarget; Render(context); m_LegacyCmdBuffer.ReleaseTemporaryRT(tempRt); }
void OnPreCull() { // Unused in scriptable render pipelines if (RuntimeUtilities.scriptableRenderPipelineActive) { return; } var context = m_CurrentContext; var sourceFormat = m_Camera.allowHDR ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default; // Resets the projection matrix from previous frame in case TAA was enabled. // We also need to force reset the non-jittered projection matrix here as it's not done // when ResetProjectionMatrix() is called and will break transparent rendering if TAA // is switched off and the FOV or any other camera property changes. m_Camera.ResetProjectionMatrix(); m_Camera.nonJitteredProjectionMatrix = m_Camera.projectionMatrix; context.Reset(); context.camera = m_Camera; context.sourceFormat = sourceFormat; m_LegacyCmdBufferBeforeReflections.Clear(); m_LegacyCmdBufferBeforeLighting.Clear(); m_LegacyCmdBufferOpaque.Clear(); m_LegacyCmdBuffer.Clear(); SetupContext(context); context.command = m_LegacyCmdBufferOpaque; UpdateSettingsIfNeeded(context); // Lighting & opaque-only effects var aoBundle = GetBundle <AmbientOcclusion>(); var aoSettings = aoBundle.CastSettings <AmbientOcclusion>(); var aoRenderer = aoBundle.CastRenderer <AmbientOcclusionRenderer>(); bool aoSupported = aoSettings.IsEnabledAndSupported(context); bool aoAmbientOnly = aoRenderer.IsAmbientOnly(context); bool isAmbientOcclusionDeferred = aoSupported && aoAmbientOnly; bool isAmbientOcclusionOpaque = aoSupported && !aoAmbientOnly; var ssrBundle = GetBundle <ScreenSpaceReflections>(); var ssrSettings = ssrBundle.settings; var ssrRenderer = ssrBundle.renderer; bool isScreenSpaceReflectionsActive = ssrSettings.IsEnabledAndSupported(context); // Ambient-only AO is a special case and has to be done in separate command buffers if (isAmbientOcclusionDeferred) { var ao = aoRenderer.Get(); // Render as soon as possible - should be done async in SRPs when available context.command = m_LegacyCmdBufferBeforeReflections; ao.RenderAmbientOnly(context); // Composite with GBuffer right before the lighting pass context.command = m_LegacyCmdBufferBeforeLighting; ao.CompositeAmbientOnly(context); } else if (isAmbientOcclusionOpaque) { context.command = m_LegacyCmdBufferOpaque; aoRenderer.Get().RenderAfterOpaque(context); } bool isFogActive = fog.IsEnabledAndSupported(context); bool hasCustomOpaqueOnlyEffects = HasOpaqueOnlyEffects(context); int opaqueOnlyEffects = 0; opaqueOnlyEffects += isScreenSpaceReflectionsActive ? 1 : 0; opaqueOnlyEffects += isFogActive ? 1 : 0; opaqueOnlyEffects += hasCustomOpaqueOnlyEffects ? 1 : 0; var cameraTarget = new RenderTargetIdentifier(BuiltinRenderTextureType.CameraTarget); if (opaqueOnlyEffects > 0) { var cmd = m_LegacyCmdBufferOpaque; context.command = cmd; // We need to use the internal Blit method to copy the camera target or it'll fail // on tiled GPU as it won't be able to resolve int tempTarget0 = m_TargetPool.Get(); cmd.GetTemporaryRT(tempTarget0, context.width, context.height, 24, FilterMode.Bilinear, sourceFormat); cmd.Blit(cameraTarget, tempTarget0); context.source = tempTarget0; int tempTarget1 = -1; if (opaqueOnlyEffects > 1) { tempTarget1 = m_TargetPool.Get(); cmd.GetTemporaryRT(tempTarget1, context.width, context.height, 24, FilterMode.Bilinear, sourceFormat); context.destination = tempTarget1; } else { context.destination = cameraTarget; } if (isScreenSpaceReflectionsActive) { ssrRenderer.Render(context); opaqueOnlyEffects--; var prevSource = context.source; context.source = context.destination; context.destination = opaqueOnlyEffects == 1 ? cameraTarget : prevSource; } if (isFogActive) { fog.Render(context); opaqueOnlyEffects--; var prevSource = context.source; context.source = context.destination; context.destination = opaqueOnlyEffects == 1 ? cameraTarget : prevSource; } if (hasCustomOpaqueOnlyEffects) { RenderOpaqueOnly(context); } if (opaqueOnlyEffects > 1) { cmd.ReleaseTemporaryRT(tempTarget1); } cmd.ReleaseTemporaryRT(tempTarget0); } // Post-transparency stack // Same as before, first blit needs to use the builtin Blit command to properly handle // tiled GPUs int tempRt = m_TargetPool.Get(); m_LegacyCmdBuffer.GetTemporaryRT(tempRt, context.width, context.height, 24, FilterMode.Bilinear, sourceFormat); m_LegacyCmdBuffer.Blit(cameraTarget, tempRt, RuntimeUtilities.copyStdMaterial, stopNaNPropagation ? 1 : 0); m_NaNKilled = stopNaNPropagation; context.command = m_LegacyCmdBuffer; context.source = tempRt; context.destination = cameraTarget; Render(context); m_LegacyCmdBuffer.ReleaseTemporaryRT(tempRt); }
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); }
void OnPreCull() { // Unused in scriptable render pipelines if (RuntimeUtilities.scriptableRenderPipelineActive) { return; } var context = m_CurrentContext; var sourceFormat = m_Camera.allowHDR ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default; context.Reset(); context.camera = m_Camera; context.sourceFormat = sourceFormat; m_LegacyCmdBufferBeforeReflections.Clear(); m_LegacyCmdBufferOpaque.Clear(); m_LegacyCmdBuffer.Clear(); SetupContext(context); // Lighting & opaque-only effects int opaqueOnlyEffects = 0; bool hasCustomOpaqueOnlyEffects = HasOpaqueOnlyEffects(context); bool isAmbientOcclusionDeferred = ambientOcclusion.IsEnabledAndSupported(context) && ambientOcclusion.IsAmbientOnly(context); bool isAmbientOcclusionOpaque = ambientOcclusion.IsEnabledAndSupported(context) && !ambientOcclusion.IsAmbientOnly(context); bool isFogActive = fog.IsEnabledAndSupported(context); // Ambient-only AO is done in a separate command buffer, before reflections if (isAmbientOcclusionDeferred) { context.command = m_LegacyCmdBufferBeforeReflections; ambientOcclusion.RenderAmbientOnly(context); } else if (isAmbientOcclusionOpaque) { opaqueOnlyEffects++; } opaqueOnlyEffects += isFogActive ? 1 : 0; opaqueOnlyEffects += hasCustomOpaqueOnlyEffects ? 1 : 0; var cameraTarget = new RenderTargetIdentifier(BuiltinRenderTextureType.CameraTarget); if (opaqueOnlyEffects > 0) { var cmd = m_LegacyCmdBufferOpaque; context.command = cmd; // We need to use the internal Blit method to copy the camera target or it'll fail // on tiled GPU as it won't be able to resolve int tempTarget0 = m_TargetPool.Get(); cmd.GetTemporaryRT(tempTarget0, context.width, context.height, 24, FilterMode.Bilinear, sourceFormat); cmd.Blit(cameraTarget, tempTarget0); context.source = tempTarget0; int tempTarget1 = -1; if (opaqueOnlyEffects > 1) { tempTarget1 = m_TargetPool.Get(); cmd.GetTemporaryRT(tempTarget1, context.width, context.height, 24, FilterMode.Bilinear, sourceFormat); context.destination = tempTarget1; } else { context.destination = cameraTarget; } if (isAmbientOcclusionOpaque) { ambientOcclusion.RenderAfterOpaque(context); opaqueOnlyEffects--; var prevSource = context.source; context.source = context.destination; context.destination = opaqueOnlyEffects == 1 ? cameraTarget : prevSource; } // TODO: Insert SSR here if (isFogActive) { fog.Render(context); opaqueOnlyEffects--; var prevSource = context.source; context.source = context.destination; context.destination = opaqueOnlyEffects == 1 ? cameraTarget : prevSource; } if (hasCustomOpaqueOnlyEffects) { RenderOpaqueOnly(context); } if (opaqueOnlyEffects > 1) { cmd.ReleaseTemporaryRT(tempTarget1); } cmd.ReleaseTemporaryRT(tempTarget0); } // Post-transparency stack // Same as before, first blit needs to use the builtin Blit command to properly handle // tiled GPUs int tempRt = m_TargetPool.Get(); m_LegacyCmdBuffer.GetTemporaryRT(tempRt, context.width, context.height, 24, FilterMode.Bilinear, sourceFormat); m_LegacyCmdBuffer.SetGlobalTexture(ShaderIDs.MainTex, cameraTarget); m_LegacyCmdBuffer.Blit(cameraTarget, tempRt, RuntimeUtilities.copyMaterial, stopNaNPropagation ? 3 : 2); m_NaNKilled = stopNaNPropagation; context.command = m_LegacyCmdBuffer; context.source = tempRt; context.destination = cameraTarget; Render(context); m_LegacyCmdBuffer.ReleaseTemporaryRT(tempRt); }