Merge branch '3.7-beta' into 3.7-beta-cpp

This commit is contained in:
badlogic 2018-06-12 15:42:39 +02:00
commit d8dfa62016
15 changed files with 126 additions and 217 deletions

View File

@ -98,6 +98,20 @@
* **SpineAtlasAsset** The existing `AtlasAsset` type has been renamed to `SpineAtlasAsset` to signify that it specifically uses a Spine/libGDX atlas as its source. Serialization should be intact but user code will need to be updated to refer to existing atlases as `SpineAtlasAsset`. * **SpineAtlasAsset** The existing `AtlasAsset` type has been renamed to `SpineAtlasAsset` to signify that it specifically uses a Spine/libGDX atlas as its source. Serialization should be intact but user code will need to be updated to refer to existing atlases as `SpineAtlasAsset`.
* **AtlasAssetBase** `SpineAtlasAsset` now has an abstract base class called `SpineAtlasAsset`. This is the base class to derive when using alternate atlas sources. Existing SkeletonDataAsset field "atlasAssets" now have the "AtlasAssetBase" type. Serialization should be intact, but user code will need to be updated to refer to the atlas assets accordingly. * **AtlasAssetBase** `SpineAtlasAsset` now has an abstract base class called `SpineAtlasAsset`. This is the base class to derive when using alternate atlas sources. Existing SkeletonDataAsset field "atlasAssets" now have the "AtlasAssetBase" type. Serialization should be intact, but user code will need to be updated to refer to the atlas assets accordingly.
* This change is in preparation for alternate atlas options such as Unity's SpriteAtlas. * This change is in preparation for alternate atlas options such as Unity's SpriteAtlas.
* **Optional Straight Alpha for shaders** Spine-Unity's included Unity shaders now have a `_STRAIGHT_ALPHA_INPUT` shader_feature, toggled as a checkbox in the Material's inspector. This allows the Material to use a non-premultiplied alpha/straight alpha input texture.
* The following shaders now have the "Straight Alpha Texture" checkbox when used on a material:
* `Spine/Skeleton`
* `Spine/Skeleton Tint Black`
* `Spine/Skeleton Lit`
* `Spine/Skeleton Tint`
* `Spine/Skeleton Fill`
* `Spine/SkeletonGraphic (Premultiply Alpha)` was renamed to `Spine/SkeletonGraphic`
* `Spine/SkeletonGraphic Tint Black (Premultiply Alpha)` was renamed to `Spine/SkeletonGraphic Tint Black`
* `Spine/Skeleton PMA Multiply`
* `Spine/Skeleton PMA Screen`
* Dedicated straight alpha shaders were removed from the runtime.
* `Spine/Straight Alpha/Skeleton Fill`
* `Spine/Straight Alpha/Skeleton Tint`
### XNA/MonoGame ### XNA/MonoGame
* Added support for any `Effect` to be used by `SkeletonRenderer` * Added support for any `Effect` to be used by `SkeletonRenderer`

View File

@ -1,12 +1,13 @@
// - Unlit + no shadow // - Unlit + no shadow
// - Premultiplied Alpha Blending (One OneMinusSrcAlpha) // - Premultiplied Alpha Blending (Optional straight alpha input)
// - Double-sided, no depth // - Double-sided, no depth
Shader "Spine/Skeleton Fill" { Shader "Spine/Skeleton Fill" {
Properties { Properties {
_FillColor ("FillColor", Color) = (1,1,1,1) _FillColor ("FillColor", Color) = (1,1,1,1)
_FillPhase ("FillPhase", Range(0, 1)) = 0 _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 { SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" } Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
@ -17,6 +18,7 @@ Shader "Spine/Skeleton Fill" {
Pass { Pass {
CGPROGRAM CGPROGRAM
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
#pragma vertex vert #pragma vertex vert
#pragma fragment frag #pragma fragment frag
#include "UnityCG.cginc" #include "UnityCG.cginc"
@ -40,13 +42,18 @@ Shader "Spine/Skeleton Fill" {
VertexOutput o = (VertexOutput)0; VertexOutput o = (VertexOutput)0;
o.uv = v.uv; o.uv = v.uv;
o.vertexColor = v.vertexColor; 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; return o;
} }
float4 frag (VertexOutput i) : COLOR { float4 frag (VertexOutput i) : COLOR {
float4 rawColor = tex2D(_MainTex,i.uv); float4 rawColor = tex2D(_MainTex,i.uv);
float finalAlpha = (rawColor.a * i.vertexColor.a); 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. float3 finalColor = lerp((rawColor.rgb * i.vertexColor.rgb), (_FillColor.rgb * finalAlpha), _FillPhase); // make sure to PMA _FillColor.
return fixed4(finalColor, finalAlpha); return fixed4(finalColor, finalAlpha);
} }

View File

@ -1,7 +1,7 @@
// Spine/Skeleton Tint // Spine/Skeleton Tint
// - Two color tint // - Two color tint
// - unlit // - unlit
// - Premultiplied alpha blending // - Premultiplied alpha blending (Optional straight alpha input)
// - No depth, no backface culling, no fog. // - No depth, no backface culling, no fog.
Shader "Spine/Skeleton Tint" { Shader "Spine/Skeleton Tint" {
@ -9,6 +9,7 @@ Shader "Spine/Skeleton Tint" {
_Color ("Tint Color", Color) = (1,1,1,1) _Color ("Tint Color", Color) = (1,1,1,1)
_Black ("Black Point", Color) = (0,0,0,0) _Black ("Black Point", Color) = (0,0,0,0)
[NoScaleOffset] _MainTex ("MainTex", 2D) = "black" {} [NoScaleOffset] _MainTex ("MainTex", 2D) = "black" {}
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
} }
@ -23,6 +24,7 @@ Shader "Spine/Skeleton Tint" {
Pass { Pass {
CGPROGRAM CGPROGRAM
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
#pragma vertex vert #pragma vertex vert
#pragma fragment frag #pragma fragment frag
#include "UnityCG.cginc" #include "UnityCG.cginc"
@ -44,7 +46,7 @@ Shader "Spine/Skeleton Tint" {
VertexOutput vert (VertexInput v) { VertexOutput vert (VertexInput v) {
VertexOutput o; VertexOutput o;
o.pos = UnityObjectToClipPos(v.vertex); // replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.uv; o.uv = v.uv;
o.vertexColor = v.vertexColor * float4(_Color.rgb * _Color.a, _Color.a); // Combine a PMA version of _Color with vertexColor. o.vertexColor = v.vertexColor * float4(_Color.rgb * _Color.a, _Color.a); // Combine a PMA version of _Color with vertexColor.
return o; return o;
@ -52,6 +54,11 @@ Shader "Spine/Skeleton Tint" {
float4 frag (VertexOutput i) : COLOR { float4 frag (VertexOutput i) : COLOR {
float4 texColor = tex2D(_MainTex, i.uv); 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); return (texColor * i.vertexColor) + float4(((1-texColor.rgb) * _Black.rgb * texColor.a*_Color.a*i.vertexColor.a), 0);
} }
ENDCG ENDCG

View File

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: d6f7e10049c6d6348ae5c92ccb3825e0
folderAsset: yes
timeCreated: 1521392482
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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"
}

View File

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: ec3c686f972ccf5459c2b55555e6635f
timeCreated: 1492385797
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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
}
}
}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: c9a84b3418d033a4f9749511a6ac36d6
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,10 +1,12 @@
// This is a premultiply-alpha adaptation of the built-in Unity shader "UI/Default" to allow Unity UI stencil masking. // 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 Properties
{ {
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
_Color ("Tint", Color) = (1,1,1,1) _Color ("Tint", Color) = (1,1,1,1)
_Black ("Black Point", Color) = (0,0,0,0) _Black ("Black Point", Color) = (0,0,0,0)
@ -50,6 +52,7 @@ Shader "Spine/SkeletonGraphic Tint Black (Premultiply Alpha)"
Pass Pass
{ {
CGPROGRAM CGPROGRAM
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
#pragma vertex vert #pragma vertex vert
#pragma fragment frag #pragma fragment frag
@ -104,6 +107,10 @@ Shader "Spine/SkeletonGraphic Tint Black (Premultiply Alpha)"
{ {
half4 texColor = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd); half4 texColor = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd);
#if defined(_STRAIGHT_ALPHA_INPUT)
texColor.rgb *= texColor.a;
#endif
texColor.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect); texColor.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
#ifdef UNITY_UI_ALPHACLIP #ifdef UNITY_UI_ALPHACLIP

View File

@ -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. // 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 Properties
{ {
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
_Color ("Tint", Color) = (1,1,1,1) _Color ("Tint", Color) = (1,1,1,1)
_StencilComp ("Stencil Comparison", Float) = 8 _StencilComp ("Stencil Comparison", Float) = 8
@ -49,6 +50,7 @@ Shader "Spine/SkeletonGraphic (Premultiply Alpha)"
Pass Pass
{ {
CGPROGRAM CGPROGRAM
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
#pragma vertex vert #pragma vertex vert
#pragma fragment frag #pragma fragment frag
#pragma target 2.0 #pragma target 2.0
@ -99,7 +101,13 @@ Shader "Spine/SkeletonGraphic (Premultiply Alpha)"
fixed4 frag (VertexOutput IN) : SV_Target 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); color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);

View File

@ -11,6 +11,7 @@ Shader "Spine/Skeleton PMA Multiply" {
Properties { Properties {
_Color ("Tint Color", Color) = (1,1,1,1) _Color ("Tint Color", Color) = (1,1,1,1)
[NoScaleOffset] _MainTex ("MainTex", 2D) = "black" {} [NoScaleOffset] _MainTex ("MainTex", 2D) = "black" {}
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
} }
@ -26,6 +27,7 @@ Shader "Spine/Skeleton PMA Multiply" {
Pass { Pass {
CGPROGRAM CGPROGRAM
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
#pragma vertex vert #pragma vertex vert
#pragma fragment frag #pragma fragment frag
#include "UnityCG.cginc" #include "UnityCG.cginc"
@ -54,6 +56,11 @@ Shader "Spine/Skeleton PMA Multiply" {
float4 frag (VertexOutput i) : COLOR { float4 frag (VertexOutput i) : COLOR {
float4 texColor = tex2D(_MainTex, i.uv); float4 texColor = tex2D(_MainTex, i.uv);
#if defined(_STRAIGHT_ALPHA_INPUT)
texColor.rgb *= texColor.a;
#endif
return (texColor * i.vertexColor); return (texColor * i.vertexColor);
} }
ENDCG ENDCG

View File

@ -9,6 +9,7 @@ Shader "Spine/Skeleton PMA Screen" {
Properties { Properties {
_Color ("Tint Color", Color) = (1,1,1,1) _Color ("Tint Color", Color) = (1,1,1,1)
[NoScaleOffset] _MainTex ("MainTex", 2D) = "black" {} [NoScaleOffset] _MainTex ("MainTex", 2D) = "black" {}
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
} }
@ -24,6 +25,7 @@ Shader "Spine/Skeleton PMA Screen" {
Pass { Pass {
CGPROGRAM CGPROGRAM
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
#pragma vertex vert #pragma vertex vert
#pragma fragment frag #pragma fragment frag
#include "UnityCG.cginc" #include "UnityCG.cginc"
@ -52,6 +54,11 @@ Shader "Spine/Skeleton PMA Screen" {
float4 frag (VertexOutput i) : COLOR { float4 frag (VertexOutput i) : COLOR {
float4 texColor = tex2D(_MainTex, i.uv); float4 texColor = tex2D(_MainTex, i.uv);
#if defined(_STRAIGHT_ALPHA_INPUT)
texColor.rgb *= texColor.a;
#endif
return (texColor * i.vertexColor); return (texColor * i.vertexColor);
} }
ENDCG ENDCG

View File

@ -3,7 +3,7 @@
// - UV2 and UV3 as Black Tint color. // - UV2 and UV3 as Black Tint color.
// - Final black tint is (UV black data and _Black/"Black Point") // - Final black tint is (UV black data and _Black/"Black Point")
// - unlit // - unlit
// - Premultiplied alpha blending // - Premultiplied alpha blending (optional straight alpha input)
// - No depth, no backface culling, no fog. // - No depth, no backface culling, no fog.
Shader "Spine/Skeleton Tint Black" { Shader "Spine/Skeleton Tint Black" {
@ -11,6 +11,7 @@ Shader "Spine/Skeleton Tint Black" {
_Color ("Tint Color", Color) = (1,1,1,1) _Color ("Tint Color", Color) = (1,1,1,1)
_Black ("Black Point", Color) = (0,0,0,0) _Black ("Black Point", Color) = (0,0,0,0)
[NoScaleOffset] _MainTex ("MainTex", 2D) = "black" {} [NoScaleOffset] _MainTex ("MainTex", 2D) = "black" {}
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
} }
@ -26,6 +27,7 @@ Shader "Spine/Skeleton Tint Black" {
Pass { Pass {
CGPROGRAM CGPROGRAM
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
#pragma vertex vert #pragma vertex vert
#pragma fragment frag #pragma fragment frag
#include "UnityCG.cginc" #include "UnityCG.cginc"
@ -61,6 +63,11 @@ Shader "Spine/Skeleton Tint Black" {
float4 frag (VertexOutput i) : COLOR { float4 frag (VertexOutput i) : COLOR {
float4 texColor = tex2D(_MainTex, i.uv); 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); 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 ENDCG

View File

@ -2,10 +2,11 @@ Shader "Spine/Skeleton" {
Properties { Properties {
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
[NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
} }
SubShader { SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane"} Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
Fog { Mode Off } Fog { Mode Off }
Cull Off Cull Off
@ -14,11 +15,43 @@ Shader "Spine/Skeleton" {
Lighting Off Lighting Off
Pass { Pass {
Fog { Mode Off } CGPROGRAM
ColorMaterial AmbientAndDiffuse #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
SetTexture [_MainTex] { #pragma vertex vert
Combine texture * primary #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 { Pass {
@ -41,19 +74,19 @@ Shader "Spine/Skeleton" {
sampler2D _MainTex; sampler2D _MainTex;
fixed _Cutoff; fixed _Cutoff;
struct v2f { struct VertexOutput {
V2F_SHADOW_CASTER; V2F_SHADOW_CASTER;
float2 uv : TEXCOORD1; float2 uv : TEXCOORD1;
}; };
v2f vert (appdata_base v) { VertexOutput vert (appdata_base v) {
v2f o; VertexOutput o;
TRANSFER_SHADOW_CASTER(o)
o.uv = v.texcoord; o.uv = v.texcoord;
TRANSFER_SHADOW_CASTER(o)
return o; return o;
} }
float4 frag (v2f i) : COLOR { float4 frag (VertexOutput i) : COLOR {
fixed4 texcol = tex2D(_MainTex, i.uv); fixed4 texcol = tex2D(_MainTex, i.uv);
clip(texcol.a - _Cutoff); clip(texcol.a - _Cutoff);
SHADOW_CASTER_FRAGMENT(i) SHADOW_CASTER_FRAGMENT(i)
@ -61,20 +94,4 @@ Shader "Spine/Skeleton" {
ENDCG 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
}
}
}
} }

View File

@ -1,11 +1,12 @@
// - Vertex Lit + ShadowCaster // - Vertex Lit + ShadowCaster
// - Premultiplied Alpha Blending (One OneMinusSrcAlpha) // - Premultiplied Alpha Blending (Optional straight alpha input)
// - Double-sided, no depth // - Double-sided, no depth
Shader "Spine/Skeleton Lit" { Shader "Spine/Skeleton Lit" {
Properties { Properties {
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
[NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
} }
SubShader { SubShader {
@ -38,6 +39,7 @@ Shader "Spine/Skeleton Lit" {
Blend One OneMinusSrcAlpha Blend One OneMinusSrcAlpha
CGPROGRAM CGPROGRAM
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
#pragma vertex vert #pragma vertex vert
#pragma fragment frag #pragma fragment frag
#pragma target 2.0 #pragma target 2.0
@ -135,7 +137,13 @@ Shader "Spine/Skeleton Lit" {
fixed4 tex = tex2D(_MainTex, i.uv0); fixed4 tex = tex2D(_MainTex, i.uv0);
fixed4 col; fixed4 col;
#if defined(_STRAIGHT_ALPHA_INPUT)
col.rgb = tex * i.color * tex.a;
#else
col.rgb = tex * i.color; col.rgb = tex * i.color;
#endif
col *= 2; col *= 2;
col.a = tex.a * i.color.a; col.a = tex.a * i.color.a;
return col; return col;