Forráskód Böngészése

Merge branch '3.8' into 4.0-beta

Harald Csaszar 4 éve
szülő
commit
f85907965c

+ 1 - 0
CHANGELOG.md

@@ -382,6 +382,7 @@
   * Sprite shaders now provide four `Diffuse Ramp` modes as an Inspector Material parameter: `Hard`, `Soft`, `Old Hard` and `Old Soft`. In spine-unity 3.8 it defaults to `Old Hard` to keep the behaviour of existing projects unchanged. From 4.0 on it defaults to `Hard` for newly created materials while existing ones remain unchanged. Note that `Old Hard` and `Old Soft` ramp versions were using only the right half of the ramp texture, and additionally multiplying the light intensity by 2, both leading to brighter lighting than without a ramp texture active. The new ramp modes `Hard` and `Soft` use the full ramp texture and do not modify light intensity, being consistent with lighting without a ramp texture active.
   * Added **native support for slot blend modes** `Additive`, `Multiply` and `Screen` with automatic assignment at newly imported skeleton assets. `BlendModeMaterialAssets` are now obsolete and replaced by the native properties at `SkeletonDataAsset`. The `SkeletonDataAsset` Inspector provides a new `Blend Modes - Upgrade` button to upgrade an obsolete `BlendModeMaterialAsset` to the native blend modes properties. This upgrade will be performed automatically on imported and re-imported assets in Unity 2020.1 and newer to prevent reported `BlendModeMaterialAsset` issues in these Unity versions. spine-unity 4.0 and newer will automatically perform this upgrade regardless of the Unity version.
   * `BoneFollower` and `BoneFollowerGraphic` components now provide better support for following bones when the skeleton's Transform is not the parent of the follower's Transform. Previously e.g. rotating a common parent Transform did not lead to the desired result, as well as negatively scaling a skeleton's Transform when it is not a parent of the follower's Transform.
+  * URP and LWRP `Sprite` and `SkeletonLit` shaders no longer require `Advanced - Add Normals` enabled to properly cast and receive shadows. It is recommended to disable `Add Normals` if normals are otherwise not needed.
 
 * **Changes of default values**
   * `SkeletonMecanim`'s `Layer Mix Mode` now defaults to `MixMode.MixNext` instead of `MixMode.MixAlways`.

+ 18 - 7
spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AtlasUtilities.cs

@@ -601,7 +601,7 @@ namespace Spine.Unity.AttachmentTools {
 				destination.SetPixels(pixelBuffer);
 				destination.Apply();
 			} else {
-				Graphics.CopyTexture(source, 0, 0, (int)sourceRect.x, (int)sourceRect.y, (int)sourceRect.width, (int)sourceRect.height, destination, 0, 0, 0, 0);
+			 	Graphics.CopyTexture(source, 0, 0, (int)sourceRect.x, (int)sourceRect.y, (int)sourceRect.width, (int)sourceRect.height, destination, 0, 0, 0, 0);
 			}
 		}
 
@@ -646,7 +646,7 @@ namespace Spine.Unity.AttachmentTools {
 		/// <summary>
 		/// Returns a Rect of the AtlasRegion according to Spine texture coordinates. (x-right, y-down)</summary>
 		static Rect GetSpineAtlasRect (this AtlasRegion region, bool includeRotate = true) {
-			if (includeRotate && region.degrees == 90)
+			if (includeRotate && (region.degrees == 90 || region.degrees == 270))
 				return new Rect(region.x, region.y, region.height, region.width);
 			else
 				return new Rect(region.x, region.y, region.width, region.height);
@@ -680,7 +680,7 @@ namespace Spine.Unity.AttachmentTools {
 
 			int x = (int)rr.x, y = (int)rr.y;
 			int w, h;
-			if (referenceRegion.degrees == 90) {
+			if (referenceRegion.degrees == 90 || referenceRegion.degrees == 270) {
 				w = (int)rr.height;
 				h = (int)rr.width;
 			} else {
@@ -693,14 +693,24 @@ namespace Spine.Unity.AttachmentTools {
 			int offsetX = Mathf.RoundToInt((float)referenceRegion.offsetX * ((float)w / (float)referenceRegion.width));
 			int offsetY = Mathf.RoundToInt((float)referenceRegion.offsetY * ((float)h / (float)referenceRegion.height));
 
+			if (referenceRegion.degrees == 270) {
+				w = (int)rr.width;
+				h = (int)rr.height;
+			}
+
+			float u = uvRect.xMin;
+			float u2 = uvRect.xMax;
+			float v = uvRect.yMax;
+			float v2 = uvRect.yMin;
+
 			return new AtlasRegion {
 				page = page,
 				name = referenceRegion.name,
 
-				u = uvRect.xMin,
-				u2 = uvRect.xMax,
-				v = uvRect.yMax,
-				v2 = uvRect.yMin,
+				u = u,
+				u2 = u2,
+				v = v,
+				v2 = v2,
 
 				index = -1,
 
@@ -713,6 +723,7 @@ namespace Spine.Unity.AttachmentTools {
 				x = x,
 				y = y,
 
+				rotate = referenceRegion.rotate,
 				degrees = referenceRegion.degrees
 			};
 		}

+ 0 - 8
spine-unity/Assets/Spine/Runtime/spine-unity/Utility/MaterialChecks.cs

@@ -66,10 +66,6 @@ namespace Spine.Unity {
 			"\nWarning: 'Add Normals' required when not using 'Fixed Normals'!\n\nPlease\n"
 			+ "a) enable 'Add Normals' at the SkeletonRenderer/SkeletonAnimation component under 'Advanced' or\n"
 			+ "b) enable 'Fixed Normals' at the Material.\n";
-		public static readonly string kAddNormalsRequiredForURPShadowsMessage =
-			"\nWarning: 'Add Normals' required on URP shader to receive shadows!\n\nPlease\n"
-			+ "a) enable 'Add Normals' at the SkeletonRenderer/SkeletonAnimation component under 'Advanced' or\n"
-			+ "b) disable 'Receive Shadows' at the Material.\n";
 		public static readonly string kSolveTangentsMessage =
 			"\nWarning: 'Solve Tangents' required when using a Normal Map!\n\nPlease\n"
 			+ "a) enable 'Solve Tangents' at the SkeletonRenderer/SkeletonAnimation component under 'Advanced' or\n"
@@ -119,10 +115,6 @@ namespace Spine.Unity {
 					isProblematic = true;
 					errorMessage += kTintBlackMessage;
 				}
-				if (IsURP3DMaterial(material) && !AreShadowsDisabled(material) && renderer.addNormals == false) {
-					isProblematic = true;
-					errorMessage += kAddNormalsRequiredForURPShadowsMessage;
-				}
 			}
 			return isProblematic;
 		}

+ 34 - 6
spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-SkeletonLit-ForwardPass-LW.hlsl

@@ -5,6 +5,10 @@
 #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Core.hlsl"
 #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Lighting.hlsl"
 
+#if (defined(_MAIN_LIGHT_SHADOWS) || defined(MAIN_LIGHT_CALCULATE_SHADOWS)) && !defined(_RECEIVE_SHADOWS_OFF)
+#define SKELETONLIT_RECEIVE_SHADOWS
+#endif
+
 struct appdata {
 	float3 pos : POSITION;
 	float3 normal : NORMAL;
@@ -18,25 +22,32 @@ struct VertexOutput {
 	half4 color : COLOR0;
 	float2 uv0 : TEXCOORD0;
 	float4 pos : SV_POSITION;
+
+#if defined(SKELETONLIT_RECEIVE_SHADOWS)
+	float4 shadowCoord : TEXCOORD1;
+	half3 shadowedColor : TEXCOORD2;
+#endif
+
 	UNITY_VERTEX_OUTPUT_STEREO
 };
 
-half3 LightweightLightVertexSimplified(float3 positionWS, half3 normalWS) {
+half3 LightweightLightVertexSimplified(float3 positionWS, half3 normalWS, out half3 shadowedColor) {
 	Light mainLight = GetMainLight();
-
 	half3 attenuatedLightColor = mainLight.color * (mainLight.distanceAttenuation * mainLight.shadowAttenuation);
-	half3 diffuseLightColor = LightingLambert(attenuatedLightColor, mainLight.direction, normalWS);
+	half3 mainLightColor = LightingLambert(attenuatedLightColor, mainLight.direction, normalWS);
 
+	half3 additionalLightColor = half3(0, 0, 0);
 	// Note: we don't add any lighting in the fragment shader, thus we include both variants below
 #if defined(_ADDITIONAL_LIGHTS) || defined(_ADDITIONAL_LIGHTS_VERTEX)
 	for (int i = 0; i < GetAdditionalLightsCount(); ++i)
 	{
 		Light light = GetAdditionalLight(i, positionWS);
 		half3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation);
-		diffuseLightColor += LightingLambert(attenuatedLightColor, light.direction, normalWS);
+		additionalLightColor += LightingLambert(attenuatedLightColor, light.direction, normalWS);
 	}
 #endif
-	return diffuseLightColor;
+	shadowedColor = additionalLightColor;
+	return mainLightColor + additionalLightColor;
 }
 
 VertexOutput vert(appdata v) {
@@ -57,7 +68,11 @@ VertexOutput vert(appdata v) {
 	normalWS *= faceSign;
 #endif
 
-	color.rgb = LightweightLightVertexSimplified(positionWS, normalWS);
+	half3 shadowedColor;
+	color.rgb = LightweightLightVertexSimplified(positionWS, normalWS, shadowedColor);
+#if defined(SKELETONLIT_RECEIVE_SHADOWS)
+	o.shadowedColor = shadowedColor;
+#endif
 
 	// Note: ambient light is also handled via SH.
 	half3 vertexSH;
@@ -67,6 +82,13 @@ VertexOutput vert(appdata v) {
 	o.color = color;
 	o.uv0 = v.uv0;
 	o.pos = TransformWorldToHClip(positionWS);
+
+#if defined(SKELETONLIT_RECEIVE_SHADOWS)
+	VertexPositionInputs vertexInput;
+	vertexInput.positionWS = positionWS;
+	vertexInput.positionCS = o.pos;
+	o.shadowCoord = GetShadowCoord(vertexInput);
+#endif
 	return o;
 }
 
@@ -74,12 +96,18 @@ half4 frag(VertexOutput i) : SV_Target{
 	half4 tex = tex2D(_MainTex, i.uv0);
 	half4 col;
 
+#if defined(SKELETONLIT_RECEIVE_SHADOWS)
+	half shadowAttenuation = MainLightRealtimeShadow(i.shadowCoord);
+	i.color.rgb = lerp(i.shadowedColor, i.color.rgb, shadowAttenuation);
+#endif
+
 	#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;
 }

+ 15 - 5
spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-SkeletonLit-ShadowCasterPass-LW.hlsl

@@ -22,11 +22,9 @@ struct VaryingsSpine
 	float4 texcoordAndAlpha: TEXCOORD0;
 };
 
-float4 GetShadowPositionHClip(AttributesSpine input)
+float4 GetShadowPositionHClip(float3 positionOS, half3 normalWS)
 {
-	float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
-	float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
-
+	float3 positionWS = TransformObjectToWorld(positionOS);
 	float4 positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, _LightDirection));
 
 #if UNITY_REVERSED_Z
@@ -44,7 +42,19 @@ VaryingsSpine ShadowPassVertexSkeletonLit(AttributesSpine input)
 	UNITY_SETUP_INSTANCE_ID(input);
 
 	output.texcoordAndAlpha.xyz = float3(TRANSFORM_TEX(input.texcoord, _MainTex).xy, 0);
-	output.positionCS = GetShadowPositionHClip(input);
+
+	half3 fixedNormalOS = half3(0, 0, -1);
+	half3 normalWS = normalize(TransformObjectToWorldNormal(fixedNormalOS));
+#ifdef _DOUBLE_SIDED_LIGHTING
+	// flip normal for shadow bias if necessary
+	// unfortunately we have to compute the sign here in the vertex shader
+	// instead of using VFACE in fragment shader stage.
+	half3 viewDirWS = UNITY_MATRIX_V[2].xyz;
+	half faceSign = sign(dot(viewDirWS, normalWS));
+	normalWS *= faceSign;
+#endif
+
+	output.positionCS = GetShadowPositionHClip(input.positionOS.xyz, normalWS);
 	output.texcoordAndAlpha.a = input.vertexColor.a;
 	return output;
 }

+ 13 - 5
spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-Sprite-ShadowCasterPass-LW.hlsl

@@ -21,11 +21,9 @@ struct VaryingsSpine
 	float4 texcoordAndAlpha: TEXCOORD0;
 };
 
-float4 GetShadowPositionHClip(AttributesSpine input)
+float4 GetShadowPositionHClip(float3 positionOS, half3 normalWS)
 {
-	float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
-	float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
-
+	float3 positionWS = TransformObjectToWorld(positionOS);
 	float4 positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, _LightDirection));
 
 #if UNITY_REVERSED_Z
@@ -43,7 +41,17 @@ VaryingsSpine ShadowPassVertexSprite(AttributesSpine input)
 	UNITY_SETUP_INSTANCE_ID(input);
 
 	output.texcoordAndAlpha.xyz = float3(TRANSFORM_TEX(input.texcoord, _MainTex).xy, 0);
-	output.positionCS = GetShadowPositionHClip(input);
+
+	half3 fixedNormalOS = half3(0, 0, -1);
+	half3 normalWS = normalize(TransformObjectToWorldNormal(fixedNormalOS));
+	// flip normal for shadow bias if necessary
+	// unfortunately we have to compute the sign here in the vertex shader
+	// instead of using VFACE in fragment shader stage.
+	half3 viewDirWS = UNITY_MATRIX_V[2].xyz;
+	half faceSign = sign(dot(viewDirWS, normalWS));
+	normalWS *= faceSign;
+
+	output.positionCS = GetShadowPositionHClip(input.positionOS.xyz, normalWS);
 	output.texcoordAndAlpha.a = input.vertexColor.a * _Color.a;
 	return output;
 }

+ 3 - 0
spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-SkeletonLit-LW.shader

@@ -7,6 +7,7 @@ Shader "Lightweight Render Pipeline/Spine/Skeleton Lit" {
 		_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
+		[Toggle(_RECEIVE_SHADOWS)] _ReceiveShadows("Receive Shadows", Int) = 0
 		[Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0
 		[HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
 		[Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Compare", Float) = 0.0 // Disabled stencil test by default
@@ -62,6 +63,7 @@ Shader "Lightweight Render Pipeline/Spine/Skeleton Lit" {
 			// Spine related keywords
 			#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
 			#pragma shader_feature _ _DOUBLE_SIDED_LIGHTING
+			#pragma shader_feature _RECEIVE_SHADOWS_OFF _RECEIVE_SHADOWS
 			#pragma vertex vert
 			#pragma fragment frag
 			#pragma target 2.0
@@ -100,6 +102,7 @@ Shader "Lightweight Render Pipeline/Spine/Skeleton Lit" {
 			// GPU Instancing
 			#pragma multi_compile_instancing
 			#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
+			#pragma shader_feature _ _DOUBLE_SIDED_LIGHTING
 
 			#pragma vertex ShadowPassVertexSkeletonLit
 			#pragma fragment ShadowPassFragmentSkeletonLit

+ 34 - 6
spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-SkeletonLit-ForwardPass-URP.hlsl

@@ -5,6 +5,10 @@
 #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
 #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
 
+#if (defined(_MAIN_LIGHT_SHADOWS) || defined(MAIN_LIGHT_CALCULATE_SHADOWS)) && !defined(_RECEIVE_SHADOWS_OFF)
+#define SKELETONLIT_RECEIVE_SHADOWS
+#endif
+
 struct appdata {
 	float3 pos : POSITION;
 	float3 normal : NORMAL;
@@ -18,25 +22,32 @@ struct VertexOutput {
 	half4 color : COLOR0;
 	float2 uv0 : TEXCOORD0;
 	float4 pos : SV_POSITION;
+
+#if defined(SKELETONLIT_RECEIVE_SHADOWS)
+	float4 shadowCoord : TEXCOORD1;
+	half3 shadowedColor : TEXCOORD2;
+#endif
+
 	UNITY_VERTEX_OUTPUT_STEREO
 };
 
-half3 LightweightLightVertexSimplified(float3 positionWS, half3 normalWS) {
+half3 LightweightLightVertexSimplified(float3 positionWS, half3 normalWS, out half3 shadowedColor) {
 	Light mainLight = GetMainLight();
-
 	half3 attenuatedLightColor = mainLight.color * (mainLight.distanceAttenuation * mainLight.shadowAttenuation);
-	half3 diffuseLightColor = LightingLambert(attenuatedLightColor, mainLight.direction, normalWS);
+	half3 mainLightColor = LightingLambert(attenuatedLightColor, mainLight.direction, normalWS);
 
+	half3 additionalLightColor = half3(0, 0, 0);
 	// Note: we don't add any lighting in the fragment shader, thus we include both variants below
 #if defined(_ADDITIONAL_LIGHTS) || defined(_ADDITIONAL_LIGHTS_VERTEX)
 	for (int i = 0; i < GetAdditionalLightsCount(); ++i)
 	{
 		Light light = GetAdditionalLight(i, positionWS);
 		half3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation);
-		diffuseLightColor += LightingLambert(attenuatedLightColor, light.direction, normalWS);
+		additionalLightColor += LightingLambert(attenuatedLightColor, light.direction, normalWS);
 	}
 #endif
-	return diffuseLightColor;
+	shadowedColor = additionalLightColor;
+	return mainLightColor + additionalLightColor;
 }
 
 VertexOutput vert(appdata v) {
@@ -57,7 +68,11 @@ VertexOutput vert(appdata v) {
 	normalWS *= faceSign;
 #endif
 
-	color.rgb = LightweightLightVertexSimplified(positionWS, normalWS);
+	half3 shadowedColor;
+	color.rgb = LightweightLightVertexSimplified(positionWS, normalWS, shadowedColor);
+#if defined(SKELETONLIT_RECEIVE_SHADOWS)
+	o.shadowedColor = shadowedColor;
+#endif
 
 	// Note: ambient light is also handled via SH.
 	half3 vertexSH;
@@ -67,6 +82,13 @@ VertexOutput vert(appdata v) {
 	o.color = color;
 	o.uv0 = v.uv0;
 	o.pos = TransformWorldToHClip(positionWS);
+
+#if defined(SKELETONLIT_RECEIVE_SHADOWS)
+	VertexPositionInputs vertexInput;
+	vertexInput.positionWS = positionWS;
+	vertexInput.positionCS = o.pos;
+	o.shadowCoord = GetShadowCoord(vertexInput);
+#endif
 	return o;
 }
 
@@ -74,12 +96,18 @@ half4 frag(VertexOutput i) : SV_Target{
 	half4 tex = tex2D(_MainTex, i.uv0);
 	half4 col;
 
+#if defined(SKELETONLIT_RECEIVE_SHADOWS)
+	half shadowAttenuation = MainLightRealtimeShadow(i.shadowCoord);
+	i.color.rgb = lerp(i.shadowedColor, i.color.rgb, shadowAttenuation);
+#endif
+
 	#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;
 }

+ 15 - 5
spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-SkeletonLit-ShadowCasterPass-URP.hlsl

@@ -22,11 +22,9 @@ struct VaryingsSpine
 	float4 texcoordAndAlpha: TEXCOORD0;
 };
 
-float4 GetShadowPositionHClip(AttributesSpine input)
+float4 GetShadowPositionHClip(float3 positionOS, half3 normalWS)
 {
-	float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
-	float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
-
+	float3 positionWS = TransformObjectToWorld(positionOS);
 	float4 positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, _LightDirection));
 
 #if UNITY_REVERSED_Z
@@ -44,7 +42,19 @@ VaryingsSpine ShadowPassVertexSkeletonLit(AttributesSpine input)
 	UNITY_SETUP_INSTANCE_ID(input);
 
 	output.texcoordAndAlpha.xyz = float3(TRANSFORM_TEX(input.texcoord, _MainTex).xy, 0);
-	output.positionCS = GetShadowPositionHClip(input);
+
+	half3 fixedNormalOS = half3(0, 0, -1);
+	half3 normalWS = normalize(TransformObjectToWorldNormal(fixedNormalOS));
+#ifdef _DOUBLE_SIDED_LIGHTING
+	// flip normal for shadow bias if necessary
+	// unfortunately we have to compute the sign here in the vertex shader
+	// instead of using VFACE in fragment shader stage.
+	half3 viewDirWS = UNITY_MATRIX_V[2].xyz;
+	half faceSign = sign(dot(viewDirWS, normalWS));
+	normalWS *= faceSign;
+#endif
+
+	output.positionCS = GetShadowPositionHClip(input.positionOS.xyz, normalWS);
 	output.texcoordAndAlpha.a = input.vertexColor.a;
 	return output;
 }

+ 13 - 5
spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ShadowCasterPass-URP.hlsl

@@ -21,11 +21,9 @@ struct VaryingsSpine
 	float4 texcoordAndAlpha: TEXCOORD0;
 };
 
-float4 GetShadowPositionHClip(AttributesSpine input)
+float4 GetShadowPositionHClip(float3 positionOS, half3 normalWS)
 {
-	float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
-	float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
-
+	float3 positionWS = TransformObjectToWorld(positionOS);
 	float4 positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, _LightDirection));
 
 #if UNITY_REVERSED_Z
@@ -43,7 +41,17 @@ VaryingsSpine ShadowPassVertexSprite(AttributesSpine input)
 	UNITY_SETUP_INSTANCE_ID(input);
 
 	output.texcoordAndAlpha.xyz = float3(TRANSFORM_TEX(input.texcoord, _MainTex).xy, 0);
-	output.positionCS = GetShadowPositionHClip(input);
+
+	half3 fixedNormalOS = half3(0, 0, -1);
+	half3 normalWS = normalize(TransformObjectToWorldNormal(fixedNormalOS));
+	// flip normal for shadow bias if necessary
+	// unfortunately we have to compute the sign here in the vertex shader
+	// instead of using VFACE in fragment shader stage.
+	half3 viewDirWS = UNITY_MATRIX_V[2].xyz;
+	half faceSign = sign(dot(viewDirWS, normalWS));
+	normalWS *= faceSign;
+
+	output.positionCS = GetShadowPositionHClip(input.positionOS.xyz, normalWS);
 	output.texcoordAndAlpha.a = input.vertexColor.a * _Color.a;
 	return output;
 }

+ 3 - 0
spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Spine-SkeletonLit-URP.shader

@@ -3,6 +3,7 @@
 		_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
+		[Toggle(_RECEIVE_SHADOWS)] _ReceiveShadows("Receive Shadows", Int) = 0
 		[Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0
 		[HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
 		[Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Compare", Float) = 0.0 // Disabled stencil test by default
@@ -57,6 +58,7 @@
 			// Spine related keywords
 			#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
 			#pragma shader_feature _ _DOUBLE_SIDED_LIGHTING
+			#pragma shader_feature _RECEIVE_SHADOWS_OFF _RECEIVE_SHADOWS
 			#pragma vertex vert
 			#pragma fragment frag
 
@@ -94,6 +96,7 @@
 			// GPU Instancing
 			#pragma multi_compile_instancing
 			#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
+			#pragma shader_feature _ _DOUBLE_SIDED_LIGHTING
 
 			#pragma vertex ShadowPassVertexSkeletonLit
 			#pragma fragment ShadowPassFragmentSkeletonLit