#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using UnityEngine.Rendering.Universal;
using UnityEngine.Serialization;
namespace Golems
{
public class AlbertGhostMemory : ScriptableRendererFeature
{
public bool IsEnabled
{
get
{
return m_IsEnabled;;
}
set
{
m_IsEnabled = value;
}
}
[SerializeField] private bool m_IsEnabled = true;
[FormerlySerializedAs("m_Settings")]
[SerializeField] private AlbertGhostMemorySettings m_FallbackSettings;
[FormerlySerializedAs("m_AlbertGhostMemoryCompositeSettings")]
[SerializeField] private AlbertGhostMemoryCompositeSettings m_FallbackCompositeSettings;
///
/// The material used for the ghost effect.
/// NOTE: the shader is expected to provide the "_PerGhostAlpha" property to set the per object
/// alpha.
///
[SerializeField]
private Material m_GhostMaterial;
///
/// The material used to blur the ghosts.
///
[SerializeField]
private Material m_BlurMaterial;
private AlbertGhostMemoryPass m_Pass;
private AlbertGhostMemorySettings m_SettingsLoader;
private AlbertGhostMemoryCompositeSettings m_CompositeSettingsLoader;
public override void Create()
{
bool forceFallback = false;
#if UNITY_EDITOR
//
// Cannot use Addressables in editor outside of playmode so use fallback
//
forceFallback = !EditorApplication.isPlayingOrWillChangePlaymode;
#endif
//m_SettingsLoader
//m_CompositeSettingsLoader
// This pass uses the depth buffer hence it should be executed after Unity's CopyDepth pass.
m_Pass = new AlbertGhostMemoryPass(RenderPassEvent.AfterRenderingSkybox + 1,
m_GhostMaterial, m_BlurMaterial);
}
private void DebugSetEnabledState(bool state)
{
m_IsEnabled = state;
}
private bool DebugGetEnabledState()
{
return m_IsEnabled;
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
if (m_Pass == null)
{
return;
}
//
// zeroing here in case the pass is not added
//
GhostObjectCollection.Instance.NumberOfObjectsRendered = 0;
m_Pass.SetSettings(m_FallbackSettings, m_FallbackCompositeSettings);
var ghostObjectBehaviours = GhostObjectCollection.Instance.GhostObjectBehaviours;
var render = GhostObjectCollection.Instance.HasSomethingToRender();
if (!render || !m_IsEnabled)
{
return;
}
m_Pass.Setup(renderingData.cameraData.camera, renderer.cameraColorTarget, ghostObjectBehaviours);
renderer.EnqueuePass(m_Pass);
}
}
}