Skip to content

Commit

Permalink
feat: add Color Glow, Transition Color Glow and `Shadow Color Glo…
Browse files Browse the repository at this point in the history
…w` options
  • Loading branch information
mob-sakai committed Dec 30, 2024
1 parent d0a3ca6 commit e9522d3
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Packages/src/Editor/UIEffectEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class UIEffect2Editor : Editor
private SerializedProperty _colorFilter;
private SerializedProperty _color;
private SerializedProperty _colorIntensity;
private SerializedProperty _colorGlow;

private SerializedProperty _samplingFilter;
private SerializedProperty _samplingIntensity;
Expand All @@ -36,6 +37,7 @@ public class UIEffect2Editor : Editor
private SerializedProperty _transitionSoftness;
private SerializedProperty _transitionColorFilter;
private SerializedProperty _transitionColor;
private SerializedProperty _transitionColorGlow;

private SerializedProperty _targetMode;
private SerializedProperty _targetColor;
Expand All @@ -56,6 +58,7 @@ public class UIEffect2Editor : Editor
private SerializedProperty _shadowBlurIntensity;
private SerializedProperty _shadowColorFilter;
private SerializedProperty _shadowColor;
private SerializedProperty _shadowColorGlow;

private bool _expandOthers;
private SerializedProperty _allowExtendVertex;
Expand All @@ -71,6 +74,7 @@ private void OnEnable()
_colorFilter = serializedObject.FindProperty("m_ColorFilter");
_color = serializedObject.FindProperty("m_Color");
_colorIntensity = serializedObject.FindProperty("m_ColorIntensity");
_colorGlow = serializedObject.FindProperty("m_ColorGlow");

_samplingFilter = serializedObject.FindProperty("m_SamplingFilter");
_samplingIntensity = serializedObject.FindProperty("m_SamplingIntensity");
Expand All @@ -88,6 +92,7 @@ private void OnEnable()
_transitionSoftness = serializedObject.FindProperty("m_TransitionSoftness");
_transitionColorFilter = serializedObject.FindProperty("m_TransitionColorFilter");
_transitionColor = serializedObject.FindProperty("m_TransitionColor");
_transitionColorGlow = serializedObject.FindProperty("m_TransitionColorGlow");

_targetMode = serializedObject.FindProperty("m_TargetMode");
_targetColor = serializedObject.FindProperty("m_TargetColor");
Expand All @@ -108,6 +113,7 @@ private void OnEnable()
_shadowBlurIntensity = serializedObject.FindProperty("m_ShadowBlurIntensity");
_shadowColorFilter = serializedObject.FindProperty("m_ShadowColorFilter");
_shadowColor = serializedObject.FindProperty("m_ShadowColor");
_shadowColorGlow = serializedObject.FindProperty("m_ShadowColorGlow");

_allowExtendVertex = serializedObject.FindProperty("m_AllowExtendVertex");
}
Expand Down Expand Up @@ -141,6 +147,7 @@ public void DrawProperties()
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(_colorIntensity);
DrawColor(_colorFilter, _color, prevColorFilter);
EditorGUILayout.PropertyField(_colorGlow);
EditorGUI.indentLevel--;
}

Expand Down Expand Up @@ -179,6 +186,7 @@ public void DrawProperties()
prevColorFilter = (ColorFilter)_transitionColorFilter.intValue;
EditorGUILayout.PropertyField(_transitionColorFilter);
DrawColor(_transitionColorFilter, _transitionColor, prevColorFilter);
EditorGUILayout.PropertyField(_transitionColorGlow);
}

EditorGUI.indentLevel--;
Expand Down Expand Up @@ -237,6 +245,7 @@ public void DrawProperties()

EditorGUILayout.PropertyField(_shadowColorFilter);
EditorGUILayout.PropertyField(_shadowColor);
EditorGUILayout.PropertyField(_shadowColorGlow);
EditorGUILayout.PropertyField(_shadowFade);

switch ((SamplingFilter)_samplingFilter.intValue)
Expand Down
51 changes: 51 additions & 0 deletions Packages/src/Runtime/UIEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class UIEffect : UIEffectBase
[SerializeField]
protected Color m_Color = Color.white;

[SerializeField]
protected bool m_ColorGlow = false;

[SerializeField]
protected SamplingFilter m_SamplingFilter = SamplingFilter.None;

Expand Down Expand Up @@ -82,6 +85,9 @@ public class UIEffect : UIEffectBase
[SerializeField]
protected Color m_TransitionColor = new Color(0f, 0.5f, 1.0f, 1.0f);

[SerializeField]
protected bool m_TransitionColorGlow = false;

[SerializeField]
protected TargetMode m_TargetMode = TargetMode.None;

Expand Down Expand Up @@ -135,6 +141,9 @@ public class UIEffect : UIEffectBase
[SerializeField]
protected Color m_ShadowColor = Color.white;

[SerializeField]
protected bool m_ShadowColorGlow = false;

[SerializeField]
protected bool m_AllowExtendVertex = true;

Expand Down Expand Up @@ -196,6 +205,17 @@ public Color color
}
}

public bool colorGlow
{
get => m_ColorGlow;
set
{
if (m_ColorGlow == value) return;
context.colorGlow = m_ColorGlow = value;
ApplyContextToMaterial();
}
}

public SamplingFilter samplingFilter
{
get => m_SamplingFilter;
Expand Down Expand Up @@ -372,6 +392,17 @@ public Color transitionColor
}
}

public bool transitionColorGlow
{
get => m_TransitionColorGlow;
set
{
if (m_TransitionColorGlow == value) return;
context.transitionColorGlow = m_TransitionColorGlow = value;
ApplyContextToMaterial();
}
}

public TargetMode targetMode
{
get => m_TargetMode;
Expand Down Expand Up @@ -555,6 +586,17 @@ public Color shadowColor
}
}

public bool shadowGlow
{
get => m_ShadowColorGlow;
set
{
if (m_ShadowColorGlow == value) return;
context.shadowColorGlow = m_ShadowColorGlow = value;
ApplyContextToMaterial();
}
}

public bool allowExtendVertex
{
get => m_AllowExtendVertex;
Expand Down Expand Up @@ -623,6 +665,7 @@ protected override void UpdateContext(UIEffectContext c)
c.colorFilter = m_ColorFilter;
c.color = m_Color;
c.colorIntensity = m_ColorIntensity;
c.colorGlow = m_ColorGlow;
c.samplingFilter = m_SamplingFilter;
c.samplingIntensity = m_SamplingIntensity;
c.transitionFilter = m_TransitionFilter;
Expand All @@ -637,6 +680,7 @@ protected override void UpdateContext(UIEffectContext c)
c.transitionSoftness = m_TransitionSoftness;
c.transitionColorFilter = m_TransitionColorFilter;
c.transitionColor = m_TransitionColor;
c.transitionColorGlow = m_TransitionColorGlow;
c.targetMode = m_TargetMode;
c.targetColor = m_TargetColor;
c.targetRange = m_TargetRange;
Expand All @@ -651,6 +695,7 @@ protected override void UpdateContext(UIEffectContext c)
c.shadowBlurIntensity = m_ShadowBlurIntensity;
c.shadowColorFilter = m_ShadowColorFilter;
c.shadowColor = m_ShadowColor;
c.shadowColorGlow = m_ShadowColorGlow;
c.allowExtendVertex = m_AllowExtendVertex;
}

Expand Down Expand Up @@ -716,6 +761,7 @@ public void LoadPreset(UIEffect preset)
m_ColorFilter = preset.m_ColorFilter;
m_Color = preset.m_Color;
m_ColorIntensity = preset.m_ColorIntensity;
m_ColorGlow = preset.m_ColorGlow;

m_SamplingFilter = preset.m_SamplingFilter;
m_SamplingIntensity = preset.m_SamplingIntensity;
Expand All @@ -733,6 +779,7 @@ public void LoadPreset(UIEffect preset)
m_TransitionSoftness = preset.m_TransitionSoftness;
m_TransitionColorFilter = preset.m_TransitionColorFilter;
m_TransitionColor = preset.m_TransitionColor;
m_TransitionColorGlow = preset.m_TransitionColorGlow;

m_TargetMode = preset.m_TargetMode;
m_TargetColor = preset.m_TargetColor;
Expand All @@ -750,6 +797,7 @@ public void LoadPreset(UIEffect preset)
m_ShadowBlurIntensity = preset.m_ShadowBlurIntensity;
m_ShadowColorFilter = preset.m_ShadowColorFilter;
m_ShadowColor = preset.m_ShadowColor;
m_ShadowColorGlow = preset.m_ShadowColorGlow;

UpdateContext(context);
ApplyContextToMaterial();
Expand All @@ -766,6 +814,7 @@ internal void CopyFrom(UIEffectContext c)
m_ColorFilter = c.colorFilter;
m_Color = c.color;
m_ColorIntensity = c.colorIntensity;
m_ColorGlow = c.colorGlow;

m_SamplingFilter = c.samplingFilter;
m_SamplingIntensity = c.samplingIntensity;
Expand All @@ -782,6 +831,7 @@ internal void CopyFrom(UIEffectContext c)
m_TransitionSoftness = c.transitionSoftness;
m_TransitionColorFilter = c.transitionColorFilter;
m_TransitionColor = c.transitionColor;
m_TransitionColorGlow = c.transitionColorGlow;

m_TargetMode = c.targetMode;
m_TargetColor = c.targetColor;
Expand All @@ -800,6 +850,7 @@ internal void CopyFrom(UIEffectContext c)
m_ShadowBlurIntensity = c.shadowBlurIntensity;
m_ShadowColorFilter = c.shadowColorFilter;
m_ShadowColor = c.shadowColor;
m_ShadowColorGlow = c.shadowColorGlow;

m_AllowExtendVertex = c.allowExtendVertex;

Expand Down
12 changes: 12 additions & 0 deletions Packages/src/Runtime/UIEffectContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class UIEffectContext
private static readonly int s_ToneParams = Shader.PropertyToID("_ToneParams");
private static readonly int s_ColorValue = Shader.PropertyToID("_ColorValue");
private static readonly int s_ColorIntensity = Shader.PropertyToID("_ColorIntensity");
private static readonly int s_ColorGlow = Shader.PropertyToID("_ColorGlow");
private static readonly int s_SamplingIntensity = Shader.PropertyToID("_SamplingIntensity");
private static readonly int s_SamplingScale = Shader.PropertyToID("_SamplingScale");
private static readonly int s_TransitionRate = Shader.PropertyToID("_TransitionRate");
Expand All @@ -28,11 +29,13 @@ public class UIEffectContext
private static readonly int s_TransitionSoftness = Shader.PropertyToID("_TransitionSoftness");
private static readonly int s_TransitionColorFilter = Shader.PropertyToID("_TransitionColorFilter");
private static readonly int s_TransitionColor = Shader.PropertyToID("_TransitionColor");
private static readonly int s_TransitionColorGlow = Shader.PropertyToID("_TransitionColorGlow");
private static readonly int s_TargetColor = Shader.PropertyToID("_TargetColor");
private static readonly int s_TargetRange = Shader.PropertyToID("_TargetRange");
private static readonly int s_TargetSoftness = Shader.PropertyToID("_TargetSoftness");
private static readonly int s_ShadowColor = Shader.PropertyToID("_ShadowColor");
private static readonly int s_ShadowBlurIntensity = Shader.PropertyToID("_ShadowBlurIntensity");
private static readonly int s_ShadowColorGlow = Shader.PropertyToID("_ShadowColorGlow");

private static readonly string[] s_ToneKeywords =
{
Expand Down Expand Up @@ -135,6 +138,7 @@ public class UIEffectContext
public ColorFilter colorFilter = ColorFilter.None;
public float colorIntensity = 1;
public Color color = Color.white;
public bool colorGlow;

public SamplingFilter samplingFilter = SamplingFilter.None;
public float samplingIntensity = 0.5f;
Expand All @@ -151,6 +155,7 @@ public class UIEffectContext
public float transitionSoftness = 0.2f;
public ColorFilter transitionColorFilter = ColorFilter.MultiplyAdditive;
public Color transitionColor = new Color(0f, 0.5f, 1.0f, 1.0f);
public bool transitionColorGlow;

public TargetMode targetMode = TargetMode.None;
public Color targetColor = Color.white;
Expand All @@ -168,6 +173,7 @@ public class UIEffectContext
public float shadowBlurIntensity;
public ColorFilter shadowColorFilter;
public Color shadowColor;
public bool shadowColorGlow;

public bool allowExtendVertex;

Expand All @@ -194,6 +200,7 @@ public void CopyFrom(UIEffectContext preset)
colorFilter = preset.colorFilter;
color = preset.color;
colorIntensity = preset.colorIntensity;
colorGlow = preset.colorGlow;

samplingFilter = preset.samplingFilter;
samplingIntensity = preset.samplingIntensity;
Expand All @@ -210,6 +217,7 @@ public void CopyFrom(UIEffectContext preset)
transitionSoftness = preset.transitionSoftness;
transitionColor = preset.transitionColor;
transitionColorFilter = preset.transitionColorFilter;
transitionColorGlow = preset.transitionColorGlow;

targetMode = preset.targetMode;
targetColor = preset.targetColor;
Expand All @@ -227,6 +235,7 @@ public void CopyFrom(UIEffectContext preset)
shadowBlurIntensity = preset.shadowBlurIntensity;
shadowColorFilter = preset.shadowColorFilter;
shadowColor = preset.shadowColor;
shadowColorGlow = preset.shadowColorGlow;

allowExtendVertex = preset.allowExtendVertex;
}
Expand All @@ -245,6 +254,7 @@ public void ApplyToMaterial(Material material, float actualSamplingScale = 1f)

material.SetColor(s_ColorValue, color);
material.SetFloat(s_ColorIntensity, Mathf.Clamp01(colorIntensity));
material.SetInt(s_ColorGlow, colorGlow ? 1 : 0);

material.SetFloat(s_SamplingIntensity, Mathf.Clamp01(samplingIntensity));
material.SetFloat(s_SamplingScale, actualSamplingScale);
Expand All @@ -259,6 +269,7 @@ public void ApplyToMaterial(Material material, float actualSamplingScale = 1f)
material.SetFloat(s_TransitionSoftness, Mathf.Clamp01(transitionSoftness));
material.SetInt(s_TransitionColorFilter, (int)transitionColorFilter);
material.SetColor(s_TransitionColor, transitionColor);
material.SetInt(s_TransitionColorGlow, transitionColorGlow ? 1 : 0);

material.SetColor(s_TargetColor, targetColor);
material.SetFloat(s_TargetRange, Mathf.Clamp01(targetRange));
Expand All @@ -277,6 +288,7 @@ public void ApplyToMaterial(Material material, float actualSamplingScale = 1f)
}

material.SetColor(s_ShadowColor, shadowColor);
material.SetInt(s_ShadowColorGlow, shadowColorGlow ? 1 : 0);

SetKeyword(material, s_ToneKeywords, (int)toneFilter);
SetKeyword(material, s_ColorKeywords, (int)colorFilter);
Expand Down
6 changes: 6 additions & 0 deletions Packages/src/Shaders/UIEffect.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@ uniform float4 _MainTex_TexelSize;
uniform float _ToneIntensity;
uniform half4 _ColorValue;
uniform float _ColorIntensity;
uniform int _ColorGlow;
uniform float _SamplingIntensity;
uniform float _SamplingScale;
uniform sampler2D _TransitionTex;
uniform float4 _TransitionTex_ST;
uniform float _TransitionRate;
uniform int _TransitionReverse;
uniform half4 _TransitionColor;
uniform int _TransitionColorGlow;
uniform float _TransitionSoftness;
uniform float _TransitionWidth;
uniform fixed4 _TargetColor;
uniform float _TargetRange;
uniform float _TargetSoftness;
uniform float _ShadowBlurIntensity;
uniform half4 _ShadowColor;
uniform int _ShadowColorGlow;

// For performance reasons, limit the sampling of blur in TextMeshPro.
#ifdef UIEFFECT_TEXTMESHPRO
Expand Down Expand Up @@ -180,6 +183,7 @@ half4 apply_color_filter(half4 color, const half4 factor, const float intensity)
}
#endif
color = lerp(inColor, color, intensity);
color.a *= 1 - _ColorGlow;
return color;
}

Expand Down Expand Up @@ -227,6 +231,7 @@ half4 apply_transition_color_filter(half4 color, const half4 factor, const float
}
#endif
color = lerp(inColor, color, intensity);
color.a *= 1 - _TransitionColorGlow;
return color;
}

Expand Down Expand Up @@ -278,6 +283,7 @@ half4 apply_shadow_color_filter(half4 color, const half4 factor, const float int
}
#endif
color = lerp(inColor, color, intensity);
color.a *= 1 - _ShadowColorGlow;
return color;
}

Expand Down

0 comments on commit e9522d3

Please sign in to comment.