diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Spine-Skeleton-Fill.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Spine-Skeleton-Fill.shader index 262b90e5e..161b03b59 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Spine-Skeleton-Fill.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Spine-Skeleton-Fill.shader @@ -1,12 +1,13 @@ // - Unlit + no shadow -// - Premultiplied Alpha Blending (One OneMinusSrcAlpha) +// - Premultiplied Alpha Blending (Optional straight alpha input) // - Double-sided, no depth Shader "Spine/Skeleton Fill" { Properties { _FillColor ("FillColor", Color) = (1,1,1,1) _FillPhase ("FillPhase", Range(0, 1)) = 0 - [NoScaleOffset]_MainTex ("MainTex", 2D) = "white" {} + [NoScaleOffset] _MainTex ("MainTex", 2D) = "white" {} + [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 } SubShader { Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" } @@ -17,6 +18,7 @@ Shader "Spine/Skeleton Fill" { Pass { CGPROGRAM + #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" @@ -40,13 +42,18 @@ Shader "Spine/Skeleton Fill" { VertexOutput o = (VertexOutput)0; o.uv = v.uv; o.vertexColor = v.vertexColor; - o.pos = UnityObjectToClipPos(v.vertex); // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' + o.pos = UnityObjectToClipPos(v.vertex); return o; } float4 frag (VertexOutput i) : COLOR { float4 rawColor = tex2D(_MainTex,i.uv); float finalAlpha = (rawColor.a * i.vertexColor.a); + + #if defined(_STRAIGHT_ALPHA_INPUT) + rawColor.rgb *= rawColor.a; + #endif + float3 finalColor = lerp((rawColor.rgb * i.vertexColor.rgb), (_FillColor.rgb * finalAlpha), _FillPhase); // make sure to PMA _FillColor. return fixed4(finalColor, finalAlpha); } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Spine-Skeleton-Tint.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Spine-Skeleton-Tint.shader index 79bacb5cd..0cba285cb 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Spine-Skeleton-Tint.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Spine-Skeleton-Tint.shader @@ -1,7 +1,7 @@ // Spine/Skeleton Tint // - Two color tint // - unlit -// - Premultiplied alpha blending +// - Premultiplied alpha blending (Optional straight alpha input) // - No depth, no backface culling, no fog. Shader "Spine/Skeleton Tint" { @@ -9,6 +9,7 @@ Shader "Spine/Skeleton Tint" { _Color ("Tint Color", Color) = (1,1,1,1) _Black ("Black Point", Color) = (0,0,0,0) [NoScaleOffset] _MainTex ("MainTex", 2D) = "black" {} + [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 } @@ -23,6 +24,7 @@ Shader "Spine/Skeleton Tint" { Pass { CGPROGRAM + #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" @@ -44,7 +46,7 @@ Shader "Spine/Skeleton Tint" { VertexOutput vert (VertexInput v) { VertexOutput o; - o.pos = UnityObjectToClipPos(v.vertex); // replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' + o.pos = UnityObjectToClipPos(v.vertex); o.uv = v.uv; o.vertexColor = v.vertexColor * float4(_Color.rgb * _Color.a, _Color.a); // Combine a PMA version of _Color with vertexColor. return o; @@ -52,6 +54,11 @@ Shader "Spine/Skeleton Tint" { float4 frag (VertexOutput i) : COLOR { float4 texColor = tex2D(_MainTex, i.uv); + + #if defined(_STRAIGHT_ALPHA_INPUT) + texColor.rgb *= texColor.a; + #endif + return (texColor * i.vertexColor) + float4(((1-texColor.rgb) * _Black.rgb * texColor.a*_Color.a*i.vertexColor.a), 0); } ENDCG diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Straight Alpha.meta b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Straight Alpha.meta deleted file mode 100644 index e423168d0..000000000 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Straight Alpha.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: d6f7e10049c6d6348ae5c92ccb3825e0 -folderAsset: yes -timeCreated: 1521392482 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Straight Alpha/Spine-Straight-Skeleton-Fill.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Straight Alpha/Spine-Straight-Skeleton-Fill.shader deleted file mode 100644 index a4c0eba5a..000000000 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Straight Alpha/Spine-Straight-Skeleton-Fill.shader +++ /dev/null @@ -1,56 +0,0 @@ -// - Unlit + no shadow -// - Double-sided, no depth - -Shader "Spine/Straight Alpha/Skeleton Fill" { - Properties { - _FillColor ("FillColor", Color) = (1,1,1,1) - _FillPhase ("FillPhase", Range(0, 1)) = 0 - [NoScaleOffset]_MainTex ("MainTex", 2D) = "white" {} - } - SubShader { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" } - Blend One OneMinusSrcAlpha - Cull Off - ZWrite Off - Lighting Off - - Pass { - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #include "UnityCG.cginc" - sampler2D _MainTex; - float4 _FillColor; - float _FillPhase; - - struct VertexInput { - float4 vertex : POSITION; - float2 uv : TEXCOORD0; - float4 vertexColor : COLOR; - }; - - struct VertexOutput { - float4 pos : SV_POSITION; - float2 uv : TEXCOORD0; - float4 vertexColor : COLOR; - }; - - VertexOutput vert (VertexInput v) { - VertexOutput o = (VertexOutput)0; - o.uv = v.uv; - o.vertexColor = v.vertexColor; - o.pos = UnityObjectToClipPos(v.vertex); - return o; - } - - float4 frag (VertexOutput i) : COLOR { - float4 rawColor = tex2D(_MainTex,i.uv); - float finalAlpha = (rawColor.a * i.vertexColor.a); - float3 finalColor = lerp((rawColor.rgb * i.vertexColor.rgb * rawColor.a), (_FillColor.rgb * finalAlpha), _FillPhase); - return fixed4(finalColor, finalAlpha); - } - ENDCG - } - } - FallBack "Diffuse" -} \ No newline at end of file diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Straight Alpha/Spine-Straight-Skeleton-Fill.shader.meta b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Straight Alpha/Spine-Straight-Skeleton-Fill.shader.meta deleted file mode 100644 index 38c4a7cd7..000000000 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Straight Alpha/Spine-Straight-Skeleton-Fill.shader.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: ec3c686f972ccf5459c2b55555e6635f -timeCreated: 1492385797 -licenseType: Free -ShaderImporter: - defaultTextures: [] - userData: - assetBundleName: - assetBundleVariant: diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Straight Alpha/Spine-Straight-Skeleton-Tint.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Straight Alpha/Spine-Straight-Skeleton-Tint.shader deleted file mode 100644 index 85d89cf89..000000000 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Straight Alpha/Spine-Straight-Skeleton-Tint.shader +++ /dev/null @@ -1,99 +0,0 @@ -// - Two color tint -// - unlit -// - No depth, no backface culling, no fog. - -Shader "Spine/Straight Alpha/Skeleton Tint" { - Properties { - _Color ("Tint Color", Color) = (1,1,1,1) - _Black ("Black Point", Color) = (0,0,0,0) - [NoScaleOffset] _MainTex ("MainTex", 2D) = "black" {} - _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 - } - - SubShader { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" } - - Fog { Mode Off } - Cull Off - ZWrite Off - Blend One OneMinusSrcAlpha - Lighting Off - - Pass { - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #include "UnityCG.cginc" - sampler2D _MainTex; - float4 _Color; - float4 _Black; - - struct VertexInput { - float4 vertex : POSITION; - float2 uv : TEXCOORD0; - float4 vertexColor : COLOR; - }; - - struct VertexOutput { - float4 pos : SV_POSITION; - float2 uv : TEXCOORD0; - float4 vertexColor : COLOR; - }; - - VertexOutput vert (VertexInput v) { - VertexOutput o; - o.pos = UnityObjectToClipPos(v.vertex); // replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' - o.uv = v.uv; - o.vertexColor = v.vertexColor * float4(_Color.rgb * _Color.a, _Color.a); // Combine a PMA version of _Color with vertexColor. - return o; - } - - float4 frag (VertexOutput i) : COLOR { - float4 texColor = tex2D(_MainTex, i.uv); - texColor = float4(texColor.rgb * texColor.a, texColor.a); - return (texColor * i.vertexColor) + float4(((1-texColor.rgb) * _Black.rgb * texColor.a*_Color.a*i.vertexColor.a), 0); - } - ENDCG - } - - Pass { - Name "Caster" - Tags { "LightMode"="ShadowCaster" } - Offset 1, 1 - ZWrite On - ZTest LEqual - - Fog { Mode Off } - Cull Off - Lighting Off - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile_shadowcaster - #pragma fragmentoption ARB_precision_hint_fastest - #include "UnityCG.cginc" - sampler2D _MainTex; - fixed _Cutoff; - - struct VertexOutput { - V2F_SHADOW_CASTER; - float2 uv : TEXCOORD1; - }; - - VertexOutput vert (appdata_base v) { - VertexOutput o; - o.uv = v.texcoord; - TRANSFER_SHADOW_CASTER(o) - return o; - } - - float4 frag (VertexOutput i) : COLOR { - fixed4 texcol = tex2D(_MainTex, i.uv); - clip(texcol.a - _Cutoff); - SHADOW_CASTER_FRAGMENT(i) - } - ENDCG - } - } -} diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Straight Alpha/Spine-Straight-Skeleton-Tint.shader.meta b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Straight Alpha/Spine-Straight-Skeleton-Tint.shader.meta deleted file mode 100644 index e2b0cbebd..000000000 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Shaders/Straight Alpha/Spine-Straight-Skeleton-Tint.shader.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: c9a84b3418d033a4f9749511a6ac36d6 -ShaderImporter: - defaultTextures: [] - userData: - assetBundleName: - assetBundleVariant: diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SkeletonGraphic/Shaders/Spine-SkeletonGraphic-TintBlack.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SkeletonGraphic/Shaders/Spine-SkeletonGraphic-TintBlack.shader index eb023544f..14d0eda28 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SkeletonGraphic/Shaders/Spine-SkeletonGraphic-TintBlack.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SkeletonGraphic/Shaders/Spine-SkeletonGraphic-TintBlack.shader @@ -1,10 +1,12 @@ // This is a premultiply-alpha adaptation of the built-in Unity shader "UI/Default" to allow Unity UI stencil masking. -Shader "Spine/SkeletonGraphic Tint Black (Premultiply Alpha)" +Shader "Spine/SkeletonGraphic Tint Black" { Properties { [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} + [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 + _Color ("Tint", Color) = (1,1,1,1) _Black ("Black Point", Color) = (0,0,0,0) @@ -50,6 +52,7 @@ Shader "Spine/SkeletonGraphic Tint Black (Premultiply Alpha)" Pass { CGPROGRAM + #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT #pragma vertex vert #pragma fragment frag @@ -104,6 +107,10 @@ Shader "Spine/SkeletonGraphic Tint Black (Premultiply Alpha)" { half4 texColor = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd); + #if defined(_STRAIGHT_ALPHA_INPUT) + texColor.rgb *= texColor.a; + #endif + texColor.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect); #ifdef UNITY_UI_ALPHACLIP diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SkeletonGraphic/Shaders/Spine-SkeletonGraphic.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SkeletonGraphic/Shaders/Spine-SkeletonGraphic.shader index fa25e7ba6..87ede06cd 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SkeletonGraphic/Shaders/Spine-SkeletonGraphic.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SkeletonGraphic/Shaders/Spine-SkeletonGraphic.shader @@ -1,10 +1,11 @@ // This is a premultiply-alpha adaptation of the built-in Unity shader "UI/Default" in Unity 5.6.2 to allow Unity UI stencil masking. -Shader "Spine/SkeletonGraphic (Premultiply Alpha)" +Shader "Spine/SkeletonGraphic" { Properties { [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} + [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 _Color ("Tint", Color) = (1,1,1,1) _StencilComp ("Stencil Comparison", Float) = 8 @@ -49,6 +50,7 @@ Shader "Spine/SkeletonGraphic (Premultiply Alpha)" Pass { CGPROGRAM + #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT #pragma vertex vert #pragma fragment frag #pragma target 2.0 @@ -99,7 +101,13 @@ Shader "Spine/SkeletonGraphic (Premultiply Alpha)" fixed4 frag (VertexOutput IN) : SV_Target { - half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color; + half4 texColor = tex2D(_MainTex, IN.texcoord); + + #if defined(_STRAIGHT_ALPHA_INPUT) + texColor.rgb *= texColor.a; + #endif + + half4 color = (texColor + _TextureSampleAdd) * IN.color; color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect); diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SlotBlendModes/Spine-Skeleton-PMA-Multiply.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SlotBlendModes/Spine-Skeleton-PMA-Multiply.shader index 26126be06..1cfd859e7 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SlotBlendModes/Spine-Skeleton-PMA-Multiply.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SlotBlendModes/Spine-Skeleton-PMA-Multiply.shader @@ -11,6 +11,7 @@ Shader "Spine/Skeleton PMA Multiply" { Properties { _Color ("Tint Color", Color) = (1,1,1,1) [NoScaleOffset] _MainTex ("MainTex", 2D) = "black" {} + [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 } @@ -26,6 +27,7 @@ Shader "Spine/Skeleton PMA Multiply" { Pass { CGPROGRAM + #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" @@ -54,6 +56,11 @@ Shader "Spine/Skeleton PMA Multiply" { float4 frag (VertexOutput i) : COLOR { float4 texColor = tex2D(_MainTex, i.uv); + + #if defined(_STRAIGHT_ALPHA_INPUT) + texColor.rgb *= texColor.a; + #endif + return (texColor * i.vertexColor); } ENDCG diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SlotBlendModes/Spine-Skeleton-PMA-Screen.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SlotBlendModes/Spine-Skeleton-PMA-Screen.shader index d97397036..68a0f8e3a 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SlotBlendModes/Spine-Skeleton-PMA-Screen.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SlotBlendModes/Spine-Skeleton-PMA-Screen.shader @@ -9,6 +9,7 @@ Shader "Spine/Skeleton PMA Screen" { Properties { _Color ("Tint Color", Color) = (1,1,1,1) [NoScaleOffset] _MainTex ("MainTex", 2D) = "black" {} + [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 } @@ -24,6 +25,7 @@ Shader "Spine/Skeleton PMA Screen" { Pass { CGPROGRAM + #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" @@ -52,6 +54,11 @@ Shader "Spine/Skeleton PMA Screen" { float4 frag (VertexOutput i) : COLOR { float4 texColor = tex2D(_MainTex, i.uv); + + #if defined(_STRAIGHT_ALPHA_INPUT) + texColor.rgb *= texColor.a; + #endif + return (texColor * i.vertexColor); } ENDCG diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-TintBlack.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-TintBlack.shader index 7eeca1e75..1e5c040c7 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-TintBlack.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-TintBlack.shader @@ -3,7 +3,7 @@ // - UV2 and UV3 as Black Tint color. // - Final black tint is (UV black data and _Black/"Black Point") // - unlit -// - Premultiplied alpha blending +// - Premultiplied alpha blending (optional straight alpha input) // - No depth, no backface culling, no fog. Shader "Spine/Skeleton Tint Black" { @@ -11,6 +11,7 @@ Shader "Spine/Skeleton Tint Black" { _Color ("Tint Color", Color) = (1,1,1,1) _Black ("Black Point", Color) = (0,0,0,0) [NoScaleOffset] _MainTex ("MainTex", 2D) = "black" {} + [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 } @@ -26,6 +27,7 @@ Shader "Spine/Skeleton Tint Black" { Pass { CGPROGRAM + #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" @@ -61,6 +63,11 @@ Shader "Spine/Skeleton Tint Black" { float4 frag (VertexOutput i) : COLOR { float4 texColor = tex2D(_MainTex, i.uv); + + #if defined(_STRAIGHT_ALPHA_INPUT) + texColor.rgb *= texColor.a; + #endif + return (texColor * i.vertexColor) + float4(((1-texColor.rgb) * (_Black.rgb + float3(i.uv1.r, i.uv1.g, i.uv2.r)) * texColor.a*_Color.a*i.vertexColor.a), 0); } ENDCG diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton.shader index 7b5c00d90..661f279c3 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton.shader @@ -2,10 +2,11 @@ Shader "Spine/Skeleton" { Properties { _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} + [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 } SubShader { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane"} + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" } Fog { Mode Off } Cull Off @@ -14,11 +15,43 @@ Shader "Spine/Skeleton" { Lighting Off Pass { - Fog { Mode Off } - ColorMaterial AmbientAndDiffuse - SetTexture [_MainTex] { - Combine texture * primary + CGPROGRAM + #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT + #pragma vertex vert + #pragma fragment frag + #include "UnityCG.cginc" + sampler2D _MainTex; + + struct VertexInput { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + float4 vertexColor : COLOR; + }; + + struct VertexOutput { + float4 pos : SV_POSITION; + float2 uv : TEXCOORD0; + float4 vertexColor : COLOR; + }; + + VertexOutput vert (VertexInput v) { + VertexOutput o; + o.pos = UnityObjectToClipPos(v.vertex); + o.uv = v.uv; + o.vertexColor = v.vertexColor; + return o; } + + float4 frag (VertexOutput i) : COLOR { + float4 texColor = tex2D(_MainTex, i.uv); + + #if defined(_STRAIGHT_ALPHA_INPUT) + texColor.rgb *= texColor.a; + #endif + + return (texColor * i.vertexColor); + } + ENDCG } Pass { @@ -41,19 +74,19 @@ Shader "Spine/Skeleton" { sampler2D _MainTex; fixed _Cutoff; - struct v2f { + struct VertexOutput { V2F_SHADOW_CASTER; - float2 uv : TEXCOORD1; + float2 uv : TEXCOORD1; }; - v2f vert (appdata_base v) { - v2f o; - TRANSFER_SHADOW_CASTER(o) + VertexOutput vert (appdata_base v) { + VertexOutput o; o.uv = v.texcoord; + TRANSFER_SHADOW_CASTER(o) return o; } - float4 frag (v2f i) : COLOR { + float4 frag (VertexOutput i) : COLOR { fixed4 texcol = tex2D(_MainTex, i.uv); clip(texcol.a - _Cutoff); SHADOW_CASTER_FRAGMENT(i) @@ -61,20 +94,4 @@ Shader "Spine/Skeleton" { ENDCG } } - - SubShader { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - - Cull Off - ZWrite Off - Blend One OneMinusSrcAlpha - Lighting Off - - Pass { - ColorMaterial AmbientAndDiffuse - SetTexture [_MainTex] { - Combine texture * primary DOUBLE, texture * primary - } - } - } } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-SkeletonLit.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-SkeletonLit.shader index 8b193c295..a4f9b34d6 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-SkeletonLit.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-SkeletonLit.shader @@ -1,11 +1,12 @@ // - Vertex Lit + ShadowCaster -// - Premultiplied Alpha Blending (One OneMinusSrcAlpha) +// - Premultiplied Alpha Blending (Optional straight alpha input) // - Double-sided, no depth Shader "Spine/Skeleton Lit" { Properties { _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} + [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 } SubShader { @@ -38,6 +39,7 @@ Shader "Spine/Skeleton Lit" { Blend One OneMinusSrcAlpha CGPROGRAM + #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT #pragma vertex vert #pragma fragment frag #pragma target 2.0 @@ -135,7 +137,13 @@ Shader "Spine/Skeleton Lit" { fixed4 tex = tex2D(_MainTex, i.uv0); fixed4 col; + + #if defined(_STRAIGHT_ALPHA_INPUT) + col.rgb = tex * i.color * tex.a; + #else col.rgb = tex * i.color; + #endif + col *= 2; col.a = tex.a * i.color.a; return col;