From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../XEditor/XSkillEditor/Effect/ImageEffectBase.cs | 56 ++++++++++++++++++++++ .../XSkillEditor/Effect/ImageEffectBase.cs.meta | 8 ++++ .../XEditor/XSkillEditor/Effect/RadialBlur.cs | 49 +++++++++++++++++++ .../XEditor/XSkillEditor/Effect/RadialBlur.cs.meta | 8 ++++ 4 files changed, 121 insertions(+) create mode 100644 Client/Assets/Scripts/XEditor/XSkillEditor/Effect/ImageEffectBase.cs create mode 100644 Client/Assets/Scripts/XEditor/XSkillEditor/Effect/ImageEffectBase.cs.meta create mode 100644 Client/Assets/Scripts/XEditor/XSkillEditor/Effect/RadialBlur.cs create mode 100644 Client/Assets/Scripts/XEditor/XSkillEditor/Effect/RadialBlur.cs.meta (limited to 'Client/Assets/Scripts/XEditor/XSkillEditor/Effect') diff --git a/Client/Assets/Scripts/XEditor/XSkillEditor/Effect/ImageEffectBase.cs b/Client/Assets/Scripts/XEditor/XSkillEditor/Effect/ImageEffectBase.cs new file mode 100644 index 00000000..bf9e66e2 --- /dev/null +++ b/Client/Assets/Scripts/XEditor/XSkillEditor/Effect/ImageEffectBase.cs @@ -0,0 +1,56 @@ +#if UNITY_EDITOR +using UnityEngine; + +[RequireComponent (typeof(Camera))] +[AddComponentMenu("")] +public class ImageEffectBase : MonoBehaviour { + /// Provides a shader property that is set in the inspector + /// and a material instantiated from the shader + public Shader m_shader; + private Material m_Material; + protected string m_shaderName = "Mobile/Diffuse"; + protected virtual void Start () + { + // Disable if we don't support image effects + if (!SystemInfo.supportsImageEffects) { + enabled = false; + return; + } + + // Disable the image effect if the shader can't + // run on the users graphics card + if (!shader || !shader.isSupported) + enabled = false; + } + public virtual Shader shader + { + get + { + if (m_shader == null) + { + m_shader = Shader.Find(m_shaderName); + } + return m_shader; + } + set + { + m_shader = value; + } + } + protected Material material { + get { + if (m_Material == null) { + m_Material = new Material (shader); + m_Material.hideFlags = HideFlags.HideAndDontSave; + } + return m_Material; + } + } + + protected virtual void OnDisable() { + if( m_Material ) { + DestroyImmediate( m_Material ); + } + } +} +#endif \ No newline at end of file diff --git a/Client/Assets/Scripts/XEditor/XSkillEditor/Effect/ImageEffectBase.cs.meta b/Client/Assets/Scripts/XEditor/XSkillEditor/Effect/ImageEffectBase.cs.meta new file mode 100644 index 00000000..42c7ce0d --- /dev/null +++ b/Client/Assets/Scripts/XEditor/XSkillEditor/Effect/ImageEffectBase.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c965db0de94104d4996defd5df4f006e +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/XEditor/XSkillEditor/Effect/RadialBlur.cs b/Client/Assets/Scripts/XEditor/XSkillEditor/Effect/RadialBlur.cs new file mode 100644 index 00000000..553496bf --- /dev/null +++ b/Client/Assets/Scripts/XEditor/XSkillEditor/Effect/RadialBlur.cs @@ -0,0 +1,49 @@ +#if UNITY_EDITOR +using UnityEngine; + +[ExecuteInEditMode] +[RequireComponent(typeof(Camera))] + +public class RadialBlur : ImageEffectBase +{ + public float blurStrength = 6.0f; + public float blurWidth = 0.7f; + + void Awake() + { + enabled = false; + m_shaderName = "Hidden/radialBlur"; + //if (!SystemInfo.supportsRenderTextures) + //{ + // enabled = false; + // return; + //} + } + void OnEnable() + { + } + void OnRenderImage(RenderTexture source, RenderTexture dest) + { + // Create the accumulation texture + //if (accumTexture == null || accumTexture.width != source.width || accumTexture.height != source.height) + //{ + // DestroyImmediate(accumTexture); + // accumTexture = new RenderTexture(source.width, source.height, 0); + // accumTexture.hideFlags = HideFlags.HideAndDontSave; + // Graphics.Blit(source, accumTexture); + //} + + material.SetTexture("_MainTex", source); + material.SetFloat("_BlurStrength", blurStrength); + material.SetFloat("_BlurWidth", blurWidth); + material.SetFloat("_iHeight", 1); + material.SetFloat("_iWidth", 1); + //accumTexture.MarkRestoreExpected(); + + // Graphics.Blit(source, accumTexture, material); + // Graphics.Blit(accumTexture, dest); + + Graphics.Blit(source, dest, material); + } +} +#endif \ No newline at end of file diff --git a/Client/Assets/Scripts/XEditor/XSkillEditor/Effect/RadialBlur.cs.meta b/Client/Assets/Scripts/XEditor/XSkillEditor/Effect/RadialBlur.cs.meta new file mode 100644 index 00000000..456d3d2c --- /dev/null +++ b/Client/Assets/Scripts/XEditor/XSkillEditor/Effect/RadialBlur.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bd9d2efe45f76fb4d87e90244d34accb +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: -- cgit v1.1-26-g67d0