diff --git a/Assets/UIEffect/UI-Effect.cginc b/Assets/UIEffect/UI-Effect.cginc
index c480881..5dc5c61 100644
--- a/Assets/UIEffect/UI-Effect.cginc
+++ b/Assets/UIEffect/UI-Effect.cginc
@@ -40,26 +40,6 @@ fixed4 UnpackToVec4(float value)
return color;
}
-// Unpack float to low-precision [0-1] half3.
-// The z value is a little high precision.
-half3 UnpackToVec3(float value)
-{
- const int PRECISION = PACKER_STEP - 1;
- const int PACKER_STEP_HIGH = PACKER_STEP * PACKER_STEP;
- const int PRECISION_HIGH = PACKER_STEP_HIGH - 1;
- half3 color;
-
- color.x = (value % PACKER_STEP) / PRECISION;
- value = floor(value / PACKER_STEP);
-
- color.y = (value % PACKER_STEP) / PRECISION;
- value = floor(value / PACKER_STEP);
-
- color.z = (value % PACKER_STEP_HIGH) / (PRECISION_HIGH - 1);
-
- return color;
-}
-
//################################
// Blur effect
//################################
diff --git a/Assets/UIEffect/UI-Effect.shader b/Assets/UIEffect/UI-Effect.shader
index 567632c..0e4d1fe 100644
--- a/Assets/UIEffect/UI-Effect.shader
+++ b/Assets/UIEffect/UI-Effect.shader
@@ -131,7 +131,7 @@ Shader "UI/Hidden/UI-Effect"
// vvvv [For UIEffect] vvvv : Calculate effect parameter.
#if defined (UI_TONE) || defined (UI_BLUR)
- OUT.effectFactor = UnpackToVec3(IN.uv1.x);
+ OUT.effectFactor = UnpackToVec4(IN.uv1.x);
#endif
#if UI_TONE_HUE
diff --git a/Assets/UIEffect/UIEffect.cs b/Assets/UIEffect/UIEffect.cs
index aabe401..8d00653 100644
--- a/Assets/UIEffect/UIEffect.cs
+++ b/Assets/UIEffect/UIEffect.cs
@@ -16,7 +16,7 @@ namespace UnityEngine.UI
[ExecuteInEditMode]
[RequireComponent(typeof(Graphic))]
[DisallowMultipleComponent]
- public class UIEffect : MonoBehaviour, IMeshModifier
+ public class UIEffect : BaseMeshEffect
#if UNITY_EDITOR
, ISerializationCallbackReceiver
#endif
@@ -228,12 +228,6 @@ namespace UnityEngine.UI
[SerializeField] Material m_EffectMaterial;
- ///
- /// Graphic affected by the UIEffect.
- ///
- public Graphic graphic { get { if (m_Graphic == null) m_Graphic = GetComponent(); return m_Graphic; } }
-
- Graphic m_Graphic;
///
/// Additional Shadows.
@@ -249,32 +243,25 @@ namespace UnityEngine.UI
///
/// This function is called when the object becomes enabled and active.
///
- protected virtual void OnEnable()
+ protected override void OnEnable()
{
- SetDirty(true);
+ graphic.material = effectMaterial;
+ base.OnEnable();
}
///
/// This function is called when the behaviour becomes disabled () or inactive.
///
- protected virtual void OnDisable()
+ protected override void OnDisable()
{
graphic.material = null;
- SetDirty();
- }
-
- ///
- /// Callback for when properties have been changed by animation.
- ///
- protected virtual void OnDidApplyAnimationProperties()
- {
- SetDirty(true);
+ base.OnDisable();
}
///
/// Modifies the mesh.
///
- public virtual void ModifyMesh(VertexHelper vh)
+ public override void ModifyMesh(VertexHelper vh)
{
if (!isActiveAndEnabled)
{
@@ -290,7 +277,7 @@ namespace UnityEngine.UI
{
// Pack some effect factors to 1 float.
Vector2 factor = new Vector2(
- PackToFloat(toneLevel, 0, blur),
+ PackToFloat(toneLevel, 0, blur, 0),
PackToFloat(effectColor.r, effectColor.g, effectColor.b, effectColor.a)
);
@@ -329,22 +316,7 @@ namespace UnityEngine.UI
s_Verts.Clear();
}
- ///
- /// Modifies the mesh.
- ///
- [System.Obsolete("use IMeshModifier.ModifyMesh (VertexHelper verts) instead")]
- public void ModifyMesh(Mesh mesh)
- {
- }
-
#if UNITY_EDITOR
- ///
- /// This function is called when the script is loaded or a value is changed in the inspector (Called in the editor only).
- ///
- protected virtual void OnValidate()
- {
- SetDirty(true);
- }
public void OnBeforeSerialize()
{
@@ -398,7 +370,7 @@ namespace UnityEngine.UI
return;
var factor = new Vector2(
- PackToFloat(toneLevel, 0, blur),
+ PackToFloat(toneLevel, 0, blur, 0),
PackToFloat(color.r, color.g, color.b, 1)
);
@@ -472,15 +444,10 @@ namespace UnityEngine.UI
///
/// Mark the UIEffect as dirty.
///
- /// If set to true material dirty.
- void SetDirty(bool isMaterialDirty = false)
+ void SetDirty()
{
- // Update material if needed.
- if (isMaterialDirty)
- {
- graphic.material = effectMaterial;
- }
- graphic.SetVerticesDirty();
+ if(graphic)
+ graphic.SetVerticesDirty();
}
///
@@ -495,20 +462,5 @@ namespace UnityEngine.UI
+ (Mathf.FloorToInt(y * PRECISION) << 6)
+ Mathf.FloorToInt(x * PRECISION);
}
-
- ///
- /// Pack 3 low-precision [0-1] floats values to a float.
- /// The x and y values [0-1] have 64 steps(6 bits).
- /// The z value [0-1] is a little high precision(12 bits).
- ///
- static float PackToFloat(float x, float y, float z)
- {
- const int PRECISION = (1 << 6) - 1;
- const int PRECISION_HIGH = (1 << 12) - 1;
-
- return (Mathf.FloorToInt(z * PRECISION_HIGH) << 12)
- + (Mathf.FloorToInt(y * PRECISION) << 6)
- + Mathf.FloorToInt(x * PRECISION);
- }
}
}