From 5635f31053c905627581a1cf2d7a5b9fad3fe654 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Mon, 3 Jul 2023 20:55:19 +0200 Subject: [PATCH 1/3] [unity] Fixed URP shaders compile error on Unity 2023.1. Closes #2311. --- .../Spine-Sprite-NormalsPass-URP-2D.hlsl | 2 -- .../Spine-Sprite-StandardPass-URP-2D.hlsl | 2 -- .../Shaders/Include/Spine-Common-URP.hlsl | 17 +++++++++++------ .../Spine-SkeletonLit-ForwardPass-URP.hlsl | 4 ++++ .../Include/Spine-Sprite-ForwardPass-URP.hlsl | 4 ++++ .../package.json | 2 +- 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/2D/Include/Spine-Sprite-NormalsPass-URP-2D.hlsl b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/2D/Include/Spine-Sprite-NormalsPass-URP-2D.hlsl index 150a75d76..6a0587cfa 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/2D/Include/Spine-Sprite-NormalsPass-URP-2D.hlsl +++ b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/2D/Include/Spine-Sprite-NormalsPass-URP-2D.hlsl @@ -1,8 +1,6 @@ #ifndef SPRITE_NORMALS_PASS_URP_INCLUDED #define SPRITE_NORMALS_PASS_URP_INCLUDED -#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/LightingUtility.hlsl" - #include "../Include/SpineCoreShaders/ShaderShared.cginc" #include "../Include/SpineCoreShaders/SpriteLighting.cginc" diff --git a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/2D/Include/Spine-Sprite-StandardPass-URP-2D.hlsl b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/2D/Include/Spine-Sprite-StandardPass-URP-2D.hlsl index 2f95b1bb2..51ded8a72 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/2D/Include/Spine-Sprite-StandardPass-URP-2D.hlsl +++ b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/2D/Include/Spine-Sprite-StandardPass-URP-2D.hlsl @@ -1,8 +1,6 @@ #ifndef SPRITE_STANDARD_PASS_URP_INCLUDED #define SPRITE_STANDARD_PASS_URP_INCLUDED -#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/LightingUtility.hlsl" - #include "../Include/SpineCoreShaders/ShaderShared.cginc" #include "../Include/SpineCoreShaders/SpriteLighting.cginc" #if defined(_ALPHAPREMULTIPLY_ON) diff --git a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Common-URP.hlsl b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Common-URP.hlsl index a56e218ea..21c062e23 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Common-URP.hlsl +++ b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Common-URP.hlsl @@ -2,16 +2,21 @@ #define SPINE_COMMON_URP_INCLUDED #ifdef USE_FORWARD_PLUS -#define IS_URP_14_OR_NEWER 1 -#define IS_URP_12_OR_NEWER 1 -#else -#define IS_URP_14_OR_NEWER 0 - #ifdef UNIVERSAL_REALTIME_LIGHTS_INCLUDED + #define IS_URP_14_OR_NEWER 1 #define IS_URP_12_OR_NEWER 1 +#else + #define IS_URP_14_OR_NEWER 0 + #ifdef UNIVERSAL_REALTIME_LIGHTS_INCLUDED + #define IS_URP_12_OR_NEWER 1 #else - #define IS_URP_12_OR_NEWER 0 + #define IS_URP_12_OR_NEWER 0 #endif #endif +#if IS_URP_14_OR_NEWER && !defined(_USE_WEBGL1_LIGHTS) + #define IS_URP_15_OR_NEWER 1 +#else + #define IS_URP_15_OR_NEWER 0 +#endif #if defined(_WRITE_RENDERING_LAYERS) && IS_URP_14_OR_NEWER #define USE_WRITE_RENDERING_LAYERS diff --git a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-SkeletonLit-ForwardPass-URP.hlsl b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-SkeletonLit-ForwardPass-URP.hlsl index 560259251..49421f68e 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-SkeletonLit-ForwardPass-URP.hlsl +++ b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-SkeletonLit-ForwardPass-URP.hlsl @@ -150,7 +150,11 @@ VertexOutput vert(appdata v) { // Note: ambient light is also handled via SH. half3 vertexSH; +#if IS_URP_15_OR_NEWER + OUTPUT_SH(positionWS, normalWS.xyz, GetWorldSpaceNormalizeViewDir(positionWS), vertexSH); +#else OUTPUT_SH(normalWS.xyz, vertexSH); +#endif color.rgb += SAMPLE_GI(v.lightmapUV, vertexSH, normalWS); o.color = color; diff --git a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl index df7b69dd6..42aac9a17 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl +++ b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl @@ -311,7 +311,11 @@ VertexOutputLWRP ForwardPassVertexSprite(VertexInput input) output.fogFactorAndVertexLight.x = fogFactor; #endif +#if IS_URP_15_OR_NEWER + OUTPUT_SH(positionWS, normalWS.xyz, GetWorldSpaceNormalizeViewDir(positionWS), output.vertexSH); +#else OUTPUT_SH(normalWS.xyz, output.vertexSH); +#endif return output; } diff --git a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/package.json b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/package.json index eced01aad..25e15624d 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/package.json +++ b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/package.json @@ -2,7 +2,7 @@ "name": "com.esotericsoftware.spine.urp-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 4.1.\n(See http://esotericsoftware.com/git/spine-runtimes/spine-unity)", - "version": "4.1.16", + "version": "4.1.17", "unity": "2019.3", "author": { "name": "Esoteric Software", From ccc41337f6ea0fae9a61b6957899fc8c3ef5278d Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Tue, 4 Jul 2023 18:36:42 +0200 Subject: [PATCH 2/3] [unity] Fixed Timeline preview speed-scale applied twice in Unity 2019 and newer versions. Closes #2312. --- .../SpineAnimationStateMixerBehaviour.cs | 18 +++++++++++++++++- .../package.json | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateMixerBehaviour.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateMixerBehaviour.cs index fbdaf8c5c..84725b448 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateMixerBehaviour.cs +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateMixerBehaviour.cs @@ -27,6 +27,10 @@ * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ +#if UNITY_2019_1_OR_NEWER +#define SPEED_INCLUDED_IN_CLIP_TIME +#endif + #define SPINE_EDITMODEPOSE using System; @@ -212,7 +216,11 @@ namespace Spine.Unity.Playables { float clipSpeed = (float)clipPlayable.GetSpeed(); trackEntry.EventThreshold = clipData.eventThreshold; trackEntry.DrawOrderThreshold = clipData.drawOrderThreshold; - trackEntry.TrackTime = (float)clipPlayable.GetTime() * clipSpeed * rootPlayableSpeed; +#if SPEED_INCLUDED_IN_CLIP_TIME + trackEntry.TrackTime = (float)clipPlayable.GetTime(); +#else + trackEntry.TrackTime = (float)clipPlayable.GetTime() * rootPlayableSpeed * clipSpeed; +#endif trackEntry.TimeScale = clipSpeed * rootPlayableSpeed; trackEntry.AttachmentThreshold = clipData.attachmentThreshold; trackEntry.HoldPrevious = clipData.holdPrevious; @@ -283,12 +291,20 @@ namespace Spine.Unity.Playables { var fromClip = (ScriptPlayable)playable.GetInput(lastNonZeroWeightTrack - 1); SpineAnimationStateBehaviour fromClipData = fromClip.GetBehaviour(); fromAnimation = fromClipData.animationReference != null ? fromClipData.animationReference.Animation : null; +#if SPEED_INCLUDED_IN_CLIP_TIME + fromClipTime = (float)fromClip.GetTime(); +#else fromClipTime = (float)fromClip.GetTime() * (float)fromClip.GetSpeed() * rootSpeed; +#endif fromClipLoop = fromClipData.loop; } Animation toAnimation = clipData.animationReference != null ? clipData.animationReference.Animation : null; +#if SPEED_INCLUDED_IN_CLIP_TIME + float toClipTime = (float)inputPlayableClip.GetTime(); +#else float toClipTime = (float)inputPlayableClip.GetTime() * (float)inputPlayableClip.GetSpeed() * rootSpeed; +#endif float mixDuration = clipData.mixDuration; if (!clipData.customDuration && fromAnimation != null && toAnimation != null) { diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/package.json b/spine-unity/Modules/com.esotericsoftware.spine.timeline/package.json index 4bf822a59..a83045a1a 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/package.json +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/package.json @@ -2,7 +2,7 @@ "name": "com.esotericsoftware.spine.timeline", "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 and spine-csharp runtimes as UPM packages (not as spine-unity unitypackage), version 4.1.\n(See http://esotericsoftware.com/git/spine-runtimes/spine-unity)", - "version": "4.1.8", + "version": "4.1.9", "unity": "2018.3", "author": { "name": "Esoteric Software", From 0672c6c862095813979f74a558754b7445f359a6 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Tue, 11 Jul 2023 09:10:28 +0200 Subject: [PATCH 3/3] [phaser] Bounds providers return zero bounds in case there are no attachments to calculate the bounds with. --- .../example/mix-and-match-example.html | 4 +-- spine-ts/spine-phaser/src/SpineGameObject.ts | 27 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/spine-ts/spine-phaser/example/mix-and-match-example.html b/spine-ts/spine-phaser/example/mix-and-match-example.html index b5a77ccc0..fd87dedb3 100644 --- a/spine-ts/spine-phaser/example/mix-and-match-example.html +++ b/spine-ts/spine-phaser/example/mix-and-match-example.html @@ -37,7 +37,7 @@ } function create() { - const mixAndMatch = this.add.spine(400, 500, 'mix-and-match-data', "mix-and-match-atlas"); + const mixAndMatch = this.add.spine(400, 500, 'mix-and-match-data', "mix-and-match-atlas", new spine.SkinsAndAnimationBoundsProvider(null, ["full-skins/girl"])); mixAndMatch.scale = 0.5; mixAndMatch.animationState.setAnimation(0, "walk", true); @@ -51,7 +51,7 @@ skin.addSkin(skeletonData.findSkin("clothes/hoodie-orange")); skin.addSkin(skeletonData.findSkin("legs/pants-jeans")); skin.addSkin(skeletonData.findSkin("accessories/bag")); - skin.addSkin(skeletonData.findSkin("accessories/hat-red-yellow")); + skin.addSkin(skeletonData.findSkin("accessories/hat-red-yellow")); mixAndMatch.skeleton.setSkin(skin); mixAndMatch.skeleton.setToSetupPose(); } diff --git a/spine-ts/spine-phaser/src/SpineGameObject.ts b/spine-ts/spine-phaser/src/SpineGameObject.ts index 856476391..3df13af95 100644 --- a/spine-ts/spine-phaser/src/SpineGameObject.ts +++ b/spine-ts/spine-phaser/src/SpineGameObject.ts @@ -25,7 +25,8 @@ export class SetupPoseBoundsProvider implements SpineGameObjectBoundsProvider { const skeleton = new Skeleton(gameObject.skeleton.data); skeleton.setToSetupPose(); skeleton.updateWorldTransform(); - return skeleton.getBoundsRect(); + const bounds = skeleton.getBoundsRect(); + return bounds.width == Number.NEGATIVE_INFINITY ? { x: 0, y: 0, width: 0, height: 0 } : bounds; } } @@ -36,7 +37,7 @@ export class SkinsAndAnimationBoundsProvider implements SpineGameObjectBoundsPro * @param skins The skins to use for calculating the bounds. If empty, the default skin is used. * @param timeStep The time step to use for calculating the bounds. A smaller time step means more precision, but slower calculation. */ - constructor (private animation: string, private skins: string[] = [], private timeStep: number = 0.05) { + constructor (private animation: string | null, private skins: string[] = [], private timeStep: number = 0.05) { } calculateBounds (gameObject: SpineGameObject): { x: number; y: number; width: number; height: number; } { @@ -61,7 +62,8 @@ export class SkinsAndAnimationBoundsProvider implements SpineGameObjectBoundsPro const animation = this.animation != null ? data.findAnimation(this.animation!) : null; if (animation == null) { skeleton.updateWorldTransform(); - return skeleton.getBoundsRect(); + const bounds = skeleton.getBoundsRect(); + return bounds.width == Number.NEGATIVE_INFINITY ? { x: 0, y: 0, width: 0, height: 0 } : bounds; } else { let minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY; animationState.clearTracks(); @@ -78,30 +80,31 @@ export class SkinsAndAnimationBoundsProvider implements SpineGameObjectBoundsPro maxX = Math.max(maxX, minX + bounds.width); maxY = Math.max(maxY, minY + bounds.height); } - return { x: minX, y: minY, width: maxX - minX, height: maxY - minY }; + const bounds = { x: minX, y: minY, width: maxX - minX, height: maxY - minY }; + return bounds.width == Number.NEGATIVE_INFINITY ? { x: 0, y: 0, width: 0, height: 0 } : bounds; } } } /** * A SpineGameObject is a Phaser {@link GameObject} that can be added to a Phaser Scene and render a Spine skeleton. - * + * * The Spine GameObject is a thin wrapper around a Spine {@link Skeleton}, {@link AnimationState} and {@link AnimationStateData}. It is responsible for: * - updating the animation state * - applying the animation state to the skeleton's bones, slots, attachments, and draw order. * - updating the skeleton's bone world transforms * - rendering the skeleton - * + * * See the {@link SpinePlugin} class for more information on how to create a `SpineGameObject`. - * + * * The skeleton, animation state, and animation state data can be accessed via the repsective fields. They can be manually updated via {@link updatePose}. - * + * * To modify the bone hierarchy before the world transforms are computed, a callback can be set via the {@link beforeUpdateWorldTransforms} field. - * + * * To modify the bone hierarchy after the world transforms are computed, a callback can be set via the {@link afterUpdateWorldTransforms} field. - * - * The class also features methods to convert between the skeleton coordinate system and the Phaser coordinate system. - * + * + * The class also features methods to convert between the skeleton coordinate system and the Phaser coordinate system. + * * See {@link skeletonToPhaserWorldCoordinates}, {@link phaserWorldCoordinatesToSkeleton}, and {@link phaserWorldCoordinatesToBoneLocal.} */ export class SpineGameObject extends ComputedSizeMixin(DepthMixin(FlipMixin(ScrollFactorMixin(TransformMixin(VisibleMixin(AlphaMixin(BaseSpineGameObject))))))) {