mirror of
https://github.com/mob-sakai/UIEffect.git
synced 2026-11-19 17:22:37 +08:00
feat: SamplingFilter.EdgeAlpha and SamplingFilter.EdgeLuminance now support the Sampling Width property for edge width
This commit is contained in:
@@ -35,6 +35,7 @@ namespace Coffee.UIEffects.Editors
|
||||
|
||||
private SerializedProperty _samplingFilter;
|
||||
private SerializedProperty _samplingIntensity;
|
||||
private SerializedProperty _samplingWidth;
|
||||
private SerializedProperty _samplingScale;
|
||||
|
||||
private SerializedProperty _transitionFilter;
|
||||
@@ -97,6 +98,7 @@ namespace Coffee.UIEffects.Editors
|
||||
|
||||
_samplingFilter = serializedObject.FindProperty("m_SamplingFilter");
|
||||
_samplingIntensity = serializedObject.FindProperty("m_SamplingIntensity");
|
||||
_samplingWidth = serializedObject.FindProperty("m_SamplingWidth");
|
||||
_samplingScale = serializedObject.FindProperty("m_SamplingScale");
|
||||
|
||||
_transitionFilter = serializedObject.FindProperty("m_TransitionFilter");
|
||||
@@ -186,6 +188,12 @@ namespace Coffee.UIEffects.Editors
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.PropertyField(_samplingIntensity);
|
||||
if (_samplingFilter.intValue == (int)SamplingFilter.EdgeAlpha
|
||||
|| _samplingFilter.intValue == (int)SamplingFilter.EdgeLuminance)
|
||||
{
|
||||
EditorGUILayout.PropertyField(_samplingWidth);
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,10 @@ namespace Coffee.UIEffects
|
||||
[SerializeField]
|
||||
protected float m_SamplingIntensity = 0.5f;
|
||||
|
||||
[Range(0.5f, 10f)]
|
||||
[SerializeField]
|
||||
protected float m_SamplingWidth = 1;
|
||||
|
||||
[PowerRange(0.01f, 100f, 10f)]
|
||||
[SerializeField]
|
||||
protected float m_SamplingScale = 1f;
|
||||
@@ -278,6 +282,18 @@ namespace Coffee.UIEffects
|
||||
}
|
||||
}
|
||||
|
||||
public float samplingWidth
|
||||
{
|
||||
get => m_SamplingWidth;
|
||||
set
|
||||
{
|
||||
value = Mathf.Clamp(value, 0.5f, 10);
|
||||
if (Mathf.Approximately(m_SamplingWidth, value)) return;
|
||||
context.samplingWidth = m_SamplingWidth = value;
|
||||
SetMaterialDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public float samplingScale
|
||||
{
|
||||
get => m_SamplingScale;
|
||||
@@ -792,6 +808,7 @@ namespace Coffee.UIEffects
|
||||
|
||||
c.samplingFilter = m_SamplingFilter;
|
||||
c.samplingIntensity = m_SamplingIntensity;
|
||||
c.samplingWidth = m_SamplingWidth;
|
||||
|
||||
c.transitionFilter = m_TransitionFilter;
|
||||
c.transitionRate = m_TransitionRate;
|
||||
@@ -917,6 +934,7 @@ namespace Coffee.UIEffects
|
||||
|
||||
m_SamplingFilter = preset.m_SamplingFilter;
|
||||
m_SamplingIntensity = preset.m_SamplingIntensity;
|
||||
m_SamplingWidth = preset.m_SamplingWidth;
|
||||
|
||||
m_TransitionFilter = preset.m_TransitionFilter;
|
||||
m_TransitionRate = preset.m_TransitionRate;
|
||||
@@ -977,6 +995,7 @@ namespace Coffee.UIEffects
|
||||
|
||||
m_SamplingFilter = c.samplingFilter;
|
||||
m_SamplingIntensity = c.samplingIntensity;
|
||||
m_SamplingWidth = c.samplingWidth;
|
||||
|
||||
m_TransitionFilter = c.transitionFilter;
|
||||
m_TransitionRate = c.transitionRate;
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace Coffee.UIEffects
|
||||
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_SamplingWidth = Shader.PropertyToID("_SamplingWidth");
|
||||
private static readonly int s_SamplingScale = Shader.PropertyToID("_SamplingScale");
|
||||
private static readonly int s_TransitionRate = Shader.PropertyToID("_TransitionRate");
|
||||
private static readonly int s_TransitionReverse = Shader.PropertyToID("_TransitionReverse");
|
||||
@@ -142,6 +143,7 @@ namespace Coffee.UIEffects
|
||||
|
||||
public SamplingFilter samplingFilter = SamplingFilter.None;
|
||||
public float samplingIntensity = 0.5f;
|
||||
public float samplingWidth;
|
||||
|
||||
public TransitionFilter transitionFilter = TransitionFilter.None;
|
||||
public float transitionRate = 0.5f;
|
||||
@@ -211,6 +213,7 @@ namespace Coffee.UIEffects
|
||||
|
||||
samplingFilter = preset.samplingFilter;
|
||||
samplingIntensity = preset.samplingIntensity;
|
||||
samplingWidth = preset.samplingWidth;
|
||||
|
||||
transitionFilter = preset.transitionFilter;
|
||||
transitionRate = preset.transitionRate;
|
||||
@@ -275,6 +278,7 @@ namespace Coffee.UIEffects
|
||||
material.SetInt(s_ColorGlow, colorGlow ? 1 : 0);
|
||||
|
||||
material.SetFloat(s_SamplingIntensity, Mathf.Clamp01(samplingIntensity));
|
||||
material.SetFloat(s_SamplingWidth, samplingWidth);
|
||||
material.SetFloat(s_SamplingScale, actualSamplingScale);
|
||||
|
||||
material.SetFloat(s_TransitionRate, Mathf.Clamp01(transitionRate));
|
||||
|
||||
@@ -7,6 +7,7 @@ uniform half4 _ColorValue;
|
||||
uniform float _ColorIntensity;
|
||||
uniform int _ColorGlow;
|
||||
uniform float _SamplingIntensity;
|
||||
uniform float _SamplingWidth;
|
||||
uniform float _SamplingScale;
|
||||
uniform sampler2D _TransitionTex;
|
||||
uniform float4 _TransitionTex_ST;
|
||||
@@ -52,6 +53,9 @@ uniform int _ShadowColorGlow;
|
||||
#define UIEFFECT_SAMPLE_CLAMP(uv, uvMask) uieffect_frag(uv) \
|
||||
* step(uvMask.x, uv.x) * step(uv.x, uvMask.z) \
|
||||
* step(uvMask.y, uv.y) * step(uv.y, uvMask.w)
|
||||
#define TEX_SAMPLE_CLAMP(uv, uvMask) tex2D(_MainTex, uv) \
|
||||
* step(uvMask.x, uv.x) * step(uv.x, uvMask.z) \
|
||||
* step(uvMask.y, uv.y) * step(uv.y, uvMask.w)
|
||||
|
||||
float2 texel_size()
|
||||
{
|
||||
@@ -475,26 +479,17 @@ half4 uieffect(float2 uv, const float4 uvMask, const float2 uvLocal)
|
||||
#elif SAMPLING_EDGE_LUMINANCE || SAMPLING_EDGE_ALPHA
|
||||
{
|
||||
// Pixel size
|
||||
const float dx = texel_size().x;
|
||||
const float dy = texel_size().y;
|
||||
const float2 d = texel_size() * _SamplingWidth;
|
||||
|
||||
// Pixel values around the current pixel (3x3, 8 neighbors)
|
||||
const float2 uv00 = uv + half2(-dx, -dy);
|
||||
const half v00 = to_value(UIEFFECT_SAMPLE_CLAMP(uv00, uvMask));
|
||||
const float2 uv01 = uv + half2(-dx, 0.0);
|
||||
const half v01 = to_value(UIEFFECT_SAMPLE_CLAMP(uv01, uvMask));
|
||||
const float2 uv02 = uv + half2(-dx, +dy);
|
||||
const half v02 = to_value(UIEFFECT_SAMPLE_CLAMP(uv02, uvMask));
|
||||
const float2 uv10 = uv + half2(0.0, -dy);
|
||||
const half v10 = to_value(UIEFFECT_SAMPLE_CLAMP(uv10, uvMask));
|
||||
const float2 uv12 = uv + half2(0.0, +dy);
|
||||
const half v12 = to_value(UIEFFECT_SAMPLE_CLAMP(uv12, uvMask));
|
||||
const float2 uv20 = uv + half2(+dx, -dy);
|
||||
const half v20 = to_value(UIEFFECT_SAMPLE_CLAMP(uv20, uvMask));
|
||||
const float2 uv21 = uv + half2(+dx, 0.0);
|
||||
const half v21 = to_value(UIEFFECT_SAMPLE_CLAMP(uv21, uvMask));
|
||||
const float2 uv22 = uv + half2(+dx, +dy);
|
||||
const half v22 = to_value(UIEFFECT_SAMPLE_CLAMP(uv22, uvMask));
|
||||
const half v00 = to_value(TEX_SAMPLE_CLAMP((uv + half2(-d.x, -d.y)), uvMask));
|
||||
const half v01 = to_value(TEX_SAMPLE_CLAMP((uv + half2(-d.x, 0.0)), uvMask));
|
||||
const half v02 = to_value(TEX_SAMPLE_CLAMP((uv + half2(-d.x, +d.y)), uvMask));
|
||||
const half v10 = to_value(TEX_SAMPLE_CLAMP((uv + half2(0.0, -d.y)), uvMask));
|
||||
const half v12 = to_value(TEX_SAMPLE_CLAMP((uv + half2(0.0, +d.y)), uvMask));
|
||||
const half v20 = to_value(TEX_SAMPLE_CLAMP((uv + half2(+d.x, -d.y)), uvMask));
|
||||
const half v21 = to_value(TEX_SAMPLE_CLAMP((uv + half2(+d.x, 0.0)), uvMask));
|
||||
const half v22 = to_value(TEX_SAMPLE_CLAMP((uv + half2(+d.x, +d.y)), uvMask));
|
||||
|
||||
// Apply Sobel operator
|
||||
half sobel_h = v00 * -1.0 + v01 * -2.0 + v02 * -1.0 + v20 * 1.0 + v21 * 2.0 + v22 * 1.0;
|
||||
|
||||
Reference in New Issue
Block a user