fix: colors appeared darker when alpha was low

This commit is contained in:
mob-sakai
2025-04-06 11:41:04 +09:00
parent 01bbeedde7
commit 21172f37c2
17 changed files with 64 additions and 34 deletions
@@ -159,7 +159,7 @@ SubShader {
{
v2f IN = _fragInput;
float2 uvMove = uv - IN.texcoord0;
fixed4 color = fixed4(IN.color.rgb, IN.color.a * tex2D(_MainTex, IN.texcoord0 + uvMove).a);
fixed4 color = fixed4(IN.color.rgb, tex2D(_MainTex, IN.texcoord0 + uvMove).a);
color.rgb *= color.a;
return color;
}
@@ -171,6 +171,7 @@ SubShader {
{
_fragInput = IN;
half4 color = uieffect(IN.texcoord0, IN.uvMask, IN.worldPosition);
color *= IN.color.a;
// Alternative implementation to UnityGet2DClipping with support for softness.
#if UNITY_UI_CLIP_RECT
@@ -165,7 +165,7 @@ SubShader{
v2f IN = _fragInput;
float2 uvMove = uv - IN.texcoord0;
fixed4 color = tex2D(_MainTex, IN.texcoord0 + uvMove);
color = fixed4 (tex2D(_FaceTex, IN.texcoord1).rgb * IN.color.rgb, IN.color.a * color.a);
color = fixed4 (tex2D(_FaceTex, IN.texcoord1).rgb * IN.color.rgb, color.a);
color.rgb *= color.a;
return color;
}
@@ -177,6 +177,7 @@ SubShader{
{
_fragInput = IN;
half4 color = uieffect(IN.texcoord0, IN.uvMask, IN.worldPosition);
color *= IN.color.a;
// Alternative implementation to UnityGet2DClipping with support for softness.
#if UNITY_UI_CLIP_RECT
@@ -344,7 +344,7 @@ SubShader {
faceColor.rgb += glowColor.rgb * glowColor.a;
#endif
return faceColor * input.color.a;
return faceColor;
}
#define UIEFFECT_TEXTMESHPRO 1
@@ -356,6 +356,7 @@ SubShader {
UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input;
half4 faceColor = uieffect(input.atlas, input.uvMask, input.worldPosition);
faceColor *= input.color.a;
#if UNITY_UI_CLIP_RECT
half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(input.mask.xy)) * input.mask.zw);
@@ -338,7 +338,7 @@ SubShader {
faceColor.rgb += glowColor.rgb * glowColor.a;
#endif
return faceColor * input.color.a;
return faceColor;
}
@@ -351,6 +351,7 @@ SubShader {
UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input;
half4 faceColor = uieffect(input.atlas, input.uvMask, input.worldPosition);
faceColor *= input.color.a;
// Alternative implementation to UnityGet2DClipping with support for softness.
#if UNITY_UI_CLIP_RECT
@@ -146,6 +146,7 @@ SubShader {
// ==== UIEFFECT START ====
float4 uvMask : TEXCOORD5;
float4 worldPosition : TEXCOORD6;
fixed alpha : TEXCOORD7;
// ==== UIEFFECT END ====
};
@@ -189,17 +190,17 @@ SubShader {
{
input.color.rgb = UIGammaToLinear(input.color.rgb);
}
float opacity = input.color.a;
float opacity = 1;
#if (UNDERLAY_ON | UNDERLAY_INNER)
opacity = 1.0;
#endif
fixed4 faceColor = fixed4(input.color.rgb, opacity) * _FaceColor;
// faceColor.rgb *= faceColor.a;
faceColor.rgb *= faceColor.a;
fixed4 outlineColor = _OutlineColor;
outlineColor.a *= opacity;
// outlineColor.rgb *= outlineColor.a;
outlineColor.rgb *= outlineColor.a;
outlineColor = lerp(faceColor, outlineColor, sqrt(min(1.0, (outline * 2))));
#if (UNDERLAY_ON | UNDERLAY_INNER)
@@ -224,13 +225,14 @@ SubShader {
const half2 maskSoftness = half2(max(_UIMaskSoftnessX, _MaskSoftnessX), max(_UIMaskSoftnessY, _MaskSoftnessY));
output.mask = half4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * maskSoftness + pixelSize.xy));
#if (UNDERLAY_ON || UNDERLAY_INNER)
output.texcoord1 = float4(input.texcoord0 + layerOffset, input.color.a, 0);
output.texcoord1 = float4(input.texcoord0 + layerOffset, 1, 0);
output.underlayParam = half2(layerScale, layerBias);
#endif
// ==== UIEFFECT START ====
output.uvMask = input.texcoord2;
output.worldPosition = input.vertex;
output.alpha = input.color.a;
// ==== UIEFFECT END ====
return output;
@@ -277,6 +279,7 @@ SubShader {
UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input;
half4 c = uieffect(input.texcoord0.xy, input.uvMask, input.worldPosition);
c *= input.alpha;
// Alternative implementation to UnityGet2DClipping with support for softness.
#if UNITY_UI_CLIP_RECT
@@ -145,7 +145,8 @@ SubShader {
#endif
// ==== UIEFFECT START ====
float4 uvMask : TEXCOORD4;
float4 worldPosition :TEXCOORD5;
float4 worldPosition : TEXCOORD5;
fixed alpha : TEXCOORD6;
// ==== UIEFFECT END ====
};
@@ -185,7 +186,7 @@ SubShader {
color = SRGBToLinear(input.color);
#endif
float opacity = color.a;
float opacity = 1;
#if (UNDERLAY_ON | UNDERLAY_INNER)
opacity = 1.0;
#endif
@@ -216,13 +217,14 @@ SubShader {
float x = -(_UnderlayOffsetX * _ScaleRatioC) * _GradientScale / _TextureWidth;
float y = -(_UnderlayOffsetY * _ScaleRatioC) * _GradientScale / _TextureHeight;
output.texcoord2 = float4(input.texcoord0 + float2(x, y), input.color.a, 0);
output.texcoord2 = float4(input.texcoord0 + float2(x, y), 1, 0);
output.underlayColor = underlayColor;
#endif
// ==== UIEFFECT START ====
output.uvMask = input.texcoord2;
output.worldPosition = input.position;
output.alpha = input.color.a;
// ==== UIEFFECT END ====
return output;
@@ -291,6 +293,7 @@ SubShader {
UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input;
half4 faceColor = uieffect(input.texcoord0, input.uvMask, input.worldPosition);
faceColor *= input.alpha;
// Alternative implementation to UnityGet2DClipping with support for softness
#if UNITY_UI_CLIP_RECT
@@ -144,6 +144,7 @@ SubShader {
// ==== UIEFFECT START ====
float4 uvMask : TEXCOORD5;
float4 worldPosition : TEXCOORD6;
fixed alpha : TEXCOORD7;
// ==== UIEFFECT END ====
};
@@ -187,17 +188,17 @@ SubShader {
{
input.color.rgb = UIGammaToLinear(input.color.rgb);
}
float opacity = input.color.a;
float opacity = 1;
#if (UNDERLAY_ON | UNDERLAY_INNER)
opacity = 1.0;
#endif
fixed4 faceColor = fixed4(input.color.rgb, opacity) * _FaceColor;
//faceColor.rgb *= faceColor.a;
faceColor.rgb *= faceColor.a;
fixed4 outlineColor = _OutlineColor;
outlineColor.a *= opacity;
//outlineColor.rgb *= outlineColor.a;
outlineColor.rgb *= outlineColor.a;
outlineColor = lerp(faceColor, outlineColor, sqrt(min(1.0, (outline * 2))));
#if (UNDERLAY_ON | UNDERLAY_INNER)
@@ -223,13 +224,14 @@ SubShader {
const half2 maskSoftness = half2(max(_UIMaskSoftnessX, _MaskSoftnessX), max(_UIMaskSoftnessY, _MaskSoftnessY));
output.mask = half4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * maskSoftness + pixelSize.xy));
#if (UNDERLAY_ON || UNDERLAY_INNER)
output.texcoord1 = float4(input.texcoord0 + layerOffset, input.color.a, 0);
output.texcoord1 = float4(input.texcoord0 + layerOffset, 1, 0);
output.underlayParam = half2(layerScale, layerBias);
#endif
// ==== UIEFFECT START ====
output.uvMask = input.texcoord2;
output.worldPosition = input.vertex;
output.alpha = input.color.a;
// ==== UIEFFECT END ====
return output;
@@ -278,7 +280,8 @@ SubShader {
UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input;
half4 c = uieffect(input.texcoord0.xy, input.uvMask, input.worldPosition);
c *= input.alpha;
// Alternative implementation to UnityGet2DClipping with support for softness.
#if UNITY_UI_CLIP_RECT
half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(input.mask.xy)) * input.mask.zw);
@@ -346,7 +346,7 @@ SubShader {
faceColor.rgb += glowColor.rgb * glowColor.a;
#endif
return faceColor * input.color.a;
return faceColor;
}
#define UIEFFECT_TEXTMESHPRO 1
#include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc"
@@ -357,7 +357,8 @@ SubShader {
UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input;
half4 faceColor = uieffect(input.atlas, input.uvMask, input.worldPosition);
faceColor *= input.color.a;
#if UNITY_UI_CLIP_RECT
half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(input.mask.xy)) * input.mask.zw);
faceColor *= m.x * m.y;
@@ -152,7 +152,7 @@ SubShader {
{
v2f IN = _fragInput;
float2 uvMove = uv - IN.texcoord0;
fixed4 color = fixed4(IN.color.rgb, IN.color.a * tex2D(_MainTex, IN.texcoord0 + uvMove).a);
fixed4 color = fixed4(IN.color.rgb, tex2D(_MainTex, IN.texcoord0 + uvMove).a);
color.rgb *= color.a;
return color;
}
@@ -165,6 +165,7 @@ SubShader {
{
_fragInput = IN;
fixed4 color = uieffect(IN.texcoord0, IN.uvMask, IN.worldPosition);
color *= IN.color.a;
// Alternative implementation to UnityGet2DClipping with support for softness.
#if UNITY_UI_CLIP_RECT
@@ -166,7 +166,7 @@ SubShader{
v2f IN = _fragInput;
float2 uvMove = uv - IN.texcoord0;
fixed4 color = tex2D(_MainTex, IN.texcoord0 + uvMove);
color = fixed4 (tex2D(_FaceTex, IN.texcoord1).rgb * IN.color.rgb, IN.color.a * color.a);
color = fixed4 (tex2D(_FaceTex, IN.texcoord1).rgb * IN.color.rgb, color.a);
color.rgb *= color.a;
return color;
}
@@ -179,6 +179,7 @@ SubShader{
{
_fragInput = IN;
fixed4 color = uieffect(IN.texcoord0, IN.uvMask, IN.worldPosition);
color *= IN.color.a;
// Alternative implementation to UnityGet2DClipping with support for softness.
#if UNITY_UI_CLIP_RECT
@@ -338,7 +338,7 @@ SubShader {
faceColor.rgb += glowColor.rgb * glowColor.a;
#endif
return faceColor * input.color.a;
return faceColor;
}
#define UIEFFECT_TEXTMESHPRO 1
@@ -350,6 +350,7 @@ SubShader {
UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input;
half4 faceColor = uieffect(input.atlas, input.uvMask, input.worldPosition);
faceColor *= input.color.a;
#if UNITY_UI_CLIP_RECT
half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(input.mask.xy)) * input.mask.zw);
@@ -329,7 +329,7 @@ SubShader {
faceColor.rgb += glowColor.rgb * glowColor.a;
#endif
return faceColor * input.color.a;
return faceColor;
}
#define UIEFFECT_TEXTMESHPRO 1
@@ -341,6 +341,7 @@ SubShader {
UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input;
half4 faceColor = uieffect(input.atlas, input.uvMask, input.worldPosition);
faceColor *= input.color.a;
// Alternative implementation to UnityGet2DClipping with support for softness.
#if UNITY_UI_CLIP_RECT
@@ -143,6 +143,7 @@ SubShader {
// ==== UIEFFECT START ====
float4 uvMask : TEXCOORD5;
float4 worldPosition : TEXCOORD6;
fixed alpha : TEXCOORD7;
// ==== UIEFFECT END ====
};
@@ -181,17 +182,17 @@ SubShader {
float bias = (0.5 - weight) * scale - 0.5;
float outline = _OutlineWidth * _ScaleRatioA * 0.5 * scale;
float opacity = input.color.a;
float opacity = 1;
#if (UNDERLAY_ON | UNDERLAY_INNER)
opacity = 1.0;
#endif
fixed4 faceColor = fixed4(input.color.rgb, opacity) * _FaceColor;
// faceColor.rgb *= faceColor.a;
faceColor.rgb *= faceColor.a;
fixed4 outlineColor = _OutlineColor;
outlineColor.a *= opacity;
// outlineColor.rgb *= outlineColor.a;
outlineColor.rgb *= outlineColor.a;
outlineColor = lerp(faceColor, outlineColor, sqrt(min(1.0, (outline * 2))));
#if (UNDERLAY_ON | UNDERLAY_INNER)
@@ -216,13 +217,14 @@ SubShader {
const half2 maskSoftness = half2(max(_UIMaskSoftnessX, _MaskSoftnessX), max(_UIMaskSoftnessY, _MaskSoftnessY));
output.mask = half4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * maskSoftness + pixelSize.xy));
#if (UNDERLAY_ON || UNDERLAY_INNER)
output.texcoord1 = float4(input.texcoord0 + layerOffset, input.color.a, 0);
output.texcoord1 = float4(input.texcoord0 + layerOffset, 1, 0);
output.underlayParam = half2(layerScale, layerBias);
#endif
// ==== UIEFFECT START ====
output.uvMask = input.texcoord2;
output.worldPosition = input.vertex;
output.alpha = input.color.a;
// ==== UIEFFECT END ====
return output;
@@ -269,6 +271,7 @@ SubShader {
UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input;
half4 c = uieffect(input.texcoord0.xy, input.uvMask, input.worldPosition);
c *= input.alpha;
// Alternative implementation to UnityGet2DClipping with support for softness.
#if UNITY_UI_CLIP_RECT
@@ -146,6 +146,7 @@ SubShader {
// ==== UIEFFECT START ====
float4 uvMask : TEXCOORD4;
float4 worldPosition : TEXCOORD5;
fixed alpha : TEXCOORD6;
// ==== UIEFFECT END ====
};
@@ -185,7 +186,7 @@ SubShader {
color = SRGBToLinear(input.color);
#endif
float opacity = color.a;
float opacity = 1;
#if (UNDERLAY_ON | UNDERLAY_INNER)
opacity = 1.0;
#endif
@@ -216,13 +217,14 @@ SubShader {
float x = -(_UnderlayOffsetX * _ScaleRatioC) * _GradientScale / _TextureWidth;
float y = -(_UnderlayOffsetY * _ScaleRatioC) * _GradientScale / _TextureHeight;
output.texcoord2 = float4(input.texcoord0 + float2(x, y), input.color.a, 0);
output.texcoord2 = float4(input.texcoord0 + float2(x, y), 1, 0);
output.underlayColor = underlayColor;
#endif
// ==== UIEFFECT START ====
output.uvMask = input.texcoord2;
output.worldPosition = input.position;
output.alpha = input.color.a;
// ==== UIEFFECT END ====
return output;
@@ -291,6 +293,7 @@ SubShader {
UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input;
half4 faceColor = uieffect(input.texcoord0, input.uvMask, input.worldPosition);
faceColor *= input.alpha;
// Alternative implementation to UnityGet2DClipping with support for softness
#if UNITY_UI_CLIP_RECT
@@ -144,6 +144,7 @@ SubShader {
// ==== UIEFFECT START ====
float4 uvMask : TEXCOORD5;
float4 worldPosition : TEXCOORD6;
fixed alpha : TEXCOORD7;
// ==== UIEFFECT END ====
};
@@ -182,17 +183,17 @@ SubShader {
float bias = (0.5 - weight) * scale - 0.5;
float outline = _OutlineWidth * _ScaleRatioA * 0.5 * scale;
float opacity = input.color.a;
float opacity = 1;
#if (UNDERLAY_ON | UNDERLAY_INNER)
opacity = 1.0;
#endif
fixed4 faceColor = fixed4(input.color.rgb, opacity) * _FaceColor;
// faceColor.rgb *= faceColor.a;
faceColor.rgb *= faceColor.a;
fixed4 outlineColor = _OutlineColor;
outlineColor.a *= opacity;
// outlineColor.rgb *= outlineColor.a;
outlineColor.rgb *= outlineColor.a;
outlineColor = lerp(faceColor, outlineColor, sqrt(min(1.0, (outline * 2))));
#if (UNDERLAY_ON | UNDERLAY_INNER)
@@ -217,13 +218,14 @@ SubShader {
const half2 maskSoftness = half2(max(_UIMaskSoftnessX, _MaskSoftnessX), max(_UIMaskSoftnessY, _MaskSoftnessY));
output.mask = half4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * maskSoftness + pixelSize.xy));
#if (UNDERLAY_ON || UNDERLAY_INNER)
output.texcoord1 = float4(input.texcoord0 + layerOffset, input.color.a, 0);
output.texcoord1 = float4(input.texcoord0 + layerOffset, 1, 0);
output.underlayParam = half2(layerScale, layerBias);
#endif
// ==== UIEFFECT START ====
output.uvMask = input.texcoord2;
output.worldPosition = input.vertex;
output.alpha = input.color.a;
// ==== UIEFFECT END ====
return output;
@@ -270,6 +272,7 @@ SubShader {
UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input;
half4 c = uieffect(input.texcoord0.xy, input.uvMask, input.worldPosition);
c *= input.alpha;
// Alternative implementation to UnityGet2DClipping with support for softness.
#if UNITY_UI_CLIP_RECT
@@ -338,7 +338,7 @@ SubShader {
faceColor.rgb += glowColor.rgb * glowColor.a;
#endif
return faceColor * input.color.a;
return faceColor;
}
#define UIEFFECT_TEXTMESHPRO 1
@@ -350,6 +350,7 @@ SubShader {
UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input;
half4 faceColor = uieffect(input.atlas, input.uvMask, input.worldPosition);
faceColor *= input.color.a;
#if UNITY_UI_CLIP_RECT
half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(input.mask.xy)) * input.mask.zw);
+3 -1
View File
@@ -154,7 +154,7 @@ Shader "Hidden/UI/Default (UIEffect)"
fixed4 uieffect_frag(float2 uv)
{
v2f IN = _fragInput;
half4 color = IN.color * (tex2D(_MainTex, uv) + _TextureSampleAdd);
half4 color = (tex2D(_MainTex, uv) + _TextureSampleAdd);
color.rgb *= color.a;
return color;
}
@@ -173,6 +173,8 @@ Shader "Hidden/UI/Default (UIEffect)"
_fragInput = IN;
half4 c = uieffect(IN.texcoord, IN.uvMask, IN.worldPosition);
c.rgb *= IN.color.rgb;
c *= IN.color.a;
#ifdef UNITY_UI_CLIP_RECT
half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(IN.mask.xy)) * IN.mask.zw);