summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Unit
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/Unit')
-rw-r--r--Assets/Scripts/Unit/Components/UnitLensEffect.cs4
-rw-r--r--Assets/Scripts/Unit/Controller/UnitController.cs32
-rw-r--r--Assets/Scripts/Unit/LensEffect/LensEffectBase.cs2
-rw-r--r--Assets/Scripts/Unit/LensEffect/LensEffect_BlurRim.cs76
-rw-r--r--Assets/Scripts/Unit/LensEffect/LensEffect_BlurRim.cs.meta11
-rw-r--r--Assets/Scripts/Unit/LensEffect/LensEffect_MotionBlur.cs4
6 files changed, 128 insertions, 1 deletions
diff --git a/Assets/Scripts/Unit/Components/UnitLensEffect.cs b/Assets/Scripts/Unit/Components/UnitLensEffect.cs
index a61955f7..394a0b92 100644
--- a/Assets/Scripts/Unit/Components/UnitLensEffect.cs
+++ b/Assets/Scripts/Unit/Components/UnitLensEffect.cs
@@ -57,7 +57,8 @@ public class UnitLensEffect : UnitComponent
MainCamera.Instance.customRenderingPipeline.onPostRender += OnRenderUnit;
/////
- m_Effects.Add(new LensEffect_MotionBlur());
+ //m_Effects.Add(new LensEffect_MotionBlur());
+ m_Effects.Add(new LensEffect_BlurRim());
}
public override void Release()
@@ -90,6 +91,7 @@ public class UnitLensEffect : UnitComponent
MethodInfo method = eff.GetType().GetMethod(re.ToString(), BindingFlags.Instance | BindingFlags.Public, null, new Type[] { typeof(LensEffectBase.EStage), typeof(CommandBuffer) }, null);
if (method == null)
continue;
+ eff.owner = owner;
method.Invoke(eff, new object[] { LensEffectBase.EStage.Before, cb.Value });
for (int j = 0; j < body.renderers.Length; ++j)
{
diff --git a/Assets/Scripts/Unit/Controller/UnitController.cs b/Assets/Scripts/Unit/Controller/UnitController.cs
index 6ccf124b..3b4ab12d 100644
--- a/Assets/Scripts/Unit/Controller/UnitController.cs
+++ b/Assets/Scripts/Unit/Controller/UnitController.cs
@@ -106,6 +106,38 @@ public class UnitController : MonoBehaviour/*, Interactable*/
}
}
+ public virtual Vector3 position
+ {
+ get
+ {
+ return transform.position;
+ }
+ set
+ {
+ transform.position = value;
+ }
+ }
+
+ public virtual Quaternion rotation
+ {
+ get
+ {
+ return transform.rotation;
+ }
+ set
+ {
+ transform.rotation = value;
+ }
+ }
+
+ public virtual Vector3 lossyScale
+ {
+ get
+ {
+ return transform.lossyScale;
+ }
+ }
+
public virtual void Initialize( GameObject obj , string folder)
{
unitObj = obj;
diff --git a/Assets/Scripts/Unit/LensEffect/LensEffectBase.cs b/Assets/Scripts/Unit/LensEffect/LensEffectBase.cs
index 8457a959..36bde0e3 100644
--- a/Assets/Scripts/Unit/LensEffect/LensEffectBase.cs
+++ b/Assets/Scripts/Unit/LensEffect/LensEffectBase.cs
@@ -9,6 +9,7 @@ public class MaterialEntry
public Material material;
}
+// unit 镜头效果,和image effect的区别在于不光是后处理
public abstract class LensEffectBase : MonoBehaviour
{
public enum EStage
@@ -27,6 +28,7 @@ public abstract class LensEffectBase : MonoBehaviour
#region upvalues
public BodyPartRenderer curBodypartRenderer;
+ public UnitController owner;
#endregion
private static MaterialEntry _ClaimMaterial(string shader)
diff --git a/Assets/Scripts/Unit/LensEffect/LensEffect_BlurRim.cs b/Assets/Scripts/Unit/LensEffect/LensEffect_BlurRim.cs
new file mode 100644
index 00000000..4f90a777
--- /dev/null
+++ b/Assets/Scripts/Unit/LensEffect/LensEffect_BlurRim.cs
@@ -0,0 +1,76 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.Rendering;
+
+public class LensEffect_BlurRim : LensEffectBase
+{
+ public override ERenderingEvent renderingEvents => ERenderingEvent.AfterForwardOpaque;
+
+ int tempID;
+
+ public override void AfterForwardOpaque(EStage stage, CommandBuffer cb)
+ {
+ if (stage == EStage.Before)
+ {
+ tempID = Shader.PropertyToID("_Temp1");
+
+ cb.GetTemporaryRT(tempID, -1, -1, 24, FilterMode.Bilinear);
+ cb.SetRenderTarget(tempID);
+ cb.ClearRenderTarget(true, true, new Color(0, 0, 0, 0));
+ }
+ else if (stage == EStage.Iterate)
+ {
+ Matrix4x4 obj2Wod = Matrix4x4.identity;
+ int subMeshCount = 0;
+ if (curBodypartRenderer.renderer is SkinnedMeshRenderer)
+ {
+ SkinnedMeshRenderer smr = curBodypartRenderer.renderer as SkinnedMeshRenderer;
+ Vector3 pos = smr.rootBone.transform.position;
+ Quaternion rot = smr.rootBone.transform.rotation;
+ obj2Wod = MatrixUtility.RotateAndTranslate(pos, rot);
+ subMeshCount = smr.sharedMesh.subMeshCount;
+ }
+ else if (curBodypartRenderer.renderer is MeshRenderer)
+ {
+ obj2Wod = curBodypartRenderer.renderer.transform.localToWorldMatrix;
+ subMeshCount = curBodypartRenderer.renderer.GetComponent<MeshFilter>().sharedMesh.subMeshCount;
+ }
+
+ for (int i = 0; i < subMeshCount; ++i)
+ {
+ MaterialEntry mat = ClaimMaterial(StaticDefine.shaders[EShader.SolidColor].name);
+ mat.material.SetColor("_Color", Color.red);
+ mat.material.SetMatrix("_ObjectToWorld", obj2Wod);
+ cb.DrawRenderer(curBodypartRenderer.renderer, mat.material, i);
+
+ mat = ClaimMaterial(StaticDefine.shaders[EShader.SolidColor].name);
+ mat.material.SetColor("_Color", Color.red);
+ obj2Wod = Matrix4x4.Translate(new Vector3(1,0,0)) * obj2Wod;
+ mat.material.SetMatrix("_ObjectToWorld", obj2Wod);
+ cb.DrawRenderer(curBodypartRenderer.renderer, mat.material, i);
+
+ mat = ClaimMaterial(StaticDefine.shaders[EShader.SolidColor].name);
+ mat.material.SetColor("_Color", Color.red);
+ obj2Wod = Matrix4x4.Translate(new Vector3(-2, 0, 0)) * obj2Wod;
+ mat.material.SetMatrix("_ObjectToWorld", obj2Wod);
+ cb.DrawRenderer(curBodypartRenderer.renderer, mat.material, i);
+ }
+ }
+ else if (stage == EStage.After)
+ {
+ 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);
+
+ cb.Blit(tempID, BuiltinRenderTextureType.CameraTarget, blur.material);
+ tempID = Shader.PropertyToID("_Temp1");
+ cb.ReleaseTemporaryRT(tempID);
+ }
+ else if (stage == EStage.Finished)
+ {
+ }
+ }
+
+} \ No newline at end of file
diff --git a/Assets/Scripts/Unit/LensEffect/LensEffect_BlurRim.cs.meta b/Assets/Scripts/Unit/LensEffect/LensEffect_BlurRim.cs.meta
new file mode 100644
index 00000000..3a2e02ef
--- /dev/null
+++ b/Assets/Scripts/Unit/LensEffect/LensEffect_BlurRim.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: f49dbf9002764be4aa6ca79b78052d7a
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Unit/LensEffect/LensEffect_MotionBlur.cs b/Assets/Scripts/Unit/LensEffect/LensEffect_MotionBlur.cs
index decee999..3e5ee4f1 100644
--- a/Assets/Scripts/Unit/LensEffect/LensEffect_MotionBlur.cs
+++ b/Assets/Scripts/Unit/LensEffect/LensEffect_MotionBlur.cs
@@ -53,6 +53,10 @@ public class LensEffect_MotionBlur : LensEffectBase
else if(stage == EStage.After)
{
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);
+
cb.Blit(tempID, BuiltinRenderTextureType.CameraTarget, blur.material);
tempID = Shader.PropertyToID("_Temp1");
cb.ReleaseTemporaryRT(tempID);