summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Unit/Components/UnitPreprocessing.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/Unit/Components/UnitPreprocessing.cs')
-rw-r--r--Assets/Scripts/Unit/Components/UnitPreprocessing.cs136
1 files changed, 0 insertions, 136 deletions
diff --git a/Assets/Scripts/Unit/Components/UnitPreprocessing.cs b/Assets/Scripts/Unit/Components/UnitPreprocessing.cs
deleted file mode 100644
index 8c56f0b6..00000000
--- a/Assets/Scripts/Unit/Components/UnitPreprocessing.cs
+++ /dev/null
@@ -1,136 +0,0 @@
-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;
-
- #region render textures
- public RenderTexture unitDepthTexture { get; private set; }
- public RenderTexture unitWorldNormalTexture { get; private set; }
- public RenderTexture unitMotionVectorTexture { get; private set; }
- #endregion
-
- private CommandBuffer m_CommandBufferBeforeDepth;
-
- 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_CommandBufferBeforeDepth = new CommandBuffer();
- m_CommandBufferBeforeDepth.name = "Unit Preprocessing(" + owner.unitObj.name + ")";
-
- 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();
- RenderMotionVector();
- MainCamera.Instance.camera.AddCommandBuffer(CameraEvent.BeforeDepthTexture, m_CommandBufferBeforeDepth);
- }
-
- void RenderDepthTexture()
- {
- var cb = m_CommandBufferBeforeDepth;
- 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 RenderMotionVector()
- {
- }
-
- //void RenderWorldNormal()
- //{
- // var cb = m_CommandBufferBeforeDepth;
- // 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_CommandBufferBeforeDepth.ReleaseTemporaryRT(unitDepthTextureID);
-
- MainCamera.Instance.camera.RemoveCommandBuffer(CameraEvent.BeforeDepthTexture, m_CommandBufferBeforeDepth);
- }
-} \ No newline at end of file