diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp index e52e8fa35..7b9eeedba 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp @@ -348,15 +348,39 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton *Skeleton) { indices.Add(idx + attachmentIndices[j]); } - FVector normal = FVector(0, -1, 0); - if (numVertices > 2 && - FVector::CrossProduct( - vertices[indices[firstIndex + 2]] - vertices[indices[firstIndex]], - vertices[indices[firstIndex + 1]] - vertices[indices[firstIndex]]) - .Y > 0.f) { - normal.Y = 1; + + //Calculate total triangle to add on this loof. + + int TriangleInitialCount = firstIndex / 3; + + int TriangleToAddNum = indices.Num() / 3 - TriangleInitialCount; + + int FirstVertexIndex = vertices.Num() - numVertices; + + //loof through all the triangles and resolve to be reversed if the triangle has winding order as CCW. + + for (int j = 0; j < TriangleToAddNum; j++) { + + const int TargetTringleIndex = firstIndex + j * 3; + + if (FVector::CrossProduct( + vertices[indices[TargetTringleIndex + 2]] - vertices[indices[TargetTringleIndex]], + vertices[indices[TargetTringleIndex + 1]] - vertices[indices[TargetTringleIndex]]) + .Y < 0.f) { + + const int32 targetVertex = indices[TargetTringleIndex]; + indices[TargetTringleIndex] = indices[TargetTringleIndex + 2]; + indices[TargetTringleIndex + 2] = targetVertex; + } } + + + FVector normal = FVector(0, 1, 0); + + //Add normals for vertices. + for (int j = 0; j < numVertices; j++) { + normals.Add(normal); } @@ -370,4 +394,4 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton *Skeleton) { clipper.clipEnd(); } -#undef LOCTEXT_NAMESPACE +#undef LOCTEXT_NAMESPACE \ No newline at end of file diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonGraphicInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonGraphicInspector.cs index c6a402943..8fe4c60bd 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonGraphicInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonGraphicInspector.cs @@ -60,7 +60,7 @@ namespace Spine.Unity.Editor { SerializedProperty initialFlipX, initialFlipY; SerializedProperty meshGeneratorSettings; SerializedProperty allowMultipleCanvasRenderers, separatorSlotNames, enableSeparatorSlots, updateSeparatorPartLocation; - SerializedProperty raycastTarget; + SerializedProperty raycastTarget, maskable; readonly GUIContent UnscaledTimeLabel = new GUIContent("Unscaled Time", "If enabled, AnimationState uses unscaled game time (Time.unscaledDeltaTime), " + @@ -107,6 +107,7 @@ namespace Spine.Unity.Editor { material = so.FindProperty("m_Material"); color = so.FindProperty("m_Color"); raycastTarget = so.FindProperty("m_RaycastTarget"); + maskable = so.FindProperty("m_Maskable"); // SkeletonRenderer additiveMaterial = so.FindProperty("additiveMaterial"); @@ -295,6 +296,7 @@ namespace Spine.Unity.Editor { EditorGUILayout.Space(); EditorGUILayout.LabelField("UI", EditorStyles.boldLabel); EditorGUILayout.PropertyField(raycastTarget); + if (maskable != null) EditorGUILayout.PropertyField(maskable); EditorGUILayout.BeginHorizontal(GUILayout.Height(EditorGUIUtility.singleLineHeight + 5)); EditorGUILayout.PrefixLabel("Match RectTransform with Mesh"); diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineBuildProcessor.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineBuildProcessor.cs index 12d836ea5..4ed661539 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineBuildProcessor.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineBuildProcessor.cs @@ -36,7 +36,14 @@ #define HAS_ON_POSTPROCESS_PREFAB #endif -#if UNITY_2020_3_OR_NEWER +#if (UNITY_2020_3 && !(UNITY_2020_3_1 || UNITY_2020_3_2 || UNITY_2020_3_3 || UNITY_2020_3_4 || UNITY_2020_3_5 || UNITY_2020_3_6 || UNITY_2020_3_7 || UNITY_2020_3_8 || UNITY_2020_3_9 || UNITY_2020_3_10 || UNITY_2020_3_11 || UNITY_2020_3_12 || UNITY_2020_3_13 || UNITY_2020_3_14 || UNITY_2020_3_15)) +#define UNITY_2020_3_16_OR_NEWER +#endif +#if (UNITY_2021_1 && !(UNITY_2021_1_1 || UNITY_2021_1_2 || UNITY_2021_1_3 || UNITY_2021_1_4 || UNITY_2021_1_5 || UNITY_2021_1_6 || UNITY_2021_1_7 || UNITY_2021_1_8 || UNITY_2021_1_9 || UNITY_2021_1_10 || UNITY_2021_1_11 || UNITY_2021_1_12 || UNITY_2021_1_13 || UNITY_2021_1_14 || UNITY_2021_1_15 || UNITY_2021_1_16)) +#define UNITY_2021_1_17_OR_NEWER +#endif + +#if UNITY_2020_3_16_OR_NEWER || UNITY_2021_1_17_OR_NEWER #define HAS_SAVE_ASSET_IF_DIRTY #endif 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 7c39640cd..e526d3574 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 @@ -43,6 +43,22 @@ struct VertexOutputLWRP /////////////////////////////////////////////////////////////////////////////// // Vertex and Fragment functions // /////////////////////////////////////////////////////////////////////////////// +#if defined(_ADDITIONAL_LIGHT_SHADOWS) && !defined(_RECEIVE_SHADOWS_OFF) +half4 CalculateShadowMaskBackwardsCompatible(InputData inputData) +{ + // To ensure backward compatibility we have to avoid using shadowMask input, as it is not present in older shaders +#if defined(SHADOWS_SHADOWMASK) && defined(LIGHTMAP_ON) + half4 shadowMask = inputData.shadowMask; +#elif !defined (LIGHTMAP_ON) + half4 shadowMask = unity_ProbesOcclusion; +#else + half4 shadowMask = half4(1, 1, 1, 1); +#endif + + return shadowMask; +} +#endif + half3 LightweightLightVertexSimplified(float3 positionWS, half3 normalWS) { #ifdef _MAIN_LIGHT_VERTEX Light mainLight = GetMainLight(); @@ -101,7 +117,12 @@ half4 LightweightFragmentPBRSimplified(InputData inputData, half4 texAlbedoAlpha int pixelLightCount = GetAdditionalLightsCount(); for (int i = 0; i < pixelLightCount; ++i) { +#if defined(_ADDITIONAL_LIGHT_SHADOWS) && !defined(_RECEIVE_SHADOWS_OFF) + half4 shadowMask = CalculateShadowMaskBackwardsCompatible(inputData); + Light light = GetAdditionalLight(i, inputData.positionWS, shadowMask); +#else Light light = GetAdditionalLight(i, inputData.positionWS); +#endif finalColor += LightingPhysicallyBased(brdfData, light, inputData.normalWS, inputData.viewDirectionWS); } #endif @@ -142,7 +163,12 @@ half4 LightweightFragmentBlinnPhongSimplified(InputData inputData, half4 texDiff int pixelLightCount = GetAdditionalLightsCount(); for (int i = 0; i < pixelLightCount; ++i) { +#if defined(_ADDITIONAL_LIGHT_SHADOWS) && !defined(_RECEIVE_SHADOWS_OFF) + half4 shadowMask = CalculateShadowMaskBackwardsCompatible(inputData); + Light light = GetAdditionalLight(i, inputData.positionWS, shadowMask); +#else Light light = GetAdditionalLight(i, inputData.positionWS); +#endif half3 attenuation = (light.distanceAttenuation * light.shadowAttenuation); half3 attenuatedLightColor = light.color * attenuation; #ifndef _DIFFUSE_RAMP 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 bc6093559..b2776c014 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.2", + "version": "4.1.3", "unity": "2019.3", "author": { "name": "Esoteric Software",