mirror of
https://github.com/mob-sakai/UIEffect.git
synced 2026-11-19 17:22:37 +08:00
fix: ShadowMode.Mirror does not flip the effect
This commit is contained in:
@@ -66,6 +66,8 @@ namespace Coffee.UIEffects
|
||||
private static readonly int s_GradationTex_ST = Shader.PropertyToID("_GradationTex_ST");
|
||||
private static readonly int s_RootViewMatrix = Shader.PropertyToID("_RootViewMatrix");
|
||||
private static readonly int s_GradViewMatrix = Shader.PropertyToID("_GradViewMatrix");
|
||||
private static readonly int s_MirrorRootViewMatrix = Shader.PropertyToID("_MirrorRootViewMatrix");
|
||||
private static readonly int s_MirrorGradViewMatrix = Shader.PropertyToID("_MirrorGradViewMatrix");
|
||||
private static readonly int s_CanvasToWorldMatrix = Shader.PropertyToID("_CanvasToWorldMatrix");
|
||||
|
||||
private static readonly string[] s_ToneKeywords =
|
||||
@@ -547,6 +549,20 @@ namespace Coffee.UIEffects
|
||||
var gradScale = 1f / GetMultiplier(GetGradationRotation());
|
||||
material.SetMatrix(s_GradViewMatrix, Matrix4x4.TRS(pivot, gradRotation, scale * gradScale) * w2LMat);
|
||||
|
||||
if (m_ShadowMode == ShadowMode.Mirror)
|
||||
{
|
||||
var mirrorInv = 1f / m_ShadowMirrorScale;
|
||||
var mirrorOffset = new Vector3(0, size.y / 2 * (mirrorInv + 1) - m_ShadowDistance.y * mirrorInv, 0);
|
||||
var mirrorScale = new Vector3(1, mirrorInv, 1);
|
||||
var udScale = new Vector3(scale.x, -scale.y, scale.z);
|
||||
material.SetMatrix(s_MirrorRootViewMatrix,
|
||||
Matrix4x4.TRS(pivot, rootRotation, udScale * rootScale)
|
||||
* Matrix4x4.TRS(mirrorOffset, Quaternion.identity, mirrorScale) * w2LMat);
|
||||
material.SetMatrix(s_MirrorGradViewMatrix,
|
||||
Matrix4x4.TRS(pivot, gradRotation, udScale * gradScale)
|
||||
* Matrix4x4.TRS(mirrorOffset, Quaternion.identity, mirrorScale) * w2LMat);
|
||||
}
|
||||
|
||||
if (canvas.renderMode == RenderMode.ScreenSpaceOverlay || !canvas.worldCamera)
|
||||
{
|
||||
material.SetMatrix(s_CanvasToWorldMatrix, canvas.transform.localToWorldMatrix);
|
||||
|
||||
@@ -80,10 +80,10 @@ namespace Coffee.UIEffects
|
||||
private static readonly Func<UIVertex, UIVertex, UIVertex, float, UIVertex> s_OnLerpVertex =
|
||||
null;
|
||||
|
||||
private static readonly Func<UIVertex, UIVertex> s_OnMarkAsShadow =
|
||||
vt =>
|
||||
private static readonly Func<UIVertex, float, UIVertex> s_OnMarkAsShadow =
|
||||
(vt, s) =>
|
||||
{
|
||||
vt.uv1.x -= 2;
|
||||
vt.uv1.x -= s;
|
||||
return vt;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Coffee.UIEffects
|
||||
{
|
||||
public static class ShadowUtil
|
||||
{
|
||||
public static Func<UIVertex, UIVertex> onMarkAsShadow;
|
||||
public static Func<UIVertex, float, UIVertex> onMarkAsShadow;
|
||||
|
||||
public static void DoShadow(List<UIVertex> verts, Vector2[] vectors, Vector2 distance, int iteration,
|
||||
float fade)
|
||||
@@ -30,14 +30,7 @@ namespace Coffee.UIEffects
|
||||
{
|
||||
if (onMarkAsShadow != null)
|
||||
{
|
||||
verts[i] = onMarkAsShadow(verts[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
var vt = verts[i];
|
||||
vt.uv0.z -= 8;
|
||||
vt.uv0.w -= 8;
|
||||
verts[i] = vt;
|
||||
verts[i] = onMarkAsShadow(verts[i], 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,6 +47,15 @@ namespace Coffee.UIEffects
|
||||
var offset = distance.y - (scale + 1) * pivot * height;
|
||||
var range = new Vector2(rect2.yMin, rect2.yMax);
|
||||
ApplyMirror(verts, count, rate, range, scale, offset, fade);
|
||||
|
||||
// Mark as shadow vertices.
|
||||
for (var i = 0; i < verts.Count - count; i++)
|
||||
{
|
||||
if (onMarkAsShadow != null)
|
||||
{
|
||||
verts[i] = onMarkAsShadow(verts[i], 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ApplyMirror(List<UIVertex> verts, int count, float rate, Vector2 range, float scale,
|
||||
|
||||
@@ -91,10 +91,10 @@ namespace Coffee.UIEffects
|
||||
};
|
||||
#endif
|
||||
|
||||
private static readonly Func<UIVertex, UIVertex> s_OnMarkAsShadow =
|
||||
vt =>
|
||||
private static readonly Func<UIVertex, float, UIVertex> s_OnMarkAsShadow =
|
||||
(vt, s) =>
|
||||
{
|
||||
vt.uv2.x -= 2;
|
||||
vt.uv2.x -= s;
|
||||
return vt;
|
||||
};
|
||||
|
||||
|
||||
@@ -63,6 +63,8 @@ uniform const sampler2D _GradationTex;
|
||||
uniform const float4 _GradationTex_ST;
|
||||
uniform const matrix _RootViewMatrix;
|
||||
uniform const matrix _GradViewMatrix;
|
||||
uniform const matrix _MirrorRootViewMatrix;
|
||||
uniform const matrix _MirrorGradViewMatrix;
|
||||
uniform const matrix _CanvasToWorldMatrix;
|
||||
|
||||
// For performance reasons, limit the sampling of blur in TextMeshPro.
|
||||
@@ -760,8 +762,17 @@ half4 uieffect(half4 origin, float2 uv, float4 uvMask, float4 wpos)
|
||||
wpos = mul(_CanvasToWorldMatrix, wpos);
|
||||
#endif
|
||||
const half rate = get_target_rate(origin.rgb);
|
||||
const float2 uvLocal = saturate(mul(_RootViewMatrix, wpos)).xy;
|
||||
const float2 uvGrad = mul(_GradViewMatrix, wpos).xy;
|
||||
float2 uvLocal = saturate(mul(_RootViewMatrix, wpos)).xy;
|
||||
float2 uvGrad = mul(_GradViewMatrix, wpos).xy;
|
||||
|
||||
// Mirror
|
||||
if (uvMask.x < -3)
|
||||
{
|
||||
uvLocal = saturate(mul(_MirrorRootViewMatrix, wpos)).xy;
|
||||
uvGrad = saturate(mul(_MirrorGradViewMatrix, wpos)).xy;
|
||||
uvMask.x += 4;
|
||||
}
|
||||
|
||||
const float isShadow = uvMask.x < 0 ? 1 : 0;
|
||||
uvMask.x += isShadow * 2;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user