First Commit
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
#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;
|
||||
|
||||
/// <summary>
|
||||
/// The material used for the ghost effect.
|
||||
/// NOTE: the shader is expected to provide the "_PerGhostAlpha" property to set the per object
|
||||
/// alpha.
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
private Material m_GhostMaterial;
|
||||
|
||||
/// <summary>
|
||||
/// The material used to blur the ghosts.
|
||||
/// </summary>
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6ff8b75980439440b930f9f955cac1b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 2f4087f258649684b9620322674cf675, type: 3}
|
||||
m_Name: AlbertGhostMemoryCompositeSettings
|
||||
m_EditorClassIdentifier:
|
||||
m_EdgeValue: 0.045
|
||||
m_ChromaticAberration: 0.0005
|
||||
m_ChromaticAberrationSpeed: 0.5
|
||||
m_Brightness: 0.5
|
||||
m_Contrast: 1
|
||||
m_Alpha: 0.5
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1b89dc39ee21574dae98ffc6243bb81
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,481 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using UnityEngine.XR;
|
||||
|
||||
namespace Golems
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods for ScriptableRenderPasses
|
||||
/// </summary>
|
||||
public static class ScriptableRenderPassHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper method to create new Engine material with specified Shader
|
||||
/// </summary>
|
||||
public static void CreateMaterial(string shaderPath, out Material mat)
|
||||
{
|
||||
mat = default;
|
||||
if (TryGetShader(out var shader, shaderPath))
|
||||
{
|
||||
mat = new Material(shader);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Failed to load shader {shaderPath}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper for Shader.Find
|
||||
/// </summary>
|
||||
/// <returns>True if Shader was found and loaded</returns>
|
||||
private static bool TryGetShader(out Shader shader, string path)
|
||||
{
|
||||
shader = default;
|
||||
shader = Shader.Find(path);
|
||||
return shader != null;
|
||||
}
|
||||
}
|
||||
|
||||
public class AlbertGhostMemoryPass : ScriptableRenderPass
|
||||
{
|
||||
private const string k_ProfilerIdent = "GhostPass";
|
||||
|
||||
#region Ident Consts
|
||||
private const string k_AlbertGhostMemoryMaskTex = "_AlbertGhostMemoryMaskTex";
|
||||
private const string k_AlbertGhostMemoryTex = "_AlbertGhostMemoryTex";
|
||||
private const string k_AlbertGhostMemoryBlurredTex = "_AlbertGhostMemoryBlurredTex";
|
||||
private const string k_TempTexGhost = "_TempTexGhost";
|
||||
private const string k_MainText = "_MainTex";
|
||||
private const string k_PerGhostAlphaProperty = "_PerGhostAlpha";
|
||||
#endregion Ident Consts
|
||||
|
||||
#region Render Texture IDs
|
||||
private readonly int m_MaskRenderTexID = Shader.PropertyToID(k_AlbertGhostMemoryMaskTex);
|
||||
private readonly int m_MemoryRenderTexID = Shader.PropertyToID(k_AlbertGhostMemoryTex);
|
||||
private readonly int m_BlurPassRenderTexID = Shader.PropertyToID(k_AlbertGhostMemoryBlurredTex);
|
||||
private readonly int m_TempRenderTexID = Shader.PropertyToID(k_TempTexGhost);
|
||||
#endregion Render Texture IDs
|
||||
|
||||
#region Shader Properties
|
||||
private readonly int k_PerGhostAlphaPropertyId = Shader.PropertyToID(k_PerGhostAlphaProperty);
|
||||
private readonly int m_LightDirectionID = Shader.PropertyToID("_LightDirection");
|
||||
private readonly int m_LightColourID = Shader.PropertyToID("_LightColour");
|
||||
private readonly int m_BlurResolution = Shader.PropertyToID("_BlurResolution");
|
||||
private readonly int m_BlurRadius = Shader.PropertyToID("_BlurRadius");
|
||||
private readonly int m_BlurDirectionX = Shader.PropertyToID("_BlurDirectionX");
|
||||
private readonly int m_BlurDirectionY = Shader.PropertyToID("_BlurDirectionY");
|
||||
#endregion
|
||||
|
||||
private RenderTargetIdentifier m_CameraColorTargetIdent;
|
||||
|
||||
/// <summary>
|
||||
/// All the actively registered GhostObjectBehaviours
|
||||
/// Passed down via GhostObject Collection
|
||||
/// </summary>
|
||||
private IList<GhostObjectBehaviour> m_GhostObjectBehaviours;
|
||||
|
||||
private MaterialPropertyBlock m_MaterialPropertyBlock = new MaterialPropertyBlock();
|
||||
|
||||
private AlbertGhostMemoryCompositeSettings m_AlbertGhostMemoryCompositeSettings;
|
||||
|
||||
private Material m_MemoryMaterial;
|
||||
private Material m_BlurMaterial;
|
||||
|
||||
private Camera m_Camera;
|
||||
private Vector3 m_LightDirection = new Vector3(1.0f, 1.0f, 0.0f);
|
||||
private Color m_LightColour = Color.white;
|
||||
|
||||
/// <summary>
|
||||
/// The uniform Blur texture size, calculated from the current screen size
|
||||
/// </summary>
|
||||
private int m_BlurRes;
|
||||
|
||||
/// <summary>
|
||||
/// Effects how far off centre each Blur sample becomes
|
||||
/// </summary>
|
||||
private float m_BlurRad = 1.5f;
|
||||
|
||||
/// <summary>
|
||||
/// The number of Blur passes performed.
|
||||
/// This effects ALL objects rendered
|
||||
/// </summary>
|
||||
#if UNITY_SWITCH
|
||||
private int m_BlurPasses = 0;
|
||||
#else
|
||||
private int m_BlurPasses = 4;
|
||||
#endif
|
||||
|
||||
//private GameSettings m_GameSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Used in DrawObjectsXYZ. We use this in conjunction with GetSharedMaterials.
|
||||
/// Avoids GC alloc from .sharedMaterials
|
||||
/// </summary>
|
||||
private readonly List<Material> m_SharedMaterials = new List<Material>();
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private readonly HashSet<Renderer> m_EditorLoggedNullMaterialRenderers = new HashSet<Renderer>();
|
||||
#endif
|
||||
|
||||
public bool HasSettings { get; private set; }
|
||||
|
||||
public AlbertGhostMemoryPass(RenderPassEvent whenToInsert,
|
||||
Material memoryMaterial, Material blurMaterial)
|
||||
{
|
||||
renderPassEvent = whenToInsert;
|
||||
|
||||
//
|
||||
// NOTE: the materials are passed in instead of being loaded to avoid the shader not
|
||||
// being available via Shader.Find() when the shader has changed and Unity first opens.
|
||||
//
|
||||
m_MemoryMaterial = memoryMaterial; //TODO TOBY: replace with one found on the object / the test fake TestFakeAlvertGhostMemoryCmdShader
|
||||
m_BlurMaterial = blurMaterial;
|
||||
|
||||
// grab the game setting for blur passes and use it here.
|
||||
|
||||
//Disabled for the sample
|
||||
//GameSettings.GetSlowStartSystem(HandleGameSettings, out m_GameSettings, true);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
private void HandleGameSettings(GameSettings system, SlowSystemState state)
|
||||
{
|
||||
m_GameSettings = system;
|
||||
if (system == null) return;
|
||||
|
||||
if (!system.TryGetValue(GameSettingsKeys.k_NumGhostBlurPasses, out int value)) return;
|
||||
|
||||
m_BlurPasses = value;
|
||||
|
||||
m_GameSettings.AddListenOnGameSettingChange(GameSettingsKeys.k_NumGhostBlurPasses, OnSettingChanged, true);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
void OnSettingChanged( int value)
|
||||
{
|
||||
m_BlurPasses = value;
|
||||
}
|
||||
|
||||
public void SetSettings(AlbertGhostMemorySettings settings, AlbertGhostMemoryCompositeSettings albertGhostMemoryCompositeSettings)
|
||||
{
|
||||
m_LightColour = settings.LightColour;
|
||||
m_LightDirection = settings.LightDirection;
|
||||
m_BlurRad = settings.BlurRadius;
|
||||
m_BlurRes = settings.BlurTextureResolution;
|
||||
|
||||
m_AlbertGhostMemoryCompositeSettings = albertGhostMemoryCompositeSettings;
|
||||
|
||||
HasSettings = true;
|
||||
}
|
||||
|
||||
#region ScriptableRenderPass
|
||||
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
|
||||
{
|
||||
if (!HasSettings)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Attempt to make RTs for XR, otherwise use Default Settings
|
||||
//
|
||||
if (!ConfigureTemporaryRenderTexturesForXR(in cmd)) ConfigureTemporaryRenderTextures(in cmd);
|
||||
}
|
||||
|
||||
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
|
||||
{
|
||||
if (!HasSettings)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//
|
||||
// Reset the number of objects renderer, this is a new pass
|
||||
//
|
||||
GhostObjectCollection.Instance.NumberOfObjectsRendered = 0;
|
||||
var cmd = CommandBufferPool.Get(k_ProfilerIdent);
|
||||
cmd.Clear();
|
||||
|
||||
SetAllShaderParameters(in cmd);
|
||||
|
||||
DrawObjectsDefault(in cmd);
|
||||
|
||||
//
|
||||
// Only bother we the rest of the process if we actually
|
||||
// rendered anything using default materials
|
||||
//
|
||||
if (GhostObjectCollection.Instance.NumberOfObjectsRendered > 0)
|
||||
{
|
||||
DrawObjectsMemory(in cmd);
|
||||
BlurMask(in cmd);
|
||||
|
||||
// make sure to set the render target back to the main camera!
|
||||
CoreUtils.SetRenderTarget(cmd, m_CameraColorTargetIdent);
|
||||
context.ExecuteCommandBuffer(cmd);
|
||||
}
|
||||
|
||||
//cmd.Clear();
|
||||
CommandBufferPool.Release(cmd);
|
||||
}
|
||||
|
||||
public override void FrameCleanup(CommandBuffer cmd)
|
||||
{
|
||||
if (!HasSettings)
|
||||
{
|
||||
return;
|
||||
}
|
||||
cmd.ReleaseTemporaryRT(m_MemoryRenderTexID);
|
||||
cmd.ReleaseTemporaryRT(m_MaskRenderTexID);
|
||||
cmd.ReleaseTemporaryRT(m_BlurPassRenderTexID);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void Setup(Camera camera, RenderTargetIdentifier cameraColorTargetIdent, List<GhostObjectBehaviour> ghostObjectBehaviours)
|
||||
{
|
||||
m_Camera = camera;
|
||||
m_CameraColorTargetIdent = cameraColorTargetIdent;
|
||||
m_GhostObjectBehaviours = ghostObjectBehaviours;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets Global and local variables used
|
||||
/// across various shaders in the process
|
||||
/// </summary>
|
||||
private void SetAllShaderParameters(in CommandBuffer commandBuffer)
|
||||
{
|
||||
commandBuffer.SetGlobalVector(m_LightDirectionID, m_LightDirection);
|
||||
commandBuffer.SetGlobalColor(m_LightColourID, m_LightColour);
|
||||
commandBuffer.SetGlobalFloat(m_BlurResolution, m_BlurRes);
|
||||
commandBuffer.SetGlobalFloat(m_BlurRadius, m_BlurRad);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw all GhostObjects either with
|
||||
/// Default materials or with the Ghost Material
|
||||
/// </summary>
|
||||
private void DrawAllObjects(in CommandBuffer commandBuffer, bool useMemoryMaterial = false)
|
||||
{
|
||||
if (m_GhostObjectBehaviours == null) return;
|
||||
|
||||
for (int i = 0, counti = m_GhostObjectBehaviours.Count; i < counti; ++i)
|
||||
{
|
||||
var ghostObjectBehaviour = m_GhostObjectBehaviours[i];
|
||||
if (ghostObjectBehaviour == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var ghostObject = ghostObjectBehaviour.GhostObject;
|
||||
if (ghostObject == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var renderers = ghostObject.Renderers;
|
||||
if (renderers == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var alpha = ghostObjectBehaviour.Alpha;
|
||||
|
||||
Debug.Log("Alpha Ghost:" + alpha);
|
||||
|
||||
if (!ghostObjectBehaviour.IgnoreGlobalAlpha)
|
||||
{
|
||||
alpha *= m_AlbertGhostMemoryCompositeSettings.Alpha;
|
||||
}
|
||||
|
||||
//
|
||||
// No need to render anything if the Alpha for this GhostObject is 0. Although the final composite will not
|
||||
// show anything we're wasting Draw calls drawing the Lit and Unlit(mask) versions of the Ghost Object Behaviours
|
||||
//
|
||||
if (alpha <= 0.0f) continue;
|
||||
|
||||
//
|
||||
// Let everything know we're rendering something this Ghost pass
|
||||
//
|
||||
++GhostObjectCollection.Instance.NumberOfObjectsRendered;
|
||||
|
||||
if (ghostObjectBehaviour.ReplacementMemoryMaterials != null)
|
||||
{
|
||||
DrawGhostRenderer(commandBuffer, renderers, alpha, useMemoryMaterial, ghostObjectBehaviour.ReplacementMemoryMaterials);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawGhostRenderer(commandBuffer, renderers, alpha, useMemoryMaterial);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawGhostRenderer(CommandBuffer commandBuffer, Renderer[] renderers, float alpha,
|
||||
bool useMemoryMaterial, IReadOnlyList<Material> replacementMemoryMaterials = null)
|
||||
{
|
||||
|
||||
Debug.Log("Ghost Renderer " + renderers.Length);
|
||||
for (int j = 0, countj = renderers.Length; j < countj; ++j)
|
||||
{
|
||||
var renderer = renderers[j];
|
||||
if (renderer == null) continue;
|
||||
|
||||
m_MaterialPropertyBlock.SetFloat(k_PerGhostAlphaPropertyId, alpha);
|
||||
renderer.SetPropertyBlock(m_MaterialPropertyBlock);
|
||||
|
||||
m_SharedMaterials.Clear();
|
||||
renderer.GetSharedMaterials(m_SharedMaterials);
|
||||
if (m_SharedMaterials.Count > 0)
|
||||
{
|
||||
//for (int m = 0, countm = materials.Length; m < countm; ++m)
|
||||
for (int m = m_SharedMaterials.Count -1, countm = 0; m >= countm; --m)
|
||||
{
|
||||
if (useMemoryMaterial)
|
||||
{
|
||||
if (replacementMemoryMaterials != null && replacementMemoryMaterials.Count > 0 && replacementMemoryMaterials[m] != null)
|
||||
{
|
||||
commandBuffer.DrawRenderer(renderer,
|
||||
replacementMemoryMaterials[m], m,
|
||||
0);
|
||||
}
|
||||
else
|
||||
{
|
||||
commandBuffer.DrawRenderer(renderer,
|
||||
m_MemoryMaterial, m,
|
||||
0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_SharedMaterials[m] == null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!m_EditorLoggedNullMaterialRenderers.Contains(renderer))
|
||||
{
|
||||
Debug.LogErrorFormat(renderer, "AlbertGhostMemory: renderer {0} with null material",
|
||||
renderer.name);
|
||||
m_EditorLoggedNullMaterialRenderers.Add(renderer);
|
||||
}
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
commandBuffer.DrawRenderer(renderer,
|
||||
m_SharedMaterials[m], m,
|
||||
0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (replacementMemoryMaterials != null && replacementMemoryMaterials.Count > 0 && replacementMemoryMaterials[0] != null)
|
||||
{
|
||||
commandBuffer.DrawRenderer(renderer,
|
||||
useMemoryMaterial ? replacementMemoryMaterials[0] : renderer.sharedMaterial);
|
||||
}
|
||||
else
|
||||
{
|
||||
commandBuffer.DrawRenderer(renderer,
|
||||
useMemoryMaterial ? m_MemoryMaterial : renderer.sharedMaterial);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw all GhostObjects using their default material/s
|
||||
/// </summary>
|
||||
private void DrawObjectsDefault(in CommandBuffer commandBuffer)
|
||||
{
|
||||
CoreUtils.SetRenderTarget(commandBuffer, m_MemoryRenderTexID, ClearFlag.All, Color.clear);
|
||||
commandBuffer.ClearRenderTarget(true, true, Color.clear);
|
||||
DrawAllObjects(in commandBuffer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw all GhostObjects using the Ghost/Memory material
|
||||
/// </summary>
|
||||
private void DrawObjectsMemory(in CommandBuffer commandBuffer)
|
||||
{
|
||||
CoreUtils.SetRenderTarget(commandBuffer, m_MaskRenderTexID, ClearFlag.All, Color.clear);
|
||||
commandBuffer.ClearRenderTarget(true, true, Color.clear);
|
||||
DrawAllObjects(in commandBuffer, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the Blur mask RT. This Blurs all the GhostObjects
|
||||
/// </summary>
|
||||
private void BlurMask(in CommandBuffer commandBuffer)
|
||||
{
|
||||
commandBuffer.Blit(m_MaskRenderTexID, m_BlurPassRenderTexID);
|
||||
|
||||
for (int i = 0; i < m_BlurPasses; ++i)
|
||||
{
|
||||
commandBuffer.SetGlobalFloat(m_BlurDirectionX, 0);
|
||||
commandBuffer.SetGlobalFloat(m_BlurDirectionY, 1);
|
||||
|
||||
commandBuffer.SetGlobalTexture(k_MainText, m_BlurPassRenderTexID);
|
||||
commandBuffer.Blit(m_BlurPassRenderTexID, m_TempRenderTexID,
|
||||
m_BlurMaterial, 0);
|
||||
|
||||
commandBuffer.SetGlobalFloat(m_BlurDirectionX, 1);
|
||||
commandBuffer.SetGlobalFloat(m_BlurDirectionY, 0);
|
||||
|
||||
commandBuffer.SetGlobalTexture(k_MainText, m_TempRenderTexID);
|
||||
commandBuffer.Blit(m_TempRenderTexID, m_BlurPassRenderTexID,
|
||||
m_BlurMaterial, 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configure Temporary RTs for XR
|
||||
/// Relies on ENABLE_VR
|
||||
/// </summary>
|
||||
/// <param name="cmd">SRF CommandBuffer</param>
|
||||
/// <returns>True if RTs were setup using XRSettings, Otherwise False.</returns>
|
||||
private bool ConfigureTemporaryRenderTexturesForXR(in CommandBuffer cmd)
|
||||
{
|
||||
#if ENABLE_VR
|
||||
if (!XRSettings.enabled) return false;
|
||||
var renderTextureDescriptor = XRSettings.eyeTextureDesc;
|
||||
cmd.GetTemporaryRT(m_MemoryRenderTexID, renderTextureDescriptor, FilterMode.Bilinear);
|
||||
cmd.GetTemporaryRT(m_MaskRenderTexID, renderTextureDescriptor, FilterMode.Bilinear);
|
||||
|
||||
renderTextureDescriptor.depthBufferBits = 0;
|
||||
renderTextureDescriptor.width = renderTextureDescriptor.height = m_BlurRes;
|
||||
|
||||
cmd.GetTemporaryRT(m_BlurPassRenderTexID, renderTextureDescriptor, FilterMode.Bilinear);
|
||||
cmd.GetTemporaryRT(m_TempRenderTexID, renderTextureDescriptor, FilterMode.Bilinear);
|
||||
return true;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configure Temporary RTs for SRF.
|
||||
/// </summary>
|
||||
/// <param name="cmd">SRF CommandBuffer</param>
|
||||
private void ConfigureTemporaryRenderTextures(in CommandBuffer cmd)
|
||||
{
|
||||
#if UNITY_SWITCH
|
||||
var width = 1280;
|
||||
var height = 720;
|
||||
#else
|
||||
var width = m_Camera.scaledPixelWidth;
|
||||
var height = m_Camera.scaledPixelHeight;
|
||||
#endif
|
||||
var aa = Mathf.Max(1, QualitySettings.antiAliasing);
|
||||
cmd.GetTemporaryRT(m_MemoryRenderTexID, width, height, 24, FilterMode.Bilinear, RenderTextureFormat.ARGB32,
|
||||
RenderTextureReadWrite.Default, aa);
|
||||
cmd.GetTemporaryRT(m_MaskRenderTexID, width >> 1, height >> 1, 0, FilterMode.Bilinear, RenderTextureFormat.ARGB32,
|
||||
RenderTextureReadWrite.Default, aa);
|
||||
|
||||
cmd.GetTemporaryRT(m_BlurPassRenderTexID, m_BlurRes, m_BlurRes, 0, FilterMode.Bilinear);
|
||||
cmd.GetTemporaryRT(m_TempRenderTexID, m_BlurRes, m_BlurRes, 0, FilterMode.Bilinear);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d65d0b4fad922724b96ef94f9d8b5b8b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,57 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Golems
|
||||
{
|
||||
[CreateAssetMenu(fileName = "New AlbertGhostMemorySettings",
|
||||
menuName = "Golems/Scriptable Render Features/AlbertGhostMemorySettings")]
|
||||
public class AlbertGhostMemorySettings : ScriptableObject
|
||||
{
|
||||
[SerializeField] private Vector3 m_LightDirection;
|
||||
|
||||
public Vector3 LightDirection
|
||||
{
|
||||
get => m_LightDirection;
|
||||
set => m_LightDirection = value;
|
||||
}
|
||||
|
||||
[SerializeField] private Color m_LightColour = Color.white;
|
||||
|
||||
public Color LightColour
|
||||
{
|
||||
get => m_LightColour;
|
||||
set => m_LightColour = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effects how far off centre each Blur sample becomes
|
||||
/// </summary>
|
||||
[Tooltip("Effects how far off centre each Blur sample becomes. Note, the bigger the number, the bigger the pixelation")]
|
||||
[Range(0.01f, 10.0f)][SerializeField] private float m_BlurRadius = .5f;
|
||||
public float BlurRadius => m_BlurRadius;
|
||||
|
||||
/// <summary>
|
||||
/// The number of Blur passes performed.
|
||||
/// This effects ALL objects rendered
|
||||
/// </summary>
|
||||
[Tooltip("How many times we Blur all the objects. Note, the bigger the number, the bigger the performance hit")]
|
||||
[Range(1, 10)][SerializeField] private int m_BlurPasses = 4;
|
||||
public int BlurPasses => m_BlurPasses;
|
||||
|
||||
/// <summary>
|
||||
/// Index into the m_BlurTextureSizes
|
||||
/// </summary>
|
||||
[Range(0,4)] [SerializeField] private int m_BlurTextureSize = 3;
|
||||
|
||||
/// <summary>
|
||||
/// Texture size of the blur textures
|
||||
/// </summary>
|
||||
private int[] m_BlurTextureSizes = new int[5] { 128, 256, 512, 1024, 2048 };
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current Blur Texture resolution driven by m_BlurTextureSize
|
||||
/// </summary>
|
||||
public int BlurTextureResolution => m_BlurTextureSizes[
|
||||
Mathf.Max(0, Mathf.Min(m_BlurTextureSize, m_BlurTextureSizes.Length - 1))];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2ea357b0ff81244b8a3573234681896
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
/*
|
||||
using System;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace Golems
|
||||
{
|
||||
[Serializable]
|
||||
public class AlbertGhostMemorySettingsRef : AssetReferenceT<AlbertGhostMemorySettings>
|
||||
{
|
||||
public AlbertGhostMemorySettingsRef(string guid) : base(guid)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5fe03499252946428c51d21897ebe3ce
|
||||
timeCreated: 1645029849
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
/*
|
||||
using RogueUtils.Data;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Golems
|
||||
{
|
||||
public class GhostMemoryLightDirection : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Light m_Light;
|
||||
[SerializeField] private Vector3 m_LightDirectionReference;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Debug.Assert(m_Light != null);
|
||||
Debug.Assert(m_LightDirectionReference != null);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
m_LightDirectionReference.variable.Value = (m_Light.transform.rotation * Vector3.forward).normalized;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 085bb191568545a4eaafe27762a10deb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user