mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
[unity] Fixed all Tint and TintBlack shader blend behaviour, previous changes by commit d43b7b0 were incorrect in some cases. Closes #1756.
This commit is contained in:
parent
106250a6c5
commit
5c1faa85af
@ -1,21 +1,21 @@
|
||||
#ifndef SKELETON_TINT_COMMON_INCLUDED
|
||||
#define SKELETON_TINT_COMMON_INCLUDED
|
||||
|
||||
float4 fragTintedColor(float4 texColor, float3 darkTintColor, float4 lightTintColor, float darkColorAlpha) {
|
||||
float4 fragTintedColor(float4 texColor, float3 darkTintColor, float4 lightTintColorPMA, float lightColorAlpha, float darkColorAlpha) {
|
||||
|
||||
float a = texColor.a * lightTintColor.a;
|
||||
float a = texColor.a * lightTintColorPMA.a;
|
||||
|
||||
#if !defined(_STRAIGHT_ALPHA_INPUT)
|
||||
float3 texDarkColor = (texColor.a - texColor.rgb);
|
||||
#else
|
||||
float3 texDarkColor = (1 - texColor.rgb);
|
||||
#endif
|
||||
float3 darkColor = texDarkColor * darkTintColor.rgb;
|
||||
float3 lightColor = texColor.rgb * lightTintColor.rgb;
|
||||
float3 darkColor = texDarkColor * darkTintColor.rgb * lightColorAlpha;
|
||||
float3 lightColor = texColor.rgb * lightTintColorPMA.rgb;
|
||||
|
||||
float4 fragColor = float4(darkColor + lightColor, a);
|
||||
#if defined(_STRAIGHT_ALPHA_INPUT)
|
||||
fragColor.rgb *= fragColor.a;
|
||||
fragColor.rgb *= texColor.a;
|
||||
#endif
|
||||
|
||||
#if defined(_DARK_COLOR_ALPHA_ADDITIVE)
|
||||
|
||||
@ -109,7 +109,7 @@ Shader "Spine/SkeletonGraphic Tint Black"
|
||||
OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
|
||||
OUT.texcoord = IN.texcoord;
|
||||
|
||||
OUT.color = IN.color * _Color;
|
||||
OUT.color = IN.color;
|
||||
OUT.darkColor = float4(IN.uv1.r, IN.uv1.g, IN.uv2.r, IN.uv2.g);
|
||||
return OUT;
|
||||
}
|
||||
@ -125,17 +125,19 @@ Shader "Spine/SkeletonGraphic Tint Black"
|
||||
clip(texColor.a - 0.001);
|
||||
#endif
|
||||
|
||||
float4 vertexColor = IN.color;
|
||||
float4 vertexColor = IN.color * float4(_Color.rgb * _Color.a, _Color.a);
|
||||
#ifdef _CANVAS_GROUP_COMPATIBLE
|
||||
// CanvasGroup alpha multiplies existing vertex color alpha, but
|
||||
// does not premultiply it to rgb components. This causes problems
|
||||
// with additive blending (alpha = 0), which is why we store the
|
||||
// alpha value in uv2.g (darkColor.a).
|
||||
vertexColor.a = IN.darkColor.a;
|
||||
float originalAlpha = IN.darkColor.a;
|
||||
float canvasAlpha = (originalAlpha == 0) ? IN.color.a : IN.color.a / originalAlpha;
|
||||
vertexColor.a = originalAlpha * _Color.a;
|
||||
#endif
|
||||
float4 fragColor = fragTintedColor(texColor, _Black.rgb + IN.darkColor, vertexColor, _Black.a);
|
||||
float4 fragColor = fragTintedColor(texColor, _Black.rgb + IN.darkColor, vertexColor, _Color.a, _Black.a);
|
||||
#ifdef _CANVAS_GROUP_COMPATIBLE
|
||||
fragColor.rgba *= IN.color.a;
|
||||
fragColor.rgba *= canvasAlpha;
|
||||
#endif
|
||||
return fragColor;
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ Shader "Spine/Skeleton Tint" {
|
||||
VertexOutput o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = v.uv;
|
||||
o.vertexColor = v.vertexColor * _Color;
|
||||
o.vertexColor = v.vertexColor * float4(_Color.rgb * _Color.a, _Color.a); // Combine a PMA version of _Color with vertexColor.
|
||||
return o;
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ Shader "Spine/Skeleton Tint" {
|
||||
|
||||
float4 frag (VertexOutput i) : SV_Target {
|
||||
float4 texColor = tex2D(_MainTex, i.uv);
|
||||
return fragTintedColor(texColor, _Black.rgb, i.vertexColor, _Black.a);
|
||||
return fragTintedColor(texColor, _Black.rgb, i.vertexColor, _Color.a, _Black.a);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ Shader "Spine/Skeleton Tint Black" {
|
||||
VertexOutput o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex); // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
o.uv = v.uv;
|
||||
o.vertexColor = v.vertexColor * _Color;
|
||||
o.vertexColor = v.vertexColor * float4(_Color.rgb * _Color.a, _Color.a); // Combine a PMA version of _Color with vertexColor.
|
||||
o.darkColor = float3(v.uv1.r, v.uv1.g, v.uv2.r);
|
||||
return o;
|
||||
}
|
||||
@ -84,7 +84,7 @@ Shader "Spine/Skeleton Tint Black" {
|
||||
|
||||
float4 frag (VertexOutput i) : SV_Target {
|
||||
float4 texColor = tex2D(_MainTex, i.uv);
|
||||
return fragTintedColor(texColor, _Black.rgb + i.darkColor, i.vertexColor, _Black.a);
|
||||
return fragTintedColor(texColor, _Black.rgb + i.darkColor, i.vertexColor, _Color.a, _Black.a);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user