[unity] Fixed Spine/Sprite core shaders now correctly drawing Additive Slots. Closes #1853.

This commit is contained in:
Harald Csaszar 2021-03-04 17:02:18 +01:00
parent c5c71747c3
commit 47e357aa88
5 changed files with 74 additions and 69 deletions

View File

@ -109,16 +109,11 @@ sampler2D _MainTex;
fixed4 frag (VertexOutput i) : SV_Target {
fixed4 tex = tex2D(_MainTex, i.uv0);
ALPHA_CLIP(tex, i.color);
fixed4 col;
#if defined(_STRAIGHT_ALPHA_INPUT)
col.rgb = tex * i.color * tex.a;
#else
col.rgb = tex * i.color;
tex.rgb *= tex.a;
#endif
col *= 2;
col.a = tex.a * i.color.a;
fixed4 col = tex * i.color;
col.rgb *= 2;
return col;
}

View File

@ -240,6 +240,20 @@ uniform fixed _Cutoff;
#endif
////////////////////////////////////////
// Additive Slot blend mode
// return unlit textureColor, alpha clip textureColor.a only
//
#if defined(_ALPHAPREMULTIPLY_ON)
#define RETURN_UNLIT_IF_ADDITIVE_SLOT(textureColor, vertexColor) \
if (vertexColor.a == 0 && (vertexColor.r || vertexColor.g || vertexColor.b)) {\
ALPHA_CLIP(texureColor, fixed4(1, 1, 1, 1))\
return texureColor * vertexColor;\
}
#else
#define RETURN_UNLIT_IF_ADDITIVE_SLOT(textureColor, vertexColor)
#endif
////////////////////////////////////////
// Color functions
//

View File

@ -163,10 +163,10 @@ VertexOutput vert(VertexInput v)
////////////////////////////////////////
// Fragment programs
//
fixed4 fragBase(VertexOutput input) : SV_Target
{
fixed4 texureColor = calculateTexturePixel(input.texcoord);
RETURN_UNLIT_IF_ADDITIVE_SLOT(texureColor, input.color) // shall be called before ALPHA_CLIP
ALPHA_CLIP(texureColor, input.color)
//Get normal direction

View File

@ -52,15 +52,11 @@ VertexOutput vert(VertexInput input)
////////////////////////////////////////
// Fragment program
//
fixed4 frag(VertexOutput input) : SV_Target
{
fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
RETURN_UNLIT_IF_ADDITIVE_SLOT(texureColor, input.color) // shall be called before ALPHA_CLIP
ALPHA_CLIP(texureColor, input.color)
fixed4 pixel = calculatePixel(texureColor, input.color);
COLORISE(pixel)

View File

@ -399,10 +399,10 @@ VertexOutput vert(VertexInput input)
////////////////////////////////////////
// Fragment program
//
fixed4 frag(VertexOutput input) : SV_Target
{
fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
RETURN_UNLIT_IF_ADDITIVE_SLOT(texureColor, input.color) // shall be called before ALPHA_CLIP
ALPHA_CLIP(texureColor, input.color)
#if defined(PER_PIXEL_LIGHTING)