using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.Universal.Internal;
namespace UnityEngine.Rendering.Universal
{
///
/// Type acts as wrapper for post process passes. Can we be recreated and destroyed at any point during runtime with post process data.
///
internal struct PostProcessPasses : IDisposable
{
ColorGradingLutPass m_ColorGradingLutPass;
PostProcessPass m_PostProcessPass;
PostProcessPass m_FinalPostProcessPass;
RenderTargetHandle m_AfterPostProcessColor;
RenderTargetHandle m_ColorGradingLut;
PostProcessData m_RendererPostProcessData;
PostProcessData m_CurrentPostProcessData;
Material m_BlitMaterial;
public ColorGradingLutPass colorGradingLutPass { get => m_ColorGradingLutPass; }
public PostProcessPass postProcessPass { get => m_PostProcessPass; }
public PostProcessPass finalPostProcessPass { get => m_FinalPostProcessPass; }
public RenderTargetHandle afterPostProcessColor { get => m_AfterPostProcessColor; }
public RenderTargetHandle colorGradingLut { get => m_ColorGradingLut; }
public bool isCreated { get => m_CurrentPostProcessData != null; }
public PostProcessPasses(PostProcessData rendererPostProcessData, Material blitMaterial)
{
m_ColorGradingLutPass = null;
m_PostProcessPass = null;
m_FinalPostProcessPass = null;
m_AfterPostProcessColor = new RenderTargetHandle();
m_ColorGradingLut = new RenderTargetHandle();
m_CurrentPostProcessData = null;
m_AfterPostProcessColor.Init("_AfterPostProcessTexture");
m_ColorGradingLut.Init("_InternalGradingLut");
m_RendererPostProcessData = rendererPostProcessData;
m_BlitMaterial = blitMaterial;
Recreate(rendererPostProcessData);
}
///
/// Recreates post process passes with supplied data. If already contains valid post process passes, they will be replaced by new ones.
///
/// Resources used for creating passes. In case of the null, no passes will be created.
public void Recreate(PostProcessData data)
{
if (m_RendererPostProcessData)
data = m_RendererPostProcessData;
if (data == m_CurrentPostProcessData)
return;
if (m_CurrentPostProcessData != null)
{
m_ColorGradingLutPass?.Cleanup();
m_PostProcessPass?.Cleanup();
m_FinalPostProcessPass?.Cleanup();
// We need to null post process passes to avoid using them
m_ColorGradingLutPass = null;
m_PostProcessPass = null;
m_FinalPostProcessPass = null;
m_CurrentPostProcessData = null;
}
if (data != null)
{
m_ColorGradingLutPass = new ColorGradingLutPass(RenderPassEvent.BeforeRenderingPrePasses, data);
m_PostProcessPass = new PostProcessPass(RenderPassEvent.BeforeRenderingPostProcessing, data, m_BlitMaterial);
m_FinalPostProcessPass = new PostProcessPass(RenderPassEvent.AfterRenderingPostProcessing, data, m_BlitMaterial);
m_CurrentPostProcessData = data;
}
}
public void Dispose()
{
// always dispose unmanaged resources
m_ColorGradingLutPass?.Cleanup();
m_PostProcessPass?.Cleanup();
m_FinalPostProcessPass?.Cleanup();
}
}
}