Skip to content

Commit e9522d3

Browse files
committed
feat: add Color Glow, Transition Color Glow and Shadow Color Glow options
1 parent d0a3ca6 commit e9522d3

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

Packages/src/Editor/UIEffectEditor.cs

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class UIEffect2Editor : Editor
1919
private SerializedProperty _colorFilter;
2020
private SerializedProperty _color;
2121
private SerializedProperty _colorIntensity;
22+
private SerializedProperty _colorGlow;
2223

2324
private SerializedProperty _samplingFilter;
2425
private SerializedProperty _samplingIntensity;
@@ -36,6 +37,7 @@ public class UIEffect2Editor : Editor
3637
private SerializedProperty _transitionSoftness;
3738
private SerializedProperty _transitionColorFilter;
3839
private SerializedProperty _transitionColor;
40+
private SerializedProperty _transitionColorGlow;
3941

4042
private SerializedProperty _targetMode;
4143
private SerializedProperty _targetColor;
@@ -56,6 +58,7 @@ public class UIEffect2Editor : Editor
5658
private SerializedProperty _shadowBlurIntensity;
5759
private SerializedProperty _shadowColorFilter;
5860
private SerializedProperty _shadowColor;
61+
private SerializedProperty _shadowColorGlow;
5962

6063
private bool _expandOthers;
6164
private SerializedProperty _allowExtendVertex;
@@ -71,6 +74,7 @@ private void OnEnable()
7174
_colorFilter = serializedObject.FindProperty("m_ColorFilter");
7275
_color = serializedObject.FindProperty("m_Color");
7376
_colorIntensity = serializedObject.FindProperty("m_ColorIntensity");
77+
_colorGlow = serializedObject.FindProperty("m_ColorGlow");
7478

7579
_samplingFilter = serializedObject.FindProperty("m_SamplingFilter");
7680
_samplingIntensity = serializedObject.FindProperty("m_SamplingIntensity");
@@ -88,6 +92,7 @@ private void OnEnable()
8892
_transitionSoftness = serializedObject.FindProperty("m_TransitionSoftness");
8993
_transitionColorFilter = serializedObject.FindProperty("m_TransitionColorFilter");
9094
_transitionColor = serializedObject.FindProperty("m_TransitionColor");
95+
_transitionColorGlow = serializedObject.FindProperty("m_TransitionColorGlow");
9196

9297
_targetMode = serializedObject.FindProperty("m_TargetMode");
9398
_targetColor = serializedObject.FindProperty("m_TargetColor");
@@ -108,6 +113,7 @@ private void OnEnable()
108113
_shadowBlurIntensity = serializedObject.FindProperty("m_ShadowBlurIntensity");
109114
_shadowColorFilter = serializedObject.FindProperty("m_ShadowColorFilter");
110115
_shadowColor = serializedObject.FindProperty("m_ShadowColor");
116+
_shadowColorGlow = serializedObject.FindProperty("m_ShadowColorGlow");
111117

112118
_allowExtendVertex = serializedObject.FindProperty("m_AllowExtendVertex");
113119
}
@@ -141,6 +147,7 @@ public void DrawProperties()
141147
EditorGUI.indentLevel++;
142148
EditorGUILayout.PropertyField(_colorIntensity);
143149
DrawColor(_colorFilter, _color, prevColorFilter);
150+
EditorGUILayout.PropertyField(_colorGlow);
144151
EditorGUI.indentLevel--;
145152
}
146153

@@ -179,6 +186,7 @@ public void DrawProperties()
179186
prevColorFilter = (ColorFilter)_transitionColorFilter.intValue;
180187
EditorGUILayout.PropertyField(_transitionColorFilter);
181188
DrawColor(_transitionColorFilter, _transitionColor, prevColorFilter);
189+
EditorGUILayout.PropertyField(_transitionColorGlow);
182190
}
183191

184192
EditorGUI.indentLevel--;
@@ -237,6 +245,7 @@ public void DrawProperties()
237245

238246
EditorGUILayout.PropertyField(_shadowColorFilter);
239247
EditorGUILayout.PropertyField(_shadowColor);
248+
EditorGUILayout.PropertyField(_shadowColorGlow);
240249
EditorGUILayout.PropertyField(_shadowFade);
241250

242251
switch ((SamplingFilter)_samplingFilter.intValue)

Packages/src/Runtime/UIEffect.cs

+51
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public class UIEffect : UIEffectBase
3030
[SerializeField]
3131
protected Color m_Color = Color.white;
3232

33+
[SerializeField]
34+
protected bool m_ColorGlow = false;
35+
3336
[SerializeField]
3437
protected SamplingFilter m_SamplingFilter = SamplingFilter.None;
3538

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

88+
[SerializeField]
89+
protected bool m_TransitionColorGlow = false;
90+
8591
[SerializeField]
8692
protected TargetMode m_TargetMode = TargetMode.None;
8793

@@ -135,6 +141,9 @@ public class UIEffect : UIEffectBase
135141
[SerializeField]
136142
protected Color m_ShadowColor = Color.white;
137143

144+
[SerializeField]
145+
protected bool m_ShadowColorGlow = false;
146+
138147
[SerializeField]
139148
protected bool m_AllowExtendVertex = true;
140149

@@ -196,6 +205,17 @@ public Color color
196205
}
197206
}
198207

208+
public bool colorGlow
209+
{
210+
get => m_ColorGlow;
211+
set
212+
{
213+
if (m_ColorGlow == value) return;
214+
context.colorGlow = m_ColorGlow = value;
215+
ApplyContextToMaterial();
216+
}
217+
}
218+
199219
public SamplingFilter samplingFilter
200220
{
201221
get => m_SamplingFilter;
@@ -372,6 +392,17 @@ public Color transitionColor
372392
}
373393
}
374394

395+
public bool transitionColorGlow
396+
{
397+
get => m_TransitionColorGlow;
398+
set
399+
{
400+
if (m_TransitionColorGlow == value) return;
401+
context.transitionColorGlow = m_TransitionColorGlow = value;
402+
ApplyContextToMaterial();
403+
}
404+
}
405+
375406
public TargetMode targetMode
376407
{
377408
get => m_TargetMode;
@@ -555,6 +586,17 @@ public Color shadowColor
555586
}
556587
}
557588

589+
public bool shadowGlow
590+
{
591+
get => m_ShadowColorGlow;
592+
set
593+
{
594+
if (m_ShadowColorGlow == value) return;
595+
context.shadowColorGlow = m_ShadowColorGlow = value;
596+
ApplyContextToMaterial();
597+
}
598+
}
599+
558600
public bool allowExtendVertex
559601
{
560602
get => m_AllowExtendVertex;
@@ -623,6 +665,7 @@ protected override void UpdateContext(UIEffectContext c)
623665
c.colorFilter = m_ColorFilter;
624666
c.color = m_Color;
625667
c.colorIntensity = m_ColorIntensity;
668+
c.colorGlow = m_ColorGlow;
626669
c.samplingFilter = m_SamplingFilter;
627670
c.samplingIntensity = m_SamplingIntensity;
628671
c.transitionFilter = m_TransitionFilter;
@@ -637,6 +680,7 @@ protected override void UpdateContext(UIEffectContext c)
637680
c.transitionSoftness = m_TransitionSoftness;
638681
c.transitionColorFilter = m_TransitionColorFilter;
639682
c.transitionColor = m_TransitionColor;
683+
c.transitionColorGlow = m_TransitionColorGlow;
640684
c.targetMode = m_TargetMode;
641685
c.targetColor = m_TargetColor;
642686
c.targetRange = m_TargetRange;
@@ -651,6 +695,7 @@ protected override void UpdateContext(UIEffectContext c)
651695
c.shadowBlurIntensity = m_ShadowBlurIntensity;
652696
c.shadowColorFilter = m_ShadowColorFilter;
653697
c.shadowColor = m_ShadowColor;
698+
c.shadowColorGlow = m_ShadowColorGlow;
654699
c.allowExtendVertex = m_AllowExtendVertex;
655700
}
656701

@@ -716,6 +761,7 @@ public void LoadPreset(UIEffect preset)
716761
m_ColorFilter = preset.m_ColorFilter;
717762
m_Color = preset.m_Color;
718763
m_ColorIntensity = preset.m_ColorIntensity;
764+
m_ColorGlow = preset.m_ColorGlow;
719765

720766
m_SamplingFilter = preset.m_SamplingFilter;
721767
m_SamplingIntensity = preset.m_SamplingIntensity;
@@ -733,6 +779,7 @@ public void LoadPreset(UIEffect preset)
733779
m_TransitionSoftness = preset.m_TransitionSoftness;
734780
m_TransitionColorFilter = preset.m_TransitionColorFilter;
735781
m_TransitionColor = preset.m_TransitionColor;
782+
m_TransitionColorGlow = preset.m_TransitionColorGlow;
736783

737784
m_TargetMode = preset.m_TargetMode;
738785
m_TargetColor = preset.m_TargetColor;
@@ -750,6 +797,7 @@ public void LoadPreset(UIEffect preset)
750797
m_ShadowBlurIntensity = preset.m_ShadowBlurIntensity;
751798
m_ShadowColorFilter = preset.m_ShadowColorFilter;
752799
m_ShadowColor = preset.m_ShadowColor;
800+
m_ShadowColorGlow = preset.m_ShadowColorGlow;
753801

754802
UpdateContext(context);
755803
ApplyContextToMaterial();
@@ -766,6 +814,7 @@ internal void CopyFrom(UIEffectContext c)
766814
m_ColorFilter = c.colorFilter;
767815
m_Color = c.color;
768816
m_ColorIntensity = c.colorIntensity;
817+
m_ColorGlow = c.colorGlow;
769818

770819
m_SamplingFilter = c.samplingFilter;
771820
m_SamplingIntensity = c.samplingIntensity;
@@ -782,6 +831,7 @@ internal void CopyFrom(UIEffectContext c)
782831
m_TransitionSoftness = c.transitionSoftness;
783832
m_TransitionColorFilter = c.transitionColorFilter;
784833
m_TransitionColor = c.transitionColor;
834+
m_TransitionColorGlow = c.transitionColorGlow;
785835

786836
m_TargetMode = c.targetMode;
787837
m_TargetColor = c.targetColor;
@@ -800,6 +850,7 @@ internal void CopyFrom(UIEffectContext c)
800850
m_ShadowBlurIntensity = c.shadowBlurIntensity;
801851
m_ShadowColorFilter = c.shadowColorFilter;
802852
m_ShadowColor = c.shadowColor;
853+
m_ShadowColorGlow = c.shadowColorGlow;
803854

804855
m_AllowExtendVertex = c.allowExtendVertex;
805856

Packages/src/Runtime/UIEffectContext.cs

+12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class UIEffectContext
1818
private static readonly int s_ToneParams = Shader.PropertyToID("_ToneParams");
1919
private static readonly int s_ColorValue = Shader.PropertyToID("_ColorValue");
2020
private static readonly int s_ColorIntensity = Shader.PropertyToID("_ColorIntensity");
21+
private static readonly int s_ColorGlow = Shader.PropertyToID("_ColorGlow");
2122
private static readonly int s_SamplingIntensity = Shader.PropertyToID("_SamplingIntensity");
2223
private static readonly int s_SamplingScale = Shader.PropertyToID("_SamplingScale");
2324
private static readonly int s_TransitionRate = Shader.PropertyToID("_TransitionRate");
@@ -28,11 +29,13 @@ public class UIEffectContext
2829
private static readonly int s_TransitionSoftness = Shader.PropertyToID("_TransitionSoftness");
2930
private static readonly int s_TransitionColorFilter = Shader.PropertyToID("_TransitionColorFilter");
3031
private static readonly int s_TransitionColor = Shader.PropertyToID("_TransitionColor");
32+
private static readonly int s_TransitionColorGlow = Shader.PropertyToID("_TransitionColorGlow");
3133
private static readonly int s_TargetColor = Shader.PropertyToID("_TargetColor");
3234
private static readonly int s_TargetRange = Shader.PropertyToID("_TargetRange");
3335
private static readonly int s_TargetSoftness = Shader.PropertyToID("_TargetSoftness");
3436
private static readonly int s_ShadowColor = Shader.PropertyToID("_ShadowColor");
3537
private static readonly int s_ShadowBlurIntensity = Shader.PropertyToID("_ShadowBlurIntensity");
38+
private static readonly int s_ShadowColorGlow = Shader.PropertyToID("_ShadowColorGlow");
3639

3740
private static readonly string[] s_ToneKeywords =
3841
{
@@ -135,6 +138,7 @@ public class UIEffectContext
135138
public ColorFilter colorFilter = ColorFilter.None;
136139
public float colorIntensity = 1;
137140
public Color color = Color.white;
141+
public bool colorGlow;
138142

139143
public SamplingFilter samplingFilter = SamplingFilter.None;
140144
public float samplingIntensity = 0.5f;
@@ -151,6 +155,7 @@ public class UIEffectContext
151155
public float transitionSoftness = 0.2f;
152156
public ColorFilter transitionColorFilter = ColorFilter.MultiplyAdditive;
153157
public Color transitionColor = new Color(0f, 0.5f, 1.0f, 1.0f);
158+
public bool transitionColorGlow;
154159

155160
public TargetMode targetMode = TargetMode.None;
156161
public Color targetColor = Color.white;
@@ -168,6 +173,7 @@ public class UIEffectContext
168173
public float shadowBlurIntensity;
169174
public ColorFilter shadowColorFilter;
170175
public Color shadowColor;
176+
public bool shadowColorGlow;
171177

172178
public bool allowExtendVertex;
173179

@@ -194,6 +200,7 @@ public void CopyFrom(UIEffectContext preset)
194200
colorFilter = preset.colorFilter;
195201
color = preset.color;
196202
colorIntensity = preset.colorIntensity;
203+
colorGlow = preset.colorGlow;
197204

198205
samplingFilter = preset.samplingFilter;
199206
samplingIntensity = preset.samplingIntensity;
@@ -210,6 +217,7 @@ public void CopyFrom(UIEffectContext preset)
210217
transitionSoftness = preset.transitionSoftness;
211218
transitionColor = preset.transitionColor;
212219
transitionColorFilter = preset.transitionColorFilter;
220+
transitionColorGlow = preset.transitionColorGlow;
213221

214222
targetMode = preset.targetMode;
215223
targetColor = preset.targetColor;
@@ -227,6 +235,7 @@ public void CopyFrom(UIEffectContext preset)
227235
shadowBlurIntensity = preset.shadowBlurIntensity;
228236
shadowColorFilter = preset.shadowColorFilter;
229237
shadowColor = preset.shadowColor;
238+
shadowColorGlow = preset.shadowColorGlow;
230239

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

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

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

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

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

281293
SetKeyword(material, s_ToneKeywords, (int)toneFilter);
282294
SetKeyword(material, s_ColorKeywords, (int)colorFilter);

Packages/src/Shaders/UIEffect.cginc

+6
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@ uniform float4 _MainTex_TexelSize;
55
uniform float _ToneIntensity;
66
uniform half4 _ColorValue;
77
uniform float _ColorIntensity;
8+
uniform int _ColorGlow;
89
uniform float _SamplingIntensity;
910
uniform float _SamplingScale;
1011
uniform sampler2D _TransitionTex;
1112
uniform float4 _TransitionTex_ST;
1213
uniform float _TransitionRate;
1314
uniform int _TransitionReverse;
1415
uniform half4 _TransitionColor;
16+
uniform int _TransitionColorGlow;
1517
uniform float _TransitionSoftness;
1618
uniform float _TransitionWidth;
1719
uniform fixed4 _TargetColor;
1820
uniform float _TargetRange;
1921
uniform float _TargetSoftness;
2022
uniform float _ShadowBlurIntensity;
2123
uniform half4 _ShadowColor;
24+
uniform int _ShadowColorGlow;
2225

2326
// For performance reasons, limit the sampling of blur in TextMeshPro.
2427
#ifdef UIEFFECT_TEXTMESHPRO
@@ -180,6 +183,7 @@ half4 apply_color_filter(half4 color, const half4 factor, const float intensity)
180183
}
181184
#endif
182185
color = lerp(inColor, color, intensity);
186+
color.a *= 1 - _ColorGlow;
183187
return color;
184188
}
185189

@@ -227,6 +231,7 @@ half4 apply_transition_color_filter(half4 color, const half4 factor, const float
227231
}
228232
#endif
229233
color = lerp(inColor, color, intensity);
234+
color.a *= 1 - _TransitionColorGlow;
230235
return color;
231236
}
232237

@@ -278,6 +283,7 @@ half4 apply_shadow_color_filter(half4 color, const half4 factor, const float int
278283
}
279284
#endif
280285
color = lerp(inColor, color, intensity);
286+
color.a *= 1 - _ShadowColorGlow;
281287
return color;
282288
}
283289

0 commit comments

Comments
 (0)