// Classic render target pipeline for RT-based effects void OnRenderImage(RenderTexture source, RenderTexture destination) { if (profile == null || m_Camera == null) { Graphics.Blit(source, destination); return; } // Uber shader setup bool uberActive = false; bool fxaaActive = m_Fxaa.active; bool taaActive = m_Taa.active && !m_RenderingInSceneView; bool dofActive = m_DepthOfField.active && !m_RenderingInSceneView; var uberMaterial = m_MaterialFactory.Get("Hidden/Post FX/Uber Shader"); uberMaterial.shaderKeywords = null; var src = source; var dst = destination; if (taaActive) { var tempRT = m_RenderTextureFactory.Get(src); m_Taa.Render(src, tempRT); src = tempRT; } #if UNITY_EDITOR // Render to a dedicated target when monitors are enabled so they can show information // about the final render. // At runtime the output will always be the backbuffer or whatever render target is // currently set on the camera. if (profile.monitors.onFrameEndEditorOnly != null) { dst = m_RenderTextureFactory.Get(src); } #endif Texture autoExposure = GraphicsUtils.whiteTexture; if (m_EyeAdaptation.active) { uberActive = true; autoExposure = m_EyeAdaptation.Prepare(src, uberMaterial); } uberMaterial.SetTexture("_AutoExposure", autoExposure); if (dofActive) { uberActive = true; m_DepthOfField.Prepare(src, uberMaterial, taaActive, m_Taa.jitterVector, m_Taa.model.settings.taaSettings.motionBlending); } if (m_Bloom.active) { uberActive = true; m_Bloom.Prepare(src, uberMaterial, autoExposure); } uberActive |= TryPrepareUberImageEffect(m_ChromaticAberration, uberMaterial); uberActive |= TryPrepareUberImageEffect(m_ColorGrading, uberMaterial); uberActive |= TryPrepareUberImageEffect(m_Vignette, uberMaterial); uberActive |= TryPrepareUberImageEffect(m_UserLut, uberMaterial); var fxaaMaterial = fxaaActive ? m_MaterialFactory.Get("Hidden/Post FX/FXAA") : null; if (fxaaActive) { fxaaMaterial.shaderKeywords = null; TryPrepareUberImageEffect(m_Grain, fxaaMaterial); TryPrepareUberImageEffect(m_Dithering, fxaaMaterial); if (uberActive) { var output = m_RenderTextureFactory.Get(src); Graphics.Blit(src, output, uberMaterial, 0); src = output; } m_Fxaa.Render(src, dst); } else { uberActive |= TryPrepareUberImageEffect(m_Grain, uberMaterial); uberActive |= TryPrepareUberImageEffect(m_Dithering, uberMaterial); if (uberActive) { if (!GraphicsUtils.isLinearColorSpace) { uberMaterial.EnableKeyword("UNITY_COLORSPACE_GAMMA"); } Graphics.Blit(src, dst, uberMaterial, 0); } } if (!uberActive && !fxaaActive) { Graphics.Blit(src, dst); } #if UNITY_EDITOR if (profile.monitors.onFrameEndEditorOnly != null) { Graphics.Blit(dst, destination); var oldRt = RenderTexture.active; profile.monitors.onFrameEndEditorOnly(dst); RenderTexture.active = oldRt; } #endif m_RenderTextureFactory.ReleaseAll(); }
void RenderImage(RenderTexture source, RenderTexture destination) { if (profile == null || m_Camera == null) { Graphics.Blit(source, destination); return; } // Uber shader setup bool uberActive = false; bool dofActive = m_DepthOfField.active && !m_RenderingInSceneView; var uberMaterial = m_MaterialFactory.Get("Hidden/Post FX/Uber Shader"); uberMaterial.shaderKeywords = null; var src = source; var dst = destination; #if UNITY_EDITOR // Render to a dedicated target when monitors are enabled so they can show information // about the final render. // At runtime the output will always be the backbuffer or whatever render target is // currently set on the camera. if (profile.monitors.onFrameEndEditorOnly != null) { dst = m_RenderTextureFactory.Get(src); } #endif Texture autoExposure = GraphicsUtils.whiteTexture; uberMaterial.SetTexture("_AutoExposure", autoExposure); if (dofActive) { uberActive = true; m_DepthOfField.Prepare(src, uberMaterial, false); } if (m_Bloom.active) { uberActive = true; m_Bloom.Prepare(src, uberMaterial, autoExposure); } uberActive |= TryPrepareUberImageEffect(m_ColorGrading, uberMaterial); uberActive |= TryPrepareUberImageEffect(m_Vignette, uberMaterial); if (uberActive) { if (!GraphicsUtils.isLinearColorSpace) { uberMaterial.EnableKeyword("UNITY_COLORSPACE_GAMMA"); } Graphics.Blit(src, dst, uberMaterial, 0); } if (!uberActive) { Graphics.Blit(src, dst); } #if UNITY_EDITOR if (profile.monitors.onFrameEndEditorOnly != null) { Graphics.Blit(dst, destination); var oldRt = RenderTexture.active; profile.monitors.onFrameEndEditorOnly(dst); RenderTexture.active = oldRt; } #endif m_RenderTextureFactory.ReleaseAll(); }