summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Unit
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/Unit')
-rw-r--r--Assets/Scripts/Unit/AI/Actions.meta8
-rw-r--r--Assets/Scripts/Unit/AI/Conditionals.meta8
-rw-r--r--Assets/Scripts/Unit/Components/UnitLensEffect.cs17
-rw-r--r--Assets/Scripts/Unit/Components/UnitPreprocessing.cs128
-rw-r--r--Assets/Scripts/Unit/Components/UnitPreprocessing.cs.meta11
-rw-r--r--Assets/Scripts/Unit/Controller/PCController.cs7
-rw-r--r--Assets/Scripts/Unit/Controller/UnitController.cs7
-rw-r--r--Assets/Scripts/Unit/LensEffect/LensEffect_Buzz.cs41
-rw-r--r--Assets/Scripts/Unit/LensEffect/LensEffect_Buzz.cs.meta11
-rw-r--r--Assets/Scripts/Unit/LensEffect/LensEffect_Dash.cs3
10 files changed, 208 insertions, 33 deletions
diff --git a/Assets/Scripts/Unit/AI/Actions.meta b/Assets/Scripts/Unit/AI/Actions.meta
deleted file mode 100644
index 9b4ad463..00000000
--- a/Assets/Scripts/Unit/AI/Actions.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 971e9d55b8bc0894eb6a110fb962000b
-folderAsset: yes
-DefaultImporter:
- externalObjects: {}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Scripts/Unit/AI/Conditionals.meta b/Assets/Scripts/Unit/AI/Conditionals.meta
deleted file mode 100644
index 70a86da5..00000000
--- a/Assets/Scripts/Unit/AI/Conditionals.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 85b7e0c7ed1d12f42a5178bfbf3d934c
-folderAsset: yes
-DefaultImporter:
- externalObjects: {}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Scripts/Unit/Components/UnitLensEffect.cs b/Assets/Scripts/Unit/Components/UnitLensEffect.cs
index a3c5d2c8..ef8e6ee6 100644
--- a/Assets/Scripts/Unit/Components/UnitLensEffect.cs
+++ b/Assets/Scripts/Unit/Components/UnitLensEffect.cs
@@ -60,19 +60,20 @@ public class UnitLensEffect : UnitComponent
}
MainCamera.Instance.customRenderingPipeline.onPreCull += OnWillRenderUnit;
- MainCamera.Instance.customRenderingPipeline.onPostRender += OnRenderUnit;
-
- /////
+ MainCamera.Instance.customRenderingPipeline.onPostRender += OnRenderUnit;
+
+ /////
//m_Effects.Add(new LensEffect_MotionBlur());
- //m_Effects.Add(new LensEffect_BlurRim(Color.blue));
+ //m_Effects.Add(new LensEffect_BlurRim(Color.blue));
+ m_Effects.Add(new LensEffect_Buzz());
}
public override void Release()
- {
- base.Release();
-
- MainCamera.Instance.customRenderingPipeline.onPreRender -= OnWillRenderUnit;
+ {
+ MainCamera.Instance.customRenderingPipeline.onPreCull -= OnWillRenderUnit;
MainCamera.Instance.customRenderingPipeline.onPostRender -= OnRenderUnit;
+
+ base.Release();
}
private void OnWillRenderUnit()
diff --git a/Assets/Scripts/Unit/Components/UnitPreprocessing.cs b/Assets/Scripts/Unit/Components/UnitPreprocessing.cs
new file mode 100644
index 00000000..30357615
--- /dev/null
+++ b/Assets/Scripts/Unit/Components/UnitPreprocessing.cs
@@ -0,0 +1,128 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.Rendering;
+
+// 给每个角色准备一些特殊的前置渲染
+public class UnitPreprocessing : UnitComponent
+{
+ [Flags]
+ public enum EUnitPreprocessing
+ {
+ None ,
+ DepthTexture, // Unit Depth Texture
+ WorldNormalTexture, // Unit World Normal Texture
+ }
+
+ public EUnitPreprocessing preprocessing;
+
+ public RenderTexture unitDepthTexture { get; private set; }
+ public RenderTexture unitWorldNormalTexture { get; private set; }
+
+ private CommandBuffer m_CBBeforeDepthTexture;
+
+ private Material m_MaterialDepth;
+
+ public override void Initialize()
+ {
+ base.Initialize();
+ }
+
+ public override void OnPostInitialize()
+ {
+ base.OnPostInitialize();
+
+ MainCamera.Instance.customRenderingPipeline.onPreCull += OnWillRenderUnit;
+ MainCamera.Instance.customRenderingPipeline.onPostRender += OnRenderUnit;
+
+ m_CBBeforeDepthTexture = new CommandBuffer();
+
+ PrepareRenderTextures();
+ PrepareMaterials();
+ }
+
+ void PrepareRenderTextures()
+ {
+ int unitHash = owner.GetHashCode();
+
+ int width = MainCamera.Instance.camera.pixelWidth;
+ int height = MainCamera.Instance.camera.pixelHeight;
+ unitDepthTexture = new RenderTexture(width, height, 24, RenderTextureFormat.Depth, RenderTextureReadWrite.Linear);
+ unitDepthTexture.name = "UnitDepthTexture_" + owner.GetHashCode();
+ }
+
+ void PrepareMaterials()
+ {
+ m_MaterialDepth = new Material(Shader.Find(StaticDefine.shaders[EShader.UnitDepth].name));
+ }
+
+ public override void OnUpdate()
+ {
+ base.OnUpdate();
+ }
+
+ public override void Release()
+ {
+ MainCamera.Instance.customRenderingPipeline.onPreCull -= OnWillRenderUnit;
+ MainCamera.Instance.customRenderingPipeline.onPostRender -= OnRenderUnit;
+
+ base.Release();
+ }
+
+ private void OnWillRenderUnit()
+ {
+ RenderDepthTexture();
+ //RenderWorldNormal();
+
+ MainCamera.Instance.camera.AddCommandBuffer(CameraEvent.BeforeDepthTexture, m_CBBeforeDepthTexture);
+ }
+
+ void RenderDepthTexture()
+ {
+ var cb = m_CBBeforeDepthTexture;
+ cb.Clear();
+ cb.SetRenderTarget(unitDepthTexture);
+ cb.ClearRenderTarget(true, true, new Color(0, 0, 0, 0));
+
+ cb.SetGlobalVector("unity_LightShadowBias", Vector4.zero);
+
+ foreach (var r in GetRenderers())
+ {
+ BodyPartRenderer br = r as BodyPartRenderer;
+ if (br == null)
+ continue;
+ Renderer renderer = br.renderer as Renderer;
+ if (renderer == null)
+ continue;
+ cb.DrawRenderer(renderer, m_MaterialDepth);
+ }
+ }
+
+ //void RenderWorldNormal()
+ //{
+ // var cb = m_CBBeforeDepthTexture;
+ // cb.Clear();
+ // cb.GetTemporaryRT(unitWorldNormalTextureID, -1, -1, 24, FilterMode.Point, RenderTextureFormat.RG16, RenderTextureReadWrite.Linear);
+ // cb.SetRenderTarget(unitWorldNormalTextureID);
+ // cb.ClearRenderTarget(true, true, new Color(0, 0, 0, 0));
+ //}
+
+ IEnumerable GetRenderers()
+ {
+ IBodyRendererAgent body = owner.unitRender.body;
+ if (body == null || body.renderers == null || body.renderers.Length == 0)
+ yield break;
+ for (int j = 0; j < body.renderers.Length; ++j)
+ {
+ yield return body.renderers[j];
+ }
+ }
+
+ private void OnRenderUnit()
+ {
+ //m_CBBeforeDepthTexture.ReleaseTemporaryRT(unitDepthTextureID);
+
+ MainCamera.Instance.camera.RemoveCommandBuffer(CameraEvent.BeforeDepthTexture, m_CBBeforeDepthTexture);
+ }
+} \ No newline at end of file
diff --git a/Assets/Scripts/Unit/Components/UnitPreprocessing.cs.meta b/Assets/Scripts/Unit/Components/UnitPreprocessing.cs.meta
new file mode 100644
index 00000000..734df2f2
--- /dev/null
+++ b/Assets/Scripts/Unit/Components/UnitPreprocessing.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 1998e85be970d1541843ff6166f6c771
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Unit/Controller/PCController.cs b/Assets/Scripts/Unit/Controller/PCController.cs
index 90520017..35645d57 100644
--- a/Assets/Scripts/Unit/Controller/PCController.cs
+++ b/Assets/Scripts/Unit/Controller/PCController.cs
@@ -11,8 +11,7 @@ public class PCController : UnitController
#region Unit的三种效果
public UnitAfterImage unitAfterImage;
public UnitImageEffect unitImageEffect;
- public UnitLensEffect unitLensEffect;
- #endregion
+ #endregion
public override UnitType type { get { return UnitType.PC; } }
@@ -36,10 +35,6 @@ public class PCController : UnitController
unitImageEffect = GetOrAddUnitComponent<UnitImageEffect>();
unitImageEffect.Initialize();
-
- unitLensEffect = GetOrAddUnitComponent<UnitLensEffect>();
- unitLensEffect.Initialize();
-
}
public override void Update()
diff --git a/Assets/Scripts/Unit/Controller/UnitController.cs b/Assets/Scripts/Unit/Controller/UnitController.cs
index c75b32b3..971eea62 100644
--- a/Assets/Scripts/Unit/Controller/UnitController.cs
+++ b/Assets/Scripts/Unit/Controller/UnitController.cs
@@ -44,6 +44,8 @@ public class UnitController : MonoBehaviour/*, Interactable*/
public UnitLensEffect unitLensEffect;
+ public UnitPreprocessing unitPreprocessing;
+
public GameObject unitObj; // 角色模型
protected List<UnitComponent> unitComponents;
@@ -184,7 +186,10 @@ public class UnitController : MonoBehaviour/*, Interactable*/
unitLensEffect.Initialize();
unitDetail = gameObject.GetComponentInChildren<UnitDetail>();
- }
+
+ unitPreprocessing = GetOrAddUnitComponent<UnitPreprocessing>();
+ unitPreprocessing.Initialize();
+ }
private void OnPostInitailize()
{
diff --git a/Assets/Scripts/Unit/LensEffect/LensEffect_Buzz.cs b/Assets/Scripts/Unit/LensEffect/LensEffect_Buzz.cs
new file mode 100644
index 00000000..55e8c772
--- /dev/null
+++ b/Assets/Scripts/Unit/LensEffect/LensEffect_Buzz.cs
@@ -0,0 +1,41 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.Rendering;
+
+// 蜂鸣
+public class LensEffect_Buzz : LensEffectBase
+{
+ public override ERenderingEvent renderingEvents => ERenderingEvent.AfterForwardAlpha;
+
+ public LensEffect_Buzz() : base()
+ {
+
+ }
+
+ public override void AfterForwardAlpha(EStage stage, CommandBuffer cb)
+ {
+ if(stage == EStage.Before)
+ {
+ Before(cb);
+ }
+ else if(stage == EStage.After)
+ {
+ After(cb);
+ }
+ }
+
+ void Before(CommandBuffer cb)
+ {
+ MaterialEntry buzz = ClaimMaterial(StaticDefine.shaders[EShader.Buzz].name);
+
+ cb.SetGlobalTexture("_UnitDepthTexture", owner.unitPreprocessing.unitDepthTexture);
+ cb.Blit(BuiltinRenderTextureType.CameraTarget, BuiltinRenderTextureType.CameraTarget, buzz.material);
+ }
+
+ void After(CommandBuffer cb)
+ {
+
+ }
+
+} \ No newline at end of file
diff --git a/Assets/Scripts/Unit/LensEffect/LensEffect_Buzz.cs.meta b/Assets/Scripts/Unit/LensEffect/LensEffect_Buzz.cs.meta
new file mode 100644
index 00000000..24b527a2
--- /dev/null
+++ b/Assets/Scripts/Unit/LensEffect/LensEffect_Buzz.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: d76bd4e3298fc574e9f90efa626f6e17
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Unit/LensEffect/LensEffect_Dash.cs b/Assets/Scripts/Unit/LensEffect/LensEffect_Dash.cs
index 84f8edcb..61bb08fa 100644
--- a/Assets/Scripts/Unit/LensEffect/LensEffect_Dash.cs
+++ b/Assets/Scripts/Unit/LensEffect/LensEffect_Dash.cs
@@ -19,12 +19,11 @@ public class LensEffect_Dash : LensEffectBase
public LensEffect_Dash(Color color, float lifeTime, float angle, UnitSnapshotInfo snapshot) : base()
{
rimColor = color;
- tempID = Shader.PropertyToID("_BlurRim_RT0");
+ tempID = Shader.PropertyToID("RT_Dash");
this.lifeTime = lifeTime;
trs = snapshot.trs;
this.snapshot = UnitManager.Instance.ClaimSnapshotSolo(snapshot);
this.angle = angle;
-
}
public override void AfterForwardOpaque(EStage stage, CommandBuffer cb)