This commit is contained in:
badlogic 2021-03-04 19:19:29 +01:00
commit 5ef75959b9
20 changed files with 150 additions and 130 deletions

View File

@ -50,6 +50,7 @@
* Removed redundant `Spine.SkeletonExtensions` extension methods `Skeleton.Set*ToSetupPose()`. Also removed less commonly used extension methods `TrackEntry.AllowImmediateQueue()` and `Attachment.IsRenderable()`. * Removed redundant `Spine.SkeletonExtensions` extension methods `Skeleton.Set*ToSetupPose()`. Also removed less commonly used extension methods `TrackEntry.AllowImmediateQueue()` and `Attachment.IsRenderable()`.
* `Skin.Attachments` now replaces `Skin.GetAttachments()`, returning an `ICollection<SkinEntry>`. This makes access more consistent and intuitive. To fix any compile errors, replace any occurrances of `skin.GetAttachments()` by `skin.Attachments`. * `Skin.Attachments` now replaces `Skin.GetAttachments()`, returning an `ICollection<SkinEntry>`. This makes access more consistent and intuitive. To fix any compile errors, replace any occurrances of `skin.GetAttachments()` by `skin.Attachments`.
* Reverted changes: `BoneFollower` property `followLocalScale` has intermediately been renamed to `followScale` but was renamed back to `followLocalScale`. Serialized values (scenes and prefabs) will automatically be upgraded, only code accessing `followScale` needs to be adapted. * Reverted changes: `BoneFollower` property `followLocalScale` has intermediately been renamed to `followScale` but was renamed back to `followLocalScale`. Serialized values (scenes and prefabs) will automatically be upgraded, only code accessing `followScale` needs to be adapted.
* Corrected blending behaviour of all `Sprite` shaders in `Premultiply Alpha` blend mode (including URP and LWRP packages). Previously vertex color alpha was premultiplied again, even though `Premultiply Alpha` blend mode assumes PMA texture and PMA vertex color input. Slot-alpha blending will thus be correctly lighter after upgrading to 4.0. If you have compensated this problem by disabling `Advanced - PMA Vertex Colors` you can now re-enable this parameter, also allowing for rendering Additive slots in a single pass.
* **Additions** * **Additions**
* Additional **Fix Draw Order** parameter at SkeletonRenderer, defaults to `disabled` (previous behaviour). * Additional **Fix Draw Order** parameter at SkeletonRenderer, defaults to `disabled` (previous behaviour).

View File

@ -134,14 +134,16 @@ namespace Spine.Unity {
#region Runtime Instantiation #region Runtime Instantiation
/// <summary>Adds and prepares a SkeletonAnimation component to a GameObject at runtime.</summary> /// <summary>Adds and prepares a SkeletonAnimation component to a GameObject at runtime.</summary>
/// <returns>The newly instantiated SkeletonAnimation</returns> /// <returns>The newly instantiated SkeletonAnimation</returns>
public static SkeletonAnimation AddToGameObject (GameObject gameObject, SkeletonDataAsset skeletonDataAsset) { public static SkeletonAnimation AddToGameObject (GameObject gameObject, SkeletonDataAsset skeletonDataAsset,
return SkeletonRenderer.AddSpineComponent<SkeletonAnimation>(gameObject, skeletonDataAsset); bool quiet = false) {
return SkeletonRenderer.AddSpineComponent<SkeletonAnimation>(gameObject, skeletonDataAsset, quiet);
} }
/// <summary>Instantiates a new UnityEngine.GameObject and adds a prepared SkeletonAnimation component to it.</summary> /// <summary>Instantiates a new UnityEngine.GameObject and adds a prepared SkeletonAnimation component to it.</summary>
/// <returns>The newly instantiated SkeletonAnimation component.</returns> /// <returns>The newly instantiated SkeletonAnimation component.</returns>
public static SkeletonAnimation NewSkeletonAnimationGameObject (SkeletonDataAsset skeletonDataAsset) { public static SkeletonAnimation NewSkeletonAnimationGameObject (SkeletonDataAsset skeletonDataAsset,
return SkeletonRenderer.NewSpineGameObject<SkeletonAnimation>(skeletonDataAsset); bool quiet = false) {
return SkeletonRenderer.NewSpineGameObject<SkeletonAnimation>(skeletonDataAsset, quiet);
} }
#endregion #endregion
@ -155,10 +157,10 @@ namespace Spine.Unity {
/// <summary> /// <summary>
/// Initialize this component. Attempts to load the SkeletonData and creates the internal Spine objects and buffers.</summary> /// Initialize this component. Attempts to load the SkeletonData and creates the internal Spine objects and buffers.</summary>
/// <param name="overwrite">If set to <c>true</c>, force overwrite an already initialized object.</param> /// <param name="overwrite">If set to <c>true</c>, force overwrite an already initialized object.</param>
public override void Initialize (bool overwrite) { public override void Initialize (bool overwrite, bool quiet = false) {
if (valid && !overwrite) if (valid && !overwrite)
return; return;
base.Initialize(overwrite); base.Initialize(overwrite, quiet);
if (!valid) if (!valid)
return; return;

View File

@ -69,11 +69,11 @@ namespace Spine.Unity {
public event UpdateBonesDelegate UpdateComplete { add { _UpdateComplete += value; } remove { _UpdateComplete -= value; } } public event UpdateBonesDelegate UpdateComplete { add { _UpdateComplete += value; } remove { _UpdateComplete -= value; } }
#endregion #endregion
public override void Initialize (bool overwrite) { public override void Initialize (bool overwrite, bool quiet = false) {
if (valid && !overwrite) if (valid && !overwrite)
return; return;
base.Initialize(overwrite); base.Initialize(overwrite, quiet);
if (!valid) if (!valid)
return; return;

View File

@ -247,17 +247,17 @@ namespace Spine.Unity {
public SkeletonDataAsset SkeletonDataAsset { get { return skeletonDataAsset; } } // ISkeletonComponent public SkeletonDataAsset SkeletonDataAsset { get { return skeletonDataAsset; } } // ISkeletonComponent
#region Runtime Instantiation #region Runtime Instantiation
public static T NewSpineGameObject<T> (SkeletonDataAsset skeletonDataAsset) where T : SkeletonRenderer { public static T NewSpineGameObject<T> (SkeletonDataAsset skeletonDataAsset, bool quiet = false) where T : SkeletonRenderer {
return SkeletonRenderer.AddSpineComponent<T>(new GameObject("New Spine GameObject"), skeletonDataAsset); return SkeletonRenderer.AddSpineComponent<T>(new GameObject("New Spine GameObject"), skeletonDataAsset, quiet);
} }
/// <summary>Add and prepare a Spine component that derives from SkeletonRenderer to a GameObject at runtime.</summary> /// <summary>Add and prepare a Spine component that derives from SkeletonRenderer to a GameObject at runtime.</summary>
/// <typeparam name="T">T should be SkeletonRenderer or any of its derived classes.</typeparam> /// <typeparam name="T">T should be SkeletonRenderer or any of its derived classes.</typeparam>
public static T AddSpineComponent<T> (GameObject gameObject, SkeletonDataAsset skeletonDataAsset) where T : SkeletonRenderer { public static T AddSpineComponent<T> (GameObject gameObject, SkeletonDataAsset skeletonDataAsset, bool quiet = false) where T : SkeletonRenderer {
var c = gameObject.AddComponent<T>(); var c = gameObject.AddComponent<T>();
if (skeletonDataAsset != null) { if (skeletonDataAsset != null) {
c.skeletonDataAsset = skeletonDataAsset; c.skeletonDataAsset = skeletonDataAsset;
c.Initialize(false); c.Initialize(false, quiet);
} }
return c; return c;
} }
@ -315,7 +315,7 @@ namespace Spine.Unity {
/// <summary> /// <summary>
/// Initialize this component. Attempts to load the SkeletonData and creates the internal Skeleton object and buffers.</summary> /// Initialize this component. Attempts to load the SkeletonData and creates the internal Skeleton object and buffers.</summary>
/// <param name="overwrite">If set to <c>true</c>, it will overwrite internal objects if they were already generated. Otherwise, the initialized component will ignore subsequent calls to initialize.</param> /// <param name="overwrite">If set to <c>true</c>, it will overwrite internal objects if they were already generated. Otherwise, the initialized component will ignore subsequent calls to initialize.</param>
public virtual void Initialize (bool overwrite) { public virtual void Initialize (bool overwrite, bool quiet = false) {
if (valid && !overwrite) if (valid && !overwrite)
return; return;
@ -361,7 +361,7 @@ namespace Spine.Unity {
#if UNITY_EDITOR #if UNITY_EDITOR
if (!Application.isPlaying) { if (!Application.isPlaying) {
string errorMessage = null; string errorMessage = null;
if (MaterialChecks.IsMaterialSetupProblematic(this, ref errorMessage)) if (quiet || MaterialChecks.IsMaterialSetupProblematic(this, ref errorMessage))
Debug.LogWarningFormat(this, "Problematic material setup at {0}: {1}", this.name, errorMessage); Debug.LogWarningFormat(this, "Problematic material setup at {0}: {1}", this.name, errorMessage);
} }
#endif #endif

View File

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

View File

@ -137,7 +137,7 @@ inline fixed4 prepareLitPixelForOutput(fixed4 finalPixel, fixed4 color) : SV_Tar
finalPixel.rgb *= finalPixel.a; finalPixel.rgb *= finalPixel.a;
#elif defined(_ALPHAPREMULTIPLY_ON) #elif defined(_ALPHAPREMULTIPLY_ON)
//Pre multiplied alpha //Pre multiplied alpha
finalPixel.rgb *= color.a; // texture and vertex colors are premultiplied already
#elif defined(_MULTIPLYBLEND) #elif defined(_MULTIPLYBLEND)
//Multiply //Multiply
finalPixel = lerp(fixed4(1,1,1,1), finalPixel, finalPixel.a); finalPixel = lerp(fixed4(1,1,1,1), finalPixel, finalPixel.a);
@ -240,6 +240,20 @@ uniform fixed _Cutoff;
#endif #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 // Color functions
// //

View File

@ -1,6 +1,6 @@
#ifndef SPRITE_PIXEL_LIGHTING_INCLUDED #ifndef SPRITE_PIXEL_LIGHTING_INCLUDED
#define SPRITE_PIXEL_LIGHTING_INCLUDED #define SPRITE_PIXEL_LIGHTING_INCLUDED
#include "ShaderShared.cginc" #include "ShaderShared.cginc"
#include "SpriteLighting.cginc" #include "SpriteLighting.cginc"
#include "SpriteSpecular.cginc" #include "SpriteSpecular.cginc"
@ -24,24 +24,24 @@
#define _LIGHT_COORD_INDEX_0 4 #define _LIGHT_COORD_INDEX_0 4
#define _LIGHT_COORD_INDEX_1 5 #define _LIGHT_COORD_INDEX_1 5
#define _FOG_COORD_INDEX 6 #define _FOG_COORD_INDEX 6
#endif // _NORMALMAP #endif // _NORMALMAP
struct VertexOutput struct VertexOutput
{ {
float4 pos : SV_POSITION; float4 pos : SV_POSITION;
fixed4 color : COLOR; fixed4 color : COLOR;
float2 texcoord : TEXCOORD0; float2 texcoord : TEXCOORD0;
float4 posWorld : TEXCOORD1; float4 posWorld : TEXCOORD1;
half3 normalWorld : TEXCOORD2; half3 normalWorld : TEXCOORD2;
#if defined(_NORMALMAP) #if defined(_NORMALMAP)
half3 tangentWorld : TEXCOORD3; half3 tangentWorld : TEXCOORD3;
half3 binormalWorld : TEXCOORD4; half3 binormalWorld : TEXCOORD4;
#endif // _NORMALMAP #endif // _NORMALMAP
fixed3 vertexLighting : _VERTEX_LIGHTING_INDEX; fixed3 vertexLighting : _VERTEX_LIGHTING_INDEX;
LIGHTING_COORDS(_LIGHT_COORD_INDEX_0, _LIGHT_COORD_INDEX_1) LIGHTING_COORDS(_LIGHT_COORD_INDEX_0, _LIGHT_COORD_INDEX_1)
#if defined(_FOG) #if defined(_FOG)
UNITY_FOG_COORDS(_FOG_COORD_INDEX) UNITY_FOG_COORDS(_FOG_COORD_INDEX)
#endif // _FOG #endif // _FOG
UNITY_VERTEX_OUTPUT_STEREO UNITY_VERTEX_OUTPUT_STEREO
}; };
@ -56,16 +56,16 @@ inline fixed3 calculateLightDiffuse(VertexOutput input, float3 normalWorld, inou
{ {
//For directional lights _WorldSpaceLightPos0.w is set to zero //For directional lights _WorldSpaceLightPos0.w is set to zero
float3 lightWorldDirection = normalize(_WorldSpaceLightPos0.xyz - input.posWorld.xyz * _WorldSpaceLightPos0.w); float3 lightWorldDirection = normalize(_WorldSpaceLightPos0.xyz - input.posWorld.xyz * _WorldSpaceLightPos0.w);
float attenuation = LIGHT_ATTENUATION(input); float attenuation = LIGHT_ATTENUATION(input);
float angleDot = max(0, dot(normalWorld, lightWorldDirection)); float angleDot = max(0, dot(normalWorld, lightWorldDirection));
#if defined(_DIFFUSE_RAMP) #if defined(_DIFFUSE_RAMP)
fixed3 lightDiffuse = calculateRampedDiffuse(_LightColor0.rgb, attenuation, angleDot); fixed3 lightDiffuse = calculateRampedDiffuse(_LightColor0.rgb, attenuation, angleDot);
#else #else
fixed3 lightDiffuse = _LightColor0.rgb * (attenuation * angleDot); fixed3 lightDiffuse = _LightColor0.rgb * (attenuation * angleDot);
#endif // _DIFFUSE_RAMP #endif // _DIFFUSE_RAMP
return lightDiffuse; return lightDiffuse;
} }
@ -96,7 +96,7 @@ fixed3 calculateAmbientLight(half3 normalWorld)
{ {
#if defined(_SPHERICAL_HARMONICS) #if defined(_SPHERICAL_HARMONICS)
fixed3 ambient = ShadeSH9(half4(normalWorld, 1.0)); fixed3 ambient = ShadeSH9(half4(normalWorld, 1.0));
#else #else
fixed3 ambient = unity_AmbientSky.rgb; fixed3 ambient = unity_AmbientSky.rgb;
#endif #endif
return ambient; return ambient;
@ -129,124 +129,124 @@ fixed4 calculateSpecularLightAdditive(SpecularCommonData s, float3 viewDir, floa
VertexOutput vert(VertexInput v) VertexOutput vert(VertexInput v)
{ {
VertexOutput output; VertexOutput output;
UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
output.pos = calculateLocalPos(v.vertex); output.pos = calculateLocalPos(v.vertex);
output.color = calculateVertexColor(v.color); output.color = calculateVertexColor(v.color);
output.texcoord = calculateTextureCoord(v.texcoord); output.texcoord = calculateTextureCoord(v.texcoord);
output.posWorld = calculateWorldPos(v.vertex); output.posWorld = calculateWorldPos(v.vertex);
float backFaceSign = 1; float backFaceSign = 1;
#if defined(FIXED_NORMALS_BACKFACE_RENDERING) #if defined(FIXED_NORMALS_BACKFACE_RENDERING)
backFaceSign = calculateBackfacingSign(output.posWorld.xyz); backFaceSign = calculateBackfacingSign(output.posWorld.xyz);
#endif #endif
output.normalWorld = calculateSpriteWorldNormal(v, backFaceSign); output.normalWorld = calculateSpriteWorldNormal(v, backFaceSign);
output.vertexLighting = calculateVertexLighting(output.posWorld, output.normalWorld); output.vertexLighting = calculateVertexLighting(output.posWorld, output.normalWorld);
#if defined(_NORMALMAP) #if defined(_NORMALMAP)
output.tangentWorld = calculateWorldTangent(v.tangent); output.tangentWorld = calculateWorldTangent(v.tangent);
output.binormalWorld = calculateSpriteWorldBinormal(v, output.normalWorld, output.tangentWorld, backFaceSign); output.binormalWorld = calculateSpriteWorldBinormal(v, output.normalWorld, output.tangentWorld, backFaceSign);
#endif #endif
TRANSFER_VERTEX_TO_FRAGMENT(output) TRANSFER_VERTEX_TO_FRAGMENT(output)
#if defined(_FOG) #if defined(_FOG)
UNITY_TRANSFER_FOG(output,output.pos); UNITY_TRANSFER_FOG(output,output.pos);
#endif // _FOG #endif // _FOG
return output; return output;
} }
//////////////////////////////////////// ////////////////////////////////////////
// Fragment programs // Fragment programs
// //
fixed4 fragBase(VertexOutput input) : SV_Target fixed4 fragBase(VertexOutput input) : SV_Target
{ {
fixed4 texureColor = calculateTexturePixel(input.texcoord); fixed4 texureColor = calculateTexturePixel(input.texcoord);
RETURN_UNLIT_IF_ADDITIVE_SLOT(texureColor, input.color) // shall be called before ALPHA_CLIP
ALPHA_CLIP(texureColor, input.color) ALPHA_CLIP(texureColor, input.color)
//Get normal direction //Get normal direction
fixed3 normalWorld = calculateNormalWorld(input); fixed3 normalWorld = calculateNormalWorld(input);
//Get Ambient diffuse //Get Ambient diffuse
fixed3 ambient = calculateAmbientLight(normalWorld); fixed3 ambient = calculateAmbientLight(normalWorld);
#if defined(SPECULAR) #if defined(SPECULAR)
//For directional lights _WorldSpaceLightPos0.w is set to zero //For directional lights _WorldSpaceLightPos0.w is set to zero
float3 lightWorldDirection = normalize(_WorldSpaceLightPos0.xyz - input.posWorld.xyz * _WorldSpaceLightPos0.w); float3 lightWorldDirection = normalize(_WorldSpaceLightPos0.xyz - input.posWorld.xyz * _WorldSpaceLightPos0.w);
float attenuation = LIGHT_ATTENUATION(input); float attenuation = LIGHT_ATTENUATION(input);
//Returns pixel lit by light, texture color should inlcluded alpha //Returns pixel lit by light, texture color should inlcluded alpha
half3 viewDir = normalize(_WorldSpaceCameraPos - input.posWorld.xyz); half3 viewDir = normalize(_WorldSpaceCameraPos - input.posWorld.xyz);
fixed4 pixel = calculateSpecularLight(getSpecularData(input.texcoord.xy, texureColor, input.color), viewDir, normalWorld, lightWorldDirection, _LightColor0.rgb * attenuation, ambient + input.vertexLighting); fixed4 pixel = calculateSpecularLight(getSpecularData(input.texcoord.xy, texureColor, input.color), viewDir, normalWorld, lightWorldDirection, _LightColor0.rgb * attenuation, ambient + input.vertexLighting);
APPLY_EMISSION_SPECULAR(pixel, input.texcoord) APPLY_EMISSION_SPECULAR(pixel, input.texcoord)
#else #else
//Get primary pixel light diffuse //Get primary pixel light diffuse
fixed3 diffuse = calculateLightDiffuse(input, normalWorld, texureColor); fixed3 diffuse = calculateLightDiffuse(input, normalWorld, texureColor);
//Combine along with vertex lighting for the base lighting pass //Combine along with vertex lighting for the base lighting pass
fixed3 lighting = ambient + diffuse + input.vertexLighting; fixed3 lighting = ambient + diffuse + input.vertexLighting;
APPLY_EMISSION(lighting, input.texcoord) APPLY_EMISSION(lighting, input.texcoord)
fixed4 pixel = calculateLitPixel(texureColor, input.color, lighting); fixed4 pixel = calculateLitPixel(texureColor, input.color, lighting);
#endif #endif
#if defined(_RIM_LIGHTING) #if defined(_RIM_LIGHTING)
pixel.rgb = applyRimLighting(input.posWorld, normalWorld, pixel); pixel.rgb = applyRimLighting(input.posWorld, normalWorld, pixel);
#endif #endif
COLORISE(pixel) COLORISE(pixel)
APPLY_FOG(pixel, input) APPLY_FOG(pixel, input)
return pixel; return pixel;
} }
fixed4 fragAdd(VertexOutput input) : SV_Target fixed4 fragAdd(VertexOutput input) : SV_Target
{ {
fixed4 texureColor = calculateTexturePixel(input.texcoord); fixed4 texureColor = calculateTexturePixel(input.texcoord);
#if defined(_COLOR_ADJUST) #if defined(_COLOR_ADJUST)
texureColor = adjustColor(texureColor); texureColor = adjustColor(texureColor);
#endif // _COLOR_ADJUST #endif // _COLOR_ADJUST
ALPHA_CLIP(texureColor, input.color) ALPHA_CLIP(texureColor, input.color)
//Get normal direction //Get normal direction
fixed3 normalWorld = calculateNormalWorld(input); fixed3 normalWorld = calculateNormalWorld(input);
#if defined(SPECULAR) #if defined(SPECULAR)
//For directional lights _WorldSpaceLightPos0.w is set to zero //For directional lights _WorldSpaceLightPos0.w is set to zero
float3 lightWorldDirection = normalize(_WorldSpaceLightPos0.xyz - input.posWorld.xyz * _WorldSpaceLightPos0.w); float3 lightWorldDirection = normalize(_WorldSpaceLightPos0.xyz - input.posWorld.xyz * _WorldSpaceLightPos0.w);
float attenuation = LIGHT_ATTENUATION(input); float attenuation = LIGHT_ATTENUATION(input);
half3 viewDir = normalize(_WorldSpaceCameraPos - input.posWorld.xyz); half3 viewDir = normalize(_WorldSpaceCameraPos - input.posWorld.xyz);
fixed4 pixel = calculateSpecularLightAdditive(getSpecularData(input.texcoord.xy, texureColor, input.color), viewDir, normalWorld, lightWorldDirection, _LightColor0.rgb * attenuation); fixed4 pixel = calculateSpecularLightAdditive(getSpecularData(input.texcoord.xy, texureColor, input.color), viewDir, normalWorld, lightWorldDirection, _LightColor0.rgb * attenuation);
#else #else
//Get light diffuse //Get light diffuse
fixed3 lighting = calculateLightDiffuse(input, normalWorld, texureColor); fixed3 lighting = calculateLightDiffuse(input, normalWorld, texureColor);
fixed4 pixel = calculateAdditiveLitPixel(texureColor, input.color, lighting); fixed4 pixel = calculateAdditiveLitPixel(texureColor, input.color, lighting);
#endif #endif
COLORISE_ADDITIVE(pixel) COLORISE_ADDITIVE(pixel)
APPLY_FOG_ADDITIVE(pixel, input) APPLY_FOG_ADDITIVE(pixel, input)
return pixel; return pixel;
} }
#endif // SPRITE_PIXEL_LIGHTING_INCLUDED #endif // SPRITE_PIXEL_LIGHTING_INCLUDED

View File

@ -6,7 +6,7 @@
//////////////////////////////////////// ////////////////////////////////////////
// Vertex structs // Vertex structs
// //
struct VertexInput struct VertexInput
{ {
float4 vertex : POSITION; float4 vertex : POSITION;
@ -22,7 +22,7 @@ struct VertexOutput
fixed4 color : COLOR; fixed4 color : COLOR;
#if defined(_FOG) #if defined(_FOG)
UNITY_FOG_COORDS(1) UNITY_FOG_COORDS(1)
#endif // _FOG #endif // _FOG
UNITY_VERTEX_OUTPUT_STEREO UNITY_VERTEX_OUTPUT_STEREO
}; };
@ -34,39 +34,35 @@ struct VertexOutput
VertexOutput vert(VertexInput input) VertexOutput vert(VertexInput input)
{ {
VertexOutput output; VertexOutput output;
UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
output.pos = calculateLocalPos(input.vertex); output.pos = calculateLocalPos(input.vertex);
output.texcoord = calculateTextureCoord(input.texcoord); output.texcoord = calculateTextureCoord(input.texcoord);
output.color = calculateVertexColor(input.color); output.color = calculateVertexColor(input.color);
#if defined(_FOG) #if defined(_FOG)
UNITY_TRANSFER_FOG(output,output.pos); UNITY_TRANSFER_FOG(output,output.pos);
#endif // _FOG #endif // _FOG
return output; return output;
} }
//////////////////////////////////////// ////////////////////////////////////////
// Fragment program // Fragment program
// //
fixed4 frag(VertexOutput input) : SV_Target fixed4 frag(VertexOutput input) : SV_Target
{ {
fixed4 texureColor = calculateTexturePixel(input.texcoord.xy); 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) ALPHA_CLIP(texureColor, input.color)
fixed4 pixel = calculatePixel(texureColor, input.color); fixed4 pixel = calculatePixel(texureColor, input.color);
COLORISE(pixel) COLORISE(pixel)
APPLY_FOG(pixel, input) APPLY_FOG(pixel, input)
return pixel; return pixel;
} }
#endif // SPRITE_UNLIT_INCLUDED #endif // SPRITE_UNLIT_INCLUDED

View File

@ -399,10 +399,10 @@ VertexOutput vert(VertexInput input)
//////////////////////////////////////// ////////////////////////////////////////
// Fragment program // Fragment program
// //
fixed4 frag(VertexOutput input) : SV_Target fixed4 frag(VertexOutput input) : SV_Target
{ {
fixed4 texureColor = calculateTexturePixel(input.texcoord.xy); 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) ALPHA_CLIP(texureColor, input.color)
#if defined(PER_PIXEL_LIGHTING) #if defined(PER_PIXEL_LIGHTING)

View File

@ -59,6 +59,8 @@ VertexOutput vert(appdata v) {
float3 positionWS = TransformObjectToWorld(v.pos); float3 positionWS = TransformObjectToWorld(v.pos);
half3 fixedNormal = half3(0, 0, -1); half3 fixedNormal = half3(0, 0, -1);
half3 normalWS = normalize(mul((float3x3)unity_ObjectToWorld, fixedNormal)); half3 normalWS = normalize(mul((float3x3)unity_ObjectToWorld, fixedNormal));
o.uv0 = v.uv0;
o.pos = TransformWorldToHClip(positionWS);
#ifdef _DOUBLE_SIDED_LIGHTING #ifdef _DOUBLE_SIDED_LIGHTING
// unfortunately we have to compute the sign here in the vertex shader // unfortunately we have to compute the sign here in the vertex shader
@ -69,7 +71,16 @@ VertexOutput vert(appdata v) {
#endif #endif
half3 shadowedColor; half3 shadowedColor;
color.rgb = LightweightLightVertexSimplified(positionWS, normalWS, shadowedColor); if (color.a == 0) {
o.color = color;
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
o.shadowedColor = color;
o.shadowCoord = float4(0, 0, 0, 0);
#endif
return o;
}
color.rgb *= LightweightLightVertexSimplified(positionWS, normalWS, shadowedColor);
#if defined(SKELETONLIT_RECEIVE_SHADOWS) #if defined(SKELETONLIT_RECEIVE_SHADOWS)
o.shadowedColor = shadowedColor; o.shadowedColor = shadowedColor;
#endif #endif
@ -78,10 +89,7 @@ VertexOutput vert(appdata v) {
half3 vertexSH; half3 vertexSH;
OUTPUT_SH(normalWS.xyz, vertexSH); OUTPUT_SH(normalWS.xyz, vertexSH);
color.rgb += SAMPLE_GI(input.lightmapUV, vertexSH, normalWS); color.rgb += SAMPLE_GI(input.lightmapUV, vertexSH, normalWS);
o.color = color; o.color = color;
o.uv0 = v.uv0;
o.pos = TransformWorldToHClip(positionWS);
#if defined(SKELETONLIT_RECEIVE_SHADOWS) #if defined(SKELETONLIT_RECEIVE_SHADOWS)
VertexPositionInputs vertexInput; VertexPositionInputs vertexInput;
@ -94,22 +102,19 @@ VertexOutput vert(appdata v) {
half4 frag(VertexOutput i) : SV_Target{ half4 frag(VertexOutput i) : SV_Target{
half4 tex = tex2D(_MainTex, i.uv0); half4 tex = tex2D(_MainTex, i.uv0);
half4 col; #if defined(_STRAIGHT_ALPHA_INPUT)
tex.rgb *= tex.a;
#endif
if (i.color.a == 0)
return tex * i.color;
#if defined(SKELETONLIT_RECEIVE_SHADOWS) #if defined(SKELETONLIT_RECEIVE_SHADOWS)
half shadowAttenuation = MainLightRealtimeShadow(i.shadowCoord); half shadowAttenuation = MainLightRealtimeShadow(i.shadowCoord);
i.color.rgb = lerp(i.shadowedColor, i.color.rgb, shadowAttenuation); i.color.rgb = lerp(i.shadowedColor, i.color.rgb, shadowAttenuation);
#endif #endif
return tex * i.color;
#if defined(_STRAIGHT_ALPHA_INPUT)
col.rgb = tex.rgb * i.color.rgb * tex.a;
#else
col.rgb = tex.rgb * i.color.rgb;
#endif
col.a = tex.a * i.color.a;
return col;
} }
#endif #endif

View File

@ -212,6 +212,7 @@ half4 ForwardPassFragmentSprite(VertexOutputLWRP input) : SV_Target
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
fixed4 texureColor = calculateTexturePixel(input.texcoord.xy); fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
RETURN_UNLIT_IF_ADDITIVE_SLOT(texureColor, input.vertexColor) // shall be called before ALPHA_CLIP
ALPHA_CLIP(texureColor, input.vertexColor) ALPHA_CLIP(texureColor, input.vertexColor)
// fill out InputData struct // fill out InputData struct

View File

@ -1,8 +1,8 @@
{ {
"name": "com.esotericsoftware.spine.lwrp-shaders", "name": "com.esotericsoftware.spine.lwrp-shaders",
"displayName": "Spine Lightweight RP Shaders", "displayName": "Spine Lightweight RP Shaders",
"description": "This plugin provides lightweight render pipeline (LWRP) shaders for the spine-unity runtime.\n\nPrerequisites:\nIt requires a working installation of the spine-unity runtime, version 3.8.\n(See http://esotericsoftware.com/git/spine-runtimes/spine-unity)", "description": "This plugin provides lightweight render pipeline (LWRP) shaders for the spine-unity runtime.\n\nPrerequisites:\nIt requires a working installation of the spine-unity runtime, version 4.0.\n(See http://esotericsoftware.com/git/spine-runtimes/spine-unity)",
"version": "3.8.1", "version": "4.0.2",
"unity": "2019.1", "unity": "2019.1",
"author": { "author": {
"name": "Esoteric Software", "name": "Esoteric Software",

View File

@ -1,8 +1,8 @@
{ {
"name": "com.esotericsoftware.spine.lwrp-shaders", "name": "com.esotericsoftware.spine.lwrp-shaders",
"displayName": "Spine Lightweight RP Shaders", "displayName": "Spine Lightweight RP Shaders",
"description": "This plugin provides lightweight render pipeline (LWRP) shaders for the spine-unity runtime.\n\nPrerequisites:\nIt requires a working installation of the spine-unity runtime, version 3.8.\n(See http://esotericsoftware.com/git/spine-runtimes/spine-unity)", "description": "This plugin provides lightweight render pipeline (LWRP) shaders for the spine-unity runtime.\n\nPrerequisites:\nIt requires a working installation of the spine-unity runtime, version 4.0.\n(See http://esotericsoftware.com/git/spine-runtimes/spine-unity)",
"version": "3.8.1", "version": "4.0.2",
"unity": "2019.2", "unity": "2019.2",
"author": { "author": {
"name": "Esoteric Software", "name": "Esoteric Software",

View File

@ -1,8 +1,8 @@
{ {
"name": "com.esotericsoftware.spine.lwrp-shaders", "name": "com.esotericsoftware.spine.lwrp-shaders",
"displayName": "Spine Lightweight RP Shaders", "displayName": "Spine Lightweight RP Shaders",
"description": "This plugin provides lightweight render pipeline (LWRP) shaders for the spine-unity runtime.\n\nPrerequisites:\nIt requires a working installation of the spine-unity runtime, version 3.8.\n(See http://esotericsoftware.com/git/spine-runtimes/spine-unity)", "description": "This plugin provides lightweight render pipeline (LWRP) shaders for the spine-unity runtime.\n\nPrerequisites:\nIt requires a working installation of the spine-unity runtime, version 4.0.\n(See http://esotericsoftware.com/git/spine-runtimes/spine-unity)",
"version": "3.8.1", "version": "4.0.2",
"unity": "2019.1", "unity": "2019.1",
"author": { "author": {
"name": "Esoteric Software", "name": "Esoteric Software",

View File

@ -1,8 +1,8 @@
{ {
"name": "com.esotericsoftware.spine.timeline", "name": "com.esotericsoftware.spine.timeline",
"displayName": "Spine Timeline Extensions", "displayName": "Spine Timeline Extensions",
"description": "This plugin provides integration of spine-unity for the Unity Timeline.\n\nPrerequisites:\nIt requires a working installation of the spine-unity runtime, version 3.8 from 2019-10-03 or newer.\n(See http://esotericsoftware.com/git/spine-runtimes/spine-unity)", "description": "This plugin provides integration of spine-unity for the Unity Timeline.\n\nPrerequisites:\nIt requires a working installation of the spine-unity runtime, version 4.0.\n(See http://esotericsoftware.com/git/spine-runtimes/spine-unity)",
"version": "3.8.2", "version": "4.0.2",
"unity": "2018.3", "unity": "2018.3",
"author": { "author": {
"name": "Esoteric Software", "name": "Esoteric Software",

View File

@ -87,7 +87,9 @@ VertexOutputSpriteURP2D CombinedShapeLightVertex(VertexInput input)
half4 CombinedShapeLightFragment(VertexOutputSpriteURP2D input) : SV_Target half4 CombinedShapeLightFragment(VertexOutputSpriteURP2D input) : SV_Target
{ {
fixed4 texureColor = calculateTexturePixel(input.texcoord.xy); fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
RETURN_UNLIT_IF_ADDITIVE_SLOT(texureColor, input.vertexColor) // shall be called before ALPHA_CLIP
ALPHA_CLIP(texureColor, input.vertexColor) ALPHA_CLIP(texureColor, input.vertexColor)
texureColor *= input.vertexColor; texureColor *= input.vertexColor;
half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, input.texcoord.xy); half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, input.texcoord.xy);

View File

@ -98,14 +98,13 @@
half4 CombinedShapeLightFragment(Varyings i) : SV_Target half4 CombinedShapeLightFragment(Varyings i) : SV_Target
{ {
half4 tex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv); half4 tex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
half4 main;
#if defined(_STRAIGHT_ALPHA_INPUT) #if defined(_STRAIGHT_ALPHA_INPUT)
main.rgb = tex.rgb * i.color.rgb * tex.a; tex.rgb *= tex.a;
#else
main.rgb = tex.rgb * i.color.rgb;
#endif #endif
main.a = tex.a * i.color.a;
half4 main = tex * i.color;
if (i.color.a == 0)
return main;
half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, i.uv); half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, i.uv);
return CombinedShapeLightShared(main, mask, i.lightingUV); return CombinedShapeLightShared(main, mask, i.lightingUV);

View File

@ -59,6 +59,8 @@ VertexOutput vert(appdata v) {
float3 positionWS = TransformObjectToWorld(v.pos); float3 positionWS = TransformObjectToWorld(v.pos);
half3 fixedNormal = half3(0, 0, -1); half3 fixedNormal = half3(0, 0, -1);
half3 normalWS = normalize(mul((float3x3)unity_ObjectToWorld, fixedNormal)); half3 normalWS = normalize(mul((float3x3)unity_ObjectToWorld, fixedNormal));
o.uv0 = v.uv0;
o.pos = TransformWorldToHClip(positionWS);
#ifdef _DOUBLE_SIDED_LIGHTING #ifdef _DOUBLE_SIDED_LIGHTING
// unfortunately we have to compute the sign here in the vertex shader // unfortunately we have to compute the sign here in the vertex shader
@ -69,7 +71,16 @@ VertexOutput vert(appdata v) {
#endif #endif
half3 shadowedColor; half3 shadowedColor;
color.rgb = LightweightLightVertexSimplified(positionWS, normalWS, shadowedColor); if (color.a == 0) {
o.color = color;
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
o.shadowedColor = color;
o.shadowCoord = float4(0, 0, 0, 0);
#endif
return o;
}
color.rgb *= LightweightLightVertexSimplified(positionWS, normalWS, shadowedColor);
#if defined(SKELETONLIT_RECEIVE_SHADOWS) #if defined(SKELETONLIT_RECEIVE_SHADOWS)
o.shadowedColor = shadowedColor; o.shadowedColor = shadowedColor;
#endif #endif
@ -78,10 +89,7 @@ VertexOutput vert(appdata v) {
half3 vertexSH; half3 vertexSH;
OUTPUT_SH(normalWS.xyz, vertexSH); OUTPUT_SH(normalWS.xyz, vertexSH);
color.rgb += SAMPLE_GI(input.lightmapUV, vertexSH, normalWS); color.rgb += SAMPLE_GI(input.lightmapUV, vertexSH, normalWS);
o.color = color; o.color = color;
o.uv0 = v.uv0;
o.pos = TransformWorldToHClip(positionWS);
#if defined(SKELETONLIT_RECEIVE_SHADOWS) #if defined(SKELETONLIT_RECEIVE_SHADOWS)
VertexPositionInputs vertexInput; VertexPositionInputs vertexInput;
@ -94,22 +102,18 @@ VertexOutput vert(appdata v) {
half4 frag(VertexOutput i) : SV_Target{ half4 frag(VertexOutput i) : SV_Target{
half4 tex = tex2D(_MainTex, i.uv0); half4 tex = tex2D(_MainTex, i.uv0);
half4 col; #if defined(_STRAIGHT_ALPHA_INPUT)
tex.rgb *= tex.a;
#endif
if (i.color.a == 0)
return tex * i.color;
#if defined(SKELETONLIT_RECEIVE_SHADOWS) #if defined(SKELETONLIT_RECEIVE_SHADOWS)
half shadowAttenuation = MainLightRealtimeShadow(i.shadowCoord); half shadowAttenuation = MainLightRealtimeShadow(i.shadowCoord);
i.color.rgb = lerp(i.shadowedColor, i.color.rgb, shadowAttenuation); i.color.rgb = lerp(i.shadowedColor, i.color.rgb, shadowAttenuation);
#endif #endif
return tex * i.color;
#if defined(_STRAIGHT_ALPHA_INPUT)
col.rgb = tex.rgb * i.color.rgb * tex.a;
#else
col.rgb = tex.rgb * i.color.rgb;
#endif
col.a = tex.a * i.color.a;
return col;
} }
#endif #endif

View File

@ -222,6 +222,7 @@ half4 ForwardPassFragmentSprite(VertexOutputLWRP input) : SV_Target
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
fixed4 texureColor = calculateTexturePixel(input.texcoord.xy); fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
RETURN_UNLIT_IF_ADDITIVE_SLOT(texureColor, input.vertexColor) // shall be called before ALPHA_CLIP
ALPHA_CLIP(texureColor, input.vertexColor) ALPHA_CLIP(texureColor, input.vertexColor)
// fill out InputData struct // fill out InputData struct

View File

@ -1,8 +1,8 @@
{ {
"name": "com.esotericsoftware.spine.urp-shaders", "name": "com.esotericsoftware.spine.urp-shaders",
"displayName": "Spine Universal RP Shaders", "displayName": "Spine Universal RP Shaders",
"description": "This plugin provides universal render pipeline (URP) shaders for the spine-unity runtime.\n\nPrerequisites:\nIt requires a working installation of the spine-unity runtime, version 3.8.\n(See http://esotericsoftware.com/git/spine-runtimes/spine-unity)", "description": "This plugin provides universal render pipeline (URP) shaders for the spine-unity runtime.\n\nPrerequisites:\nIt requires a working installation of the spine-unity runtime, version 4.0.\n(See http://esotericsoftware.com/git/spine-runtimes/spine-unity)",
"version": "3.8.1", "version": "4.0.2",
"unity": "2019.3", "unity": "2019.3",
"author": { "author": {
"name": "Esoteric Software", "name": "Esoteric Software",