summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Unit/Components
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-09-21 19:51:10 +0800
committerchai <chaifix@163.com>2021-09-21 19:51:10 +0800
commitdf1e3842c7571cf6db8f8238b893bde049abf651 (patch)
tree3207c672d3257fa90d3352b59ae62fc0a940ecd4 /Assets/Scripts/Unit/Components
parentb5645c779a3e3c4ca758400cd9a718a7bc0c2bc6 (diff)
*custom rendering pipeline
Diffstat (limited to 'Assets/Scripts/Unit/Components')
-rw-r--r--Assets/Scripts/Unit/Components/UnitLensEffect.cs43
1 files changed, 34 insertions, 9 deletions
diff --git a/Assets/Scripts/Unit/Components/UnitLensEffect.cs b/Assets/Scripts/Unit/Components/UnitLensEffect.cs
index 18328fc8..fee02a7c 100644
--- a/Assets/Scripts/Unit/Components/UnitLensEffect.cs
+++ b/Assets/Scripts/Unit/Components/UnitLensEffect.cs
@@ -5,8 +5,6 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
-//https://docs.unity3d.com/ScriptReference/Rendering.RenderTargetIdentifier.html
-
// Unit效果之一,镜头效果,通过command buffer实现
public class UnitLensEffect : UnitComponent
@@ -17,6 +15,7 @@ public class UnitLensEffect : UnitComponent
private List<LensEffectBase> m_Effects;
+ // 每个角色维护单独的command buffers,而不是共享command buffer
private Dictionary<ERenderingEvent, CommandBuffer> m_InUseCommandBuffers;
private Dictionary<ERenderingEvent, CommandBuffer> m_CachedCommandBuffers;
@@ -82,24 +81,25 @@ public class UnitLensEffect : UnitComponent
{
cb.Value.Clear();
ERenderingEvent re = cb.Key;
- CameraEvent ce = CustomRenderingPipeline.RenderingEventToCameraEvent[re];
+ CameraEvent ce = re.ToCameraEvent();
for (int i = 0; i < m_Effects.Count; ++i)
{
LensEffectBase eff = m_Effects[i];
if (!eff.renderingEvents.HasFlag(re))
continue;
- MethodInfo method = eff.GetType().GetMethod(re.ToString(), BindingFlags.Instance | BindingFlags.Public, null, new Type[] { typeof(LensEffectBase.EStage), typeof(CommandBuffer), typeof(BodyPartRenderer) }, null);
+ MethodInfo method = eff.GetType().GetMethod(re.ToString(), BindingFlags.Instance | BindingFlags.Public, null, new Type[] { typeof(LensEffectBase.EStage), typeof(CommandBuffer) }, null);
if (method == null)
continue;
- method.Invoke(eff, new object[] { LensEffectBase.EStage.Before, cb.Value, null });
+ method.Invoke(eff, new object[] { LensEffectBase.EStage.Before, cb.Value });
for (int j = 0; j < body.renderers.Length; ++j)
{
var renderer = body.renderers[j];
if (renderer == null)
continue;
- method.Invoke(eff, new object[] { LensEffectBase.EStage.Iterate, cb.Value, renderer });
+ eff.curBodypartRenderer = renderer;
+ method.Invoke(eff, new object[] { LensEffectBase.EStage.Iterate, cb.Value });
}
- method.Invoke(eff, new object[] { LensEffectBase.EStage.After, cb.Value, null });
+ method.Invoke(eff, new object[] { LensEffectBase.EStage.After, cb.Value });
}
MainCamera.Instance.camera.AddCommandBuffer(ce, cb.Value);
}
@@ -107,9 +107,34 @@ public class UnitLensEffect : UnitComponent
private void OnRenderUnit()
{
- foreach(var cb in m_InUseCommandBuffers)
+ // 执行每个event的finish
+ foreach (var cb in m_InUseCommandBuffers)
+ {
+ ERenderingEvent re = cb.Key;
+ for (int i = 0; i < m_Effects.Count; ++i)
+ {
+ LensEffectBase eff = m_Effects[i];
+ if (!eff.renderingEvents.HasFlag(re))
+ continue;
+ MethodInfo method = eff.GetType().GetMethod(re.ToString(), BindingFlags.Instance | BindingFlags.Public, null, new Type[] { typeof(LensEffectBase.EStage), typeof(CommandBuffer) }, null);
+ if (method == null)
+ continue;
+ method.Invoke(eff, new object[] { LensEffectBase.EStage.Finished, cb.Value });
+ }
+ }
+
+ for (int i = 0; i < m_Effects.Count; ++i)
+ {
+ LensEffectBase eff = m_Effects[i];
+ MethodInfo method = eff.GetType().GetMethod("OnRenderFinish", BindingFlags.Instance | BindingFlags.Public);
+ if (method == null)
+ continue;
+ method.Invoke(eff, new object[] { });
+ }
+
+ foreach (var cb in m_InUseCommandBuffers)
{
- CameraEvent ce = CustomRenderingPipeline.RenderingEventToCameraEvent[cb.Key];
+ CameraEvent ce = cb.Key.ToCameraEvent();
MainCamera.Instance.camera.RemoveCommandBuffer(ce, cb.Value);
}
var temp = m_CachedCommandBuffers;