summaryrefslogtreecommitdiff
path: root/Assets/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/Curve3D.meta (renamed from Assets/Scripts/Scene.meta)2
-rw-r--r--Assets/Scripts/Data/EnumDefine.cs1
-rw-r--r--Assets/Scripts/Data/StaticDefine.cs3
-rw-r--r--Assets/Scripts/Drone.meta8
-rw-r--r--Assets/Scripts/Managers/Physics.meta8
-rw-r--r--Assets/Scripts/Props.meta8
-rw-r--r--Assets/Scripts/Rendering/CustomRenderer.cs50
-rw-r--r--Assets/Scripts/Rendering/CustomRenderer.cs.meta11
-rw-r--r--Assets/Scripts/Rendering/CustomRenderingPipeline.cs66
-rw-r--r--Assets/Scripts/Robot.meta8
-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.cs2
-rw-r--r--Assets/Scripts/Unit/Components/UnitPreprocessing.cs29
-rw-r--r--Assets/Scripts/Unit/Components/UnitState/PCState.cs2
-rw-r--r--Assets/Scripts/Unit/LensEffect/LensEffect_BlurRim.cs2
-rw-r--r--Assets/Scripts/Unit/LensEffect/LensEffect_Dash.cs2
-rw-r--r--Assets/Scripts/Unit/LensEffect/LensEffect_MotionBlur.cs2
18 files changed, 193 insertions, 27 deletions
diff --git a/Assets/Scripts/Scene.meta b/Assets/Scripts/Curve3D.meta
index eb7a8716..fef1c5e7 100644
--- a/Assets/Scripts/Scene.meta
+++ b/Assets/Scripts/Curve3D.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: eaee2d0f48cff9b40baf0686a8105600
+guid: ad8b718b6b700d8419838dad07158567
folderAsset: yes
DefaultImporter:
externalObjects: {}
diff --git a/Assets/Scripts/Data/EnumDefine.cs b/Assets/Scripts/Data/EnumDefine.cs
index 50e0baf5..77519c60 100644
--- a/Assets/Scripts/Data/EnumDefine.cs
+++ b/Assets/Scripts/Data/EnumDefine.cs
@@ -18,6 +18,7 @@ public enum EShader
Buzz,
SolidColor,
+ GBuffer,
UnitDepth,
diff --git a/Assets/Scripts/Data/StaticDefine.cs b/Assets/Scripts/Data/StaticDefine.cs
index ae06f364..dcfb19e1 100644
--- a/Assets/Scripts/Data/StaticDefine.cs
+++ b/Assets/Scripts/Data/StaticDefine.cs
@@ -22,7 +22,8 @@ public static class StaticDefine
{ EShader.MotionBlur, new ShaderDefine("Erika/Common/Image/MotionBlur", "")},
{ EShader.SolidColor, new ShaderDefine("Erika/Common/SolidColor", "") },
{ EShader.UnitDepth, new ShaderDefine("Erika/Unit/Common/Depth", "") },
- { EShader.Buzz, new ShaderDefine("Erika/Common/Image/Buzz", "") },
+ { EShader.Buzz, new ShaderDefine("Erika/Common/Image/Buzz", "") },
+ { EShader.GBuffer, new ShaderDefine("Erika/Common/GBuffer", "") },
};
public static string bundleManifest = "bundles"; // Assets/Resources/bundles.json
diff --git a/Assets/Scripts/Drone.meta b/Assets/Scripts/Drone.meta
new file mode 100644
index 00000000..694cff70
--- /dev/null
+++ b/Assets/Scripts/Drone.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: ec3412151f8a72a41b2ed21316763399
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Managers/Physics.meta b/Assets/Scripts/Managers/Physics.meta
new file mode 100644
index 00000000..2296b3f8
--- /dev/null
+++ b/Assets/Scripts/Managers/Physics.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 603d4624aaedd794cb89497954a83f4a
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Props.meta b/Assets/Scripts/Props.meta
new file mode 100644
index 00000000..bb96602e
--- /dev/null
+++ b/Assets/Scripts/Props.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: f299520ed9fcf4a45858ad4ef5a8d5d1
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Rendering/CustomRenderer.cs b/Assets/Scripts/Rendering/CustomRenderer.cs
new file mode 100644
index 00000000..07c6ec7f
--- /dev/null
+++ b/Assets/Scripts/Rendering/CustomRenderer.cs
@@ -0,0 +1,50 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+[RequireComponent(typeof(Renderer))]
+public class CustomRenderer : MonoBehaviour
+{
+ public new Renderer renderer { get; private set; }
+
+ void OnEnable()
+ {
+ renderer = GetComponent<Renderer>();
+
+ CustomRendererRegistry.Instance.Register(this);
+ }
+
+ void OnDisable()
+ {
+ CustomRendererRegistry.Instance.Unregister(this);
+ }
+
+}
+
+public class CustomRendererRegistry : Singleton<CustomRendererRegistry>
+{
+ private List<CustomRenderer> m_Renderers;
+ public List<CustomRenderer> renderers
+ {
+ get
+ {
+ if (m_Renderers == null)
+ m_Renderers = new List<CustomRenderer>();
+ return m_Renderers;
+ }
+ }
+
+ public void Register(CustomRenderer renderer)
+ {
+ if(!renderers.Contains(renderer))
+ {
+ renderers.Add(renderer);
+ }
+ }
+
+ public void Unregister(CustomRenderer renderer)
+ {
+ renderers.Remove(renderer);
+ }
+
+}
diff --git a/Assets/Scripts/Rendering/CustomRenderer.cs.meta b/Assets/Scripts/Rendering/CustomRenderer.cs.meta
new file mode 100644
index 00000000..b9742494
--- /dev/null
+++ b/Assets/Scripts/Rendering/CustomRenderer.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: c37c88af4ec59ad47ab867ec63cd0d76
+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 af70e760..9387cf52 100644
--- a/Assets/Scripts/Rendering/CustomRenderingPipeline.cs
+++ b/Assets/Scripts/Rendering/CustomRenderingPipeline.cs
@@ -4,43 +4,91 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
+// 相机的自定义管线
[RequireComponent(typeof(MainCamera))]
public class CustomRenderingPipeline : MonoBehaviour
{
+ [Tooltip("开启自定义延迟渲染")]
+ public bool enableDeferredRender;
public delegate void RenderEventHandler();
+ // UnitPreprocessing, UnitLensEffect, etc
public event RenderEventHandler onPreCull;
public event RenderEventHandler onPreRender;
public event RenderEventHandler onPostRender;
- #region 公共贴图
+ Camera m_Camera;
- #endregion
+ // command buffers
+ CommandBuffer m_CommandBufferAfterDepth;
- Camera m_Camera;
+ RenderTargetIdentifier[] m_GBuffer = new RenderTargetIdentifier[4];
+ RenderTargetIdentifier m_DepthBuffer;
+ RenderTexture m_GBufferTextureDiffuse;
+ RenderTexture m_GBufferTextureNormal;
+ RenderTexture m_GBufferTexturePosition;
+ RenderTexture m_GBufferTextureTexCoord;
- private void OnEable()
+ void OnEnable()
{
m_Camera = GetComponent<Camera>();
+
+ // command buffers
+ m_CommandBufferAfterDepth = new CommandBuffer();
+ 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;
+
}
- private void Start()
+ void OnDisable()
{
- }
+ m_Camera.RemoveAllCommandBuffers();
+ }
- private void OnPreCull()
+ void OnPreCull()
{
+ m_CommandBufferAfterDepth.Clear();
+
+ RenderGBuffer();
+
onPreCull?.Invoke();
}
- private void OnPreRender()
+ void OnPreRender()
{
onPreRender?.Invoke();
}
- private void OnPostRender()
+ void OnPostRender()
{
onPostRender?.Invoke();
}
+ void RenderGBuffer()
+ {
+ CommandBuffer cb = m_CommandBufferAfterDepth;
+ cb.SetRenderTarget(m_GBuffer, m_DepthBuffer);
+ cb.ClearRenderTarget(true, true, new Color(0, 0, 0, 0));
+ List<CustomRenderer> renderers = CustomRendererRegistry.Instance.renderers;
+ Material mat = new Material(Shader.Find(StaticDefine.shaders[EShader.GBuffer].name));
+ for(int i = 0; i < renderers.Count; ++i)
+ {
+ CustomRenderer renderer = renderers[i];
+ if (renderer == null)
+ continue;
+ cb.DrawRenderer(renderer.renderer, mat);
+ }
+ }
+
} \ No newline at end of file
diff --git a/Assets/Scripts/Robot.meta b/Assets/Scripts/Robot.meta
new file mode 100644
index 00000000..0b5a087e
--- /dev/null
+++ b/Assets/Scripts/Robot.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 7c09ca1609552d24bbe697d1516f8aa9
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Unit/AI/Actions.meta b/Assets/Scripts/Unit/AI/Actions.meta
new file mode 100644
index 00000000..9b4ad463
--- /dev/null
+++ b/Assets/Scripts/Unit/AI/Actions.meta
@@ -0,0 +1,8 @@
+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
new file mode 100644
index 00000000..70a86da5
--- /dev/null
+++ b/Assets/Scripts/Unit/AI/Conditionals.meta
@@ -0,0 +1,8 @@
+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 ef8e6ee6..ff5af87d 100644
--- a/Assets/Scripts/Unit/Components/UnitLensEffect.cs
+++ b/Assets/Scripts/Unit/Components/UnitLensEffect.cs
@@ -65,7 +65,7 @@ public class UnitLensEffect : UnitComponent
/////
//m_Effects.Add(new LensEffect_MotionBlur());
//m_Effects.Add(new LensEffect_BlurRim(Color.blue));
- m_Effects.Add(new LensEffect_Buzz());
+ //m_Effects.Add(new LensEffect_Buzz());
}
public override void Release()
diff --git a/Assets/Scripts/Unit/Components/UnitPreprocessing.cs b/Assets/Scripts/Unit/Components/UnitPreprocessing.cs
index 30357615..44ab73b7 100644
--- a/Assets/Scripts/Unit/Components/UnitPreprocessing.cs
+++ b/Assets/Scripts/Unit/Components/UnitPreprocessing.cs
@@ -15,12 +15,15 @@ public class UnitPreprocessing : UnitComponent
WorldNormalTexture, // Unit World Normal Texture
}
- public EUnitPreprocessing preprocessing;
-
- public RenderTexture unitDepthTexture { get; private set; }
- public RenderTexture unitWorldNormalTexture { get; private set; }
-
- private CommandBuffer m_CBBeforeDepthTexture;
+ 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_CBBeforeDepthTexture;
private Material m_MaterialDepth;
@@ -72,11 +75,11 @@ public class UnitPreprocessing : UnitComponent
private void OnWillRenderUnit()
{
- RenderDepthTexture();
- //RenderWorldNormal();
-
- MainCamera.Instance.camera.AddCommandBuffer(CameraEvent.BeforeDepthTexture, m_CBBeforeDepthTexture);
- }
+ RenderDepthTexture();
+ //RenderWorldNormal();
+ RenderMotionVector();
+ MainCamera.Instance.camera.AddCommandBuffer(CameraEvent.BeforeDepthTexture, m_CBBeforeDepthTexture);
+ }
void RenderDepthTexture()
{
@@ -99,6 +102,10 @@ public class UnitPreprocessing : UnitComponent
}
}
+ void RenderMotionVector()
+ {
+ }
+
//void RenderWorldNormal()
//{
// var cb = m_CBBeforeDepthTexture;
diff --git a/Assets/Scripts/Unit/Components/UnitState/PCState.cs b/Assets/Scripts/Unit/Components/UnitState/PCState.cs
index 1bdd355f..7e766455 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.1f, Mathf.Atan2(dir.y, dir.x), info);
+ LensEffect_Dash dash = new LensEffect_Dash(Color.white, 0.05f, 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_BlurRim.cs b/Assets/Scripts/Unit/LensEffect/LensEffect_BlurRim.cs
index 6c61f2e7..5260a751 100644
--- a/Assets/Scripts/Unit/LensEffect/LensEffect_BlurRim.cs
+++ b/Assets/Scripts/Unit/LensEffect/LensEffect_BlurRim.cs
@@ -77,7 +77,7 @@ public class LensEffect_BlurRim : LensEffectBase
MaterialEntry blur = ClaimMaterial(StaticDefine.shaders[EShader.Blur].name);
Vector4 tileOffset = RenderingUtility.GetTillingOffset(MainCamera.Instance.camera, owner.center, owner.unitDetail.snapshotBound);
- blur.material.SetVector("_TileOffset", tileOffset);
+ blur.material.SetVector("_UnitTileOffset", tileOffset);
cb.Blit(tempID, BuiltinRenderTextureType.CameraTarget, blur.material);
cb.ReleaseTemporaryRT(tempID);
diff --git a/Assets/Scripts/Unit/LensEffect/LensEffect_Dash.cs b/Assets/Scripts/Unit/LensEffect/LensEffect_Dash.cs
index 61bb08fa..6cce6b4c 100644
--- a/Assets/Scripts/Unit/LensEffect/LensEffect_Dash.cs
+++ b/Assets/Scripts/Unit/LensEffect/LensEffect_Dash.cs
@@ -73,7 +73,7 @@ public class LensEffect_Dash : LensEffectBase
MaterialEntry blur = ClaimMaterial(StaticDefine.shaders[EShader.MotionBlur].name);
Vector4 tileOffset = RenderingUtility.GetTillingOffset(MainCamera.Instance.camera, owner.center, owner.unitDetail.snapshotBound);
- blur.material.SetVector("_TileOffset", tileOffset);
+ blur.material.SetVector("_UnitTileOffset", tileOffset);
blur.material.SetFloat("_Angle", Mathf.Rad2Deg * angle);
blur.material.SetFloat("_AlphaMultiplier", Mathf.Clamp(1 - curTime / lifeTime, 0, 1));
diff --git a/Assets/Scripts/Unit/LensEffect/LensEffect_MotionBlur.cs b/Assets/Scripts/Unit/LensEffect/LensEffect_MotionBlur.cs
index 3e5ee4f1..b76666ff 100644
--- a/Assets/Scripts/Unit/LensEffect/LensEffect_MotionBlur.cs
+++ b/Assets/Scripts/Unit/LensEffect/LensEffect_MotionBlur.cs
@@ -55,7 +55,7 @@ public class LensEffect_MotionBlur : LensEffectBase
MaterialEntry blur = ClaimMaterial(StaticDefine.shaders[EShader.Blur].name);
Vector4 tileOffset = RenderingUtility.GetTillingOffset(MainCamera.Instance.camera, owner.center, owner.unitDetail.snapshotBound);
- blur.material.SetVector("_TileOffset", tileOffset);
+ blur.material.SetVector("_UnitTileOffset", tileOffset);
cb.Blit(tempID, BuiltinRenderTextureType.CameraTarget, blur.material);
tempID = Shader.PropertyToID("_Temp1");