diff options
author | chai <chaifix@163.com> | 2021-10-01 10:04:00 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-01 10:04:00 +0800 |
commit | f0ae9393da021fe16af32f7ae1a3245f27050f92 (patch) | |
tree | eb3618a8661c6771098cdfe796bdff50b4e75328 /Assets/Scripts | |
parent | 5b19af7f51ad4504fc426b8387442f6b868b5f61 (diff) |
*misc
Diffstat (limited to 'Assets/Scripts')
-rw-r--r-- | Assets/Scripts/Drone.meta | 8 | ||||
-rw-r--r-- | Assets/Scripts/Editor/MainCameraEditor.cs | 5 | ||||
-rw-r--r-- | Assets/Scripts/Managers/Physics.meta | 8 | ||||
-rw-r--r-- | Assets/Scripts/Props.meta | 8 | ||||
-rw-r--r-- | Assets/Scripts/Rendering/CustomLight.cs | 46 | ||||
-rw-r--r-- | Assets/Scripts/Rendering/CustomLight.cs.meta | 11 | ||||
-rw-r--r-- | Assets/Scripts/Rendering/CustomRenderingPipeline.cs | 19 | ||||
-rw-r--r-- | Assets/Scripts/Robot.meta | 8 | ||||
-rw-r--r-- | Assets/Scripts/Scene.meta (renamed from Assets/Scripts/Curve3D.meta) | 2 | ||||
-rw-r--r-- | Assets/Scripts/Unit/AI/Actions.meta | 8 | ||||
-rw-r--r-- | Assets/Scripts/Unit/AI/Conditionals.meta | 8 | ||||
-rw-r--r-- | Assets/Scripts/Unit/Components/UnitPreprocessing.cs | 77 | ||||
-rw-r--r-- | Assets/Scripts/Unit/Components/UnitState/PCState.cs | 2 | ||||
-rw-r--r-- | Assets/Scripts/Unit/LensEffect/LensEffect_Buzz.cs | 6 | ||||
-rw-r--r-- | Assets/Scripts/Unit/LensEffect/LensEffect_Dash.cs | 96 |
15 files changed, 157 insertions, 155 deletions
diff --git a/Assets/Scripts/Drone.meta b/Assets/Scripts/Drone.meta deleted file mode 100644 index 694cff70..00000000 --- a/Assets/Scripts/Drone.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: ec3412151f8a72a41b2ed21316763399 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Editor/MainCameraEditor.cs b/Assets/Scripts/Editor/MainCameraEditor.cs index 437303a0..f2ad9479 100644 --- a/Assets/Scripts/Editor/MainCameraEditor.cs +++ b/Assets/Scripts/Editor/MainCameraEditor.cs @@ -1,7 +1,4 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEditor; +using UnityEditor; [CustomEditor(typeof(MainCamera))] public class MainCameraEditor : Editor diff --git a/Assets/Scripts/Managers/Physics.meta b/Assets/Scripts/Managers/Physics.meta deleted file mode 100644 index 2296b3f8..00000000 --- a/Assets/Scripts/Managers/Physics.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 603d4624aaedd794cb89497954a83f4a -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Props.meta b/Assets/Scripts/Props.meta deleted file mode 100644 index bb96602e..00000000 --- a/Assets/Scripts/Props.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: f299520ed9fcf4a45858ad4ef5a8d5d1 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Rendering/CustomLight.cs b/Assets/Scripts/Rendering/CustomLight.cs new file mode 100644 index 00000000..404dee12 --- /dev/null +++ b/Assets/Scripts/Rendering/CustomLight.cs @@ -0,0 +1,46 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CustomLight : MonoBehaviour +{ + // Start is called before the first frame update + void OnEnable() + { + CustomLightRegistry.Instance.Register(this); + } + + // Update is called once per frame + void OnDisable() + { + CustomLightRegistry.Instance.Unregister(this); + } +} + +public class CustomLightRegistry : Singleton<CustomLightRegistry> +{ + private List<CustomLight> m_Lights; + public List<CustomLight> lights + { + get + { + if (m_Lights == null) + m_Lights = new List<CustomLight>(); + return m_Lights; + } + } + + public void Register(CustomLight renderer) + { + if (!lights.Contains(renderer)) + { + lights.Add(renderer); + } + } + + public void Unregister(CustomLight renderer) + { + lights.Remove(renderer); + } + +}
\ No newline at end of file diff --git a/Assets/Scripts/Rendering/CustomLight.cs.meta b/Assets/Scripts/Rendering/CustomLight.cs.meta new file mode 100644 index 00000000..51106c9d --- /dev/null +++ b/Assets/Scripts/Rendering/CustomLight.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d07937a2b7582554e9ec6ba1fcf41504 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Rendering/CustomRenderingPipeline.cs b/Assets/Scripts/Rendering/CustomRenderingPipeline.cs index 9387cf52..befeed87 100644 --- a/Assets/Scripts/Rendering/CustomRenderingPipeline.cs +++ b/Assets/Scripts/Rendering/CustomRenderingPipeline.cs @@ -5,6 +5,7 @@ using UnityEngine; using UnityEngine.Rendering; // 相机的自定义管线 +// 混合延迟渲染和前向渲染 [RequireComponent(typeof(MainCamera))] public class CustomRenderingPipeline : MonoBehaviour {
@@ -22,12 +23,10 @@ public class CustomRenderingPipeline : MonoBehaviour // command buffers
CommandBuffer m_CommandBufferAfterDepth;
- RenderTargetIdentifier[] m_GBuffer = new RenderTargetIdentifier[4];
+ RenderTargetIdentifier[] m_GBuffer = new RenderTargetIdentifier[2];
RenderTargetIdentifier m_DepthBuffer;
- RenderTexture m_GBufferTextureDiffuse;
RenderTexture m_GBufferTextureNormal;
RenderTexture m_GBufferTexturePosition;
- RenderTexture m_GBufferTextureTexCoord;
void OnEnable()
{
@@ -35,20 +34,16 @@ public class CustomRenderingPipeline : MonoBehaviour // command buffers
m_CommandBufferAfterDepth = new CommandBuffer();
- m_Camera.AddCommandBuffer(CameraEvent.AfterDepthTexture, m_CommandBufferAfterDepth);
+ m_CommandBufferAfterDepth.name = "Custom RenderPipeline GBuffer";
+ m_Camera.AddCommandBuffer(CameraEvent.AfterDepthTexture, m_CommandBufferAfterDepth);
// render targets
int width = m_Camera.pixelWidth, height = m_Camera.pixelHeight;
- m_GBufferTextureDiffuse = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
m_GBufferTextureNormal = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
m_GBufferTexturePosition = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
- m_GBufferTextureTexCoord = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
- m_GBuffer[0] = m_GBufferTextureDiffuse.colorBuffer;
- m_GBuffer[1] = m_GBufferTextureNormal.colorBuffer;
- m_GBuffer[2] = m_GBufferTexturePosition.colorBuffer;
- m_GBuffer[3] = m_GBufferTextureTexCoord.colorBuffer;
- m_DepthBuffer = m_GBufferTextureDiffuse.depthBuffer;
-
+ m_GBuffer[0] = m_GBufferTextureNormal.colorBuffer;
+ m_GBuffer[1] = m_GBufferTexturePosition.colorBuffer;
+ m_DepthBuffer = m_GBufferTextureNormal.depthBuffer;
} void OnDisable()
diff --git a/Assets/Scripts/Robot.meta b/Assets/Scripts/Robot.meta deleted file mode 100644 index 0b5a087e..00000000 --- a/Assets/Scripts/Robot.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 7c09ca1609552d24bbe697d1516f8aa9 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Curve3D.meta b/Assets/Scripts/Scene.meta index fef1c5e7..eb7a8716 100644 --- a/Assets/Scripts/Curve3D.meta +++ b/Assets/Scripts/Scene.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ad8b718b6b700d8419838dad07158567 +guid: eaee2d0f48cff9b40baf0686a8105600 folderAsset: yes DefaultImporter: externalObjects: {} 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/UnitPreprocessing.cs b/Assets/Scripts/Unit/Components/UnitPreprocessing.cs index 44ab73b7..8c56f0b6 100644 --- a/Assets/Scripts/Unit/Components/UnitPreprocessing.cs +++ b/Assets/Scripts/Unit/Components/UnitPreprocessing.cs @@ -2,28 +2,28 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -using UnityEngine.Rendering; - -// 给每个角色准备一些特殊的前置渲染 +using UnityEngine.Rendering;
+
+// 给每个角色准备一些特殊的前置渲染
public class UnitPreprocessing : UnitComponent { [Flags] public enum EUnitPreprocessing { - None , - DepthTexture, // Unit Depth Texture - WorldNormalTexture, // Unit World Normal Texture + None, + DepthTexture, // Unit Depth Texture
+ WorldNormalTexture, // Unit World Normal Texture
} public EUnitPreprocessing preprocessing;
- #region render textures - public RenderTexture unitDepthTexture { get; private set; } + #region render textures + public RenderTexture unitDepthTexture { get; private set; } public RenderTexture unitWorldNormalTexture { get; private set; }
- public RenderTexture unitMotionVectorTexture { get; private set; }
- #endregion + public RenderTexture unitMotionVectorTexture { get; private set; }
+ #endregion - private CommandBuffer m_CBBeforeDepthTexture; + private CommandBuffer m_CommandBufferBeforeDepth; private Material m_MaterialDepth; @@ -39,7 +39,8 @@ public class UnitPreprocessing : UnitComponent MainCamera.Instance.customRenderingPipeline.onPreCull += OnWillRenderUnit; MainCamera.Instance.customRenderingPipeline.onPostRender += OnRenderUnit; - m_CBBeforeDepthTexture = new CommandBuffer(); + m_CommandBufferBeforeDepth = new CommandBuffer(); + m_CommandBufferBeforeDepth.name = "Unit Preprocessing(" + owner.unitObj.name + ")"; PrepareRenderTextures(); PrepareMaterials(); @@ -74,16 +75,16 @@ public class UnitPreprocessing : UnitComponent } private void OnWillRenderUnit() - { - RenderDepthTexture();
- //RenderWorldNormal();
- RenderMotionVector();
- MainCamera.Instance.camera.AddCommandBuffer(CameraEvent.BeforeDepthTexture, m_CBBeforeDepthTexture); - } + {
+ RenderDepthTexture();
+ //RenderWorldNormal();
+ RenderMotionVector();
+ MainCamera.Instance.camera.AddCommandBuffer(CameraEvent.BeforeDepthTexture, m_CommandBufferBeforeDepth);
+ } void RenderDepthTexture() { - var cb = m_CBBeforeDepthTexture; + var cb = m_CommandBufferBeforeDepth; cb.Clear(); cb.SetRenderTarget(unitDepthTexture); cb.ClearRenderTarget(true, true, new Color(0, 0, 0, 0)); @@ -100,21 +101,21 @@ public class UnitPreprocessing : UnitComponent continue; cb.DrawRenderer(renderer, m_MaterialDepth); } - } - - void RenderMotionVector()
- {
- } - - //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)); - //} - + }
+
+ 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; @@ -127,9 +128,9 @@ public class UnitPreprocessing : UnitComponent } private void OnRenderUnit() - { - //m_CBBeforeDepthTexture.ReleaseTemporaryRT(unitDepthTextureID); - - MainCamera.Instance.camera.RemoveCommandBuffer(CameraEvent.BeforeDepthTexture, m_CBBeforeDepthTexture); + {
+ //m_CommandBufferBeforeDepth.ReleaseTemporaryRT(unitDepthTextureID);
+
+ MainCamera.Instance.camera.RemoveCommandBuffer(CameraEvent.BeforeDepthTexture, m_CommandBufferBeforeDepth); } }
\ No newline at end of file diff --git a/Assets/Scripts/Unit/Components/UnitState/PCState.cs b/Assets/Scripts/Unit/Components/UnitState/PCState.cs index 7e766455..1bdd355f 100644 --- a/Assets/Scripts/Unit/Components/UnitState/PCState.cs +++ b/Assets/Scripts/Unit/Components/UnitState/PCState.cs @@ -144,7 +144,7 @@ public partial class PCState : UnitState UnitSnapshotInfo info = owner.TakeSnapshot();
Vector2 dir = TestErika.Instance.monster.owner.center + new Vector3(offset, -0.5f, 0) - owner.center;
- LensEffect_Dash dash = new LensEffect_Dash(Color.white, 0.05f, Mathf.Atan2(dir.y, dir.x), info);
+ LensEffect_Dash dash = new LensEffect_Dash(Color.white, 0.1f, Mathf.Atan2(dir.y, dir.x), info);
owner.unitLensEffect.AddEffect(dash);
owner.center = TestErika.Instance.monster.owner.center + new Vector3(offset, -0.5f, 0);
diff --git a/Assets/Scripts/Unit/LensEffect/LensEffect_Buzz.cs b/Assets/Scripts/Unit/LensEffect/LensEffect_Buzz.cs index 55e8c772..6aa06d01 100644 --- a/Assets/Scripts/Unit/LensEffect/LensEffect_Buzz.cs +++ b/Assets/Scripts/Unit/LensEffect/LensEffect_Buzz.cs @@ -15,11 +15,11 @@ public class LensEffect_Buzz : LensEffectBase public override void AfterForwardAlpha(EStage stage, CommandBuffer cb) { - if(stage == EStage.Before) + if (stage == EStage.Before) { Before(cb); } - else if(stage == EStage.After) + else if (stage == EStage.After) { After(cb); } @@ -28,7 +28,7 @@ public class LensEffect_Buzz : LensEffectBase 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); } diff --git a/Assets/Scripts/Unit/LensEffect/LensEffect_Dash.cs b/Assets/Scripts/Unit/LensEffect/LensEffect_Dash.cs index 6cce6b4c..dc14cf09 100644 --- a/Assets/Scripts/Unit/LensEffect/LensEffect_Dash.cs +++ b/Assets/Scripts/Unit/LensEffect/LensEffect_Dash.cs @@ -9,22 +9,22 @@ public class LensEffect_Dash : LensEffectBase Color rimColor; int tempID; - float lifeTime; - UnitSnapshot snapshot; - TRS trs;
- float angle;
+ float lifeTime;
+ UnitSnapshot snapshot;
+ TRS trs;
+ float angle;
- float curTime = 0;
+ float curTime = 0;
- public LensEffect_Dash(Color color, float lifeTime, float angle, UnitSnapshotInfo snapshot) : base() + public LensEffect_Dash(Color color, float lifeTime, float angle, UnitSnapshotInfo snapshot) : base() { rimColor = color; tempID = Shader.PropertyToID("RT_Dash"); - this.lifeTime = lifeTime; - trs = snapshot.trs; - this.snapshot = UnitManager.Instance.ClaimSnapshotSolo(snapshot); - this.angle = angle; - } + this.lifeTime = lifeTime;
+ trs = snapshot.trs;
+ this.snapshot = UnitManager.Instance.ClaimSnapshotSolo(snapshot);
+ this.angle = angle;
+ } public override void AfterForwardOpaque(EStage stage, CommandBuffer cb) { @@ -42,53 +42,53 @@ public class LensEffect_Dash : LensEffectBase } void Before(CommandBuffer cb) - { - cb.GetTemporaryRT(tempID, -1, -1, 24, FilterMode.Bilinear); + {
+ cb.GetTemporaryRT(tempID, -1, -1, 24, FilterMode.Bilinear); cb.SetRenderTarget(tempID); - cb.ClearRenderTarget(true, true, new Color(0, 0, 0, 0)); - - // renderer - snapshot.transform.position = trs.position; - snapshot.transform.rotation = trs.rotation; - snapshot.transform.localScale = trs.scale;
+ cb.ClearRenderTarget(true, true, new Color(0, 0, 0, 0));
- Matrix4x4 obj2Wod = Matrix4x4.identity;
- SkinnedMeshRenderer smr = snapshot.renderers[0] as SkinnedMeshRenderer;
- Vector3 pos = smr.rootBone.transform.position;
- Quaternion rot = smr.rootBone.transform.rotation;
- obj2Wod = MatrixUtility.RotateAndTranslate(pos, rot);
+ // renderer
+ snapshot.transform.position = trs.position;
+ snapshot.transform.rotation = trs.rotation;
+ snapshot.transform.localScale = trs.scale;
- MaterialEntry mat = ClaimMaterial(StaticDefine.shaders[EShader.SolidColor].name);
- mat.material.SetColor("_Color", rimColor);
- mat.material.SetMatrix("_ObjectToWorld", obj2Wod);
- mat.material.SetTexture("_MainTex", snapshot.renderers[0].sharedMaterial.GetTexture("_MainTex"));
+ Matrix4x4 obj2Wod = Matrix4x4.identity;
+ SkinnedMeshRenderer smr = snapshot.renderers[0] as SkinnedMeshRenderer;
+ Vector3 pos = smr.rootBone.transform.position;
+ Quaternion rot = smr.rootBone.transform.rotation;
+ obj2Wod = MatrixUtility.RotateAndTranslate(pos, rot);
- cb.DrawRenderer(snapshot.renderers[0], mat.material);
- } + MaterialEntry mat = ClaimMaterial(StaticDefine.shaders[EShader.SolidColor].name);
+ mat.material.SetColor("_Color", rimColor);
+ mat.material.SetMatrix("_ObjectToWorld", obj2Wod);
+ mat.material.SetTexture("_MainTex", snapshot.renderers[0].sharedMaterial.GetTexture("_MainTex"));
+
+ cb.DrawRenderer(snapshot.renderers[0], mat.material);
+ } void After(CommandBuffer cb) {
- curTime += Time.deltaTime;
+ curTime += Time.deltaTime;
- MaterialEntry blur = ClaimMaterial(StaticDefine.shaders[EShader.MotionBlur].name); + MaterialEntry blur = ClaimMaterial(StaticDefine.shaders[EShader.MotionBlur].name); - Vector4 tileOffset = RenderingUtility.GetTillingOffset(MainCamera.Instance.camera, owner.center, owner.unitDetail.snapshotBound);
- blur.material.SetVector("_UnitTileOffset", tileOffset);
- blur.material.SetFloat("_Angle", Mathf.Rad2Deg * angle);
- blur.material.SetFloat("_AlphaMultiplier", Mathf.Clamp(1 - curTime / lifeTime, 0, 1));
+ Vector4 tileOffset = RenderingUtility.GetTillingOffset(MainCamera.Instance.camera, trs.position, owner.unitDetail.snapshotBound);
+ blur.material.SetVector("_UnitTileOffset", tileOffset);
+ blur.material.SetFloat("_Angle", Mathf.Rad2Deg * angle);
+ blur.material.SetFloat("_AlphaMultiplier", Mathf.Clamp(1 - curTime / lifeTime, 0, 1));
- cb.Blit(tempID, BuiltinRenderTextureType.CameraTarget, blur.material); + cb.Blit(tempID, BuiltinRenderTextureType.CameraTarget, blur.material); cb.ReleaseTemporaryRT(tempID); - } - - public override bool CanDestroy()
- {
- return curTime > lifeTime;
- } - - public override void OnDestroy()
- {
- UnitManager.Instance.ReleaseSnapshot(ref snapshot);
- }
+ }
+
+ public override bool CanDestroy()
+ {
+ return curTime > lifeTime;
+ }
+
+ public override void OnDestroy()
+ {
+ UnitManager.Instance.ReleaseSnapshot(ref snapshot);
+ }
}
\ No newline at end of file |