소스 검색

[unity] Fixed URP lit shaders ignoring straight alpha settings during fallback to unlit. Affected SkeletonRenderTexture. Closes #2044.

Harald Csaszar 3 년 전
부모
커밋
5a32e002b8

+ 47 - 0
spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/2D/Include/Spine-SkeletonLit-UnlitPass-URP-2D.hlsl

@@ -0,0 +1,47 @@
+#ifndef SKELETONLIT_UNLIT_PASS_INCLUDED
+#define SKELETONLIT_UNLIT_PASS_INCLUDED
+
+struct Attributes
+{
+	float3 positionOS   : POSITION;
+	float4 color		: COLOR;
+	float2 uv			: TEXCOORD0;
+};
+
+struct Varyings
+{
+	float4  positionCS		: SV_POSITION;
+	float4  color			: COLOR;
+	float2	uv				: TEXCOORD0;
+};
+
+TEXTURE2D(_MainTex);
+SAMPLER(sampler_MainTex);
+float4 _MainTex_ST;
+
+Varyings UnlitVertex(Attributes attributes)
+{
+	Varyings o = (Varyings)0;
+
+	o.positionCS = TransformObjectToHClip(attributes.positionOS);
+	o.uv = TRANSFORM_TEX(attributes.uv, _MainTex);
+	o.uv = attributes.uv;
+	o.color = attributes.color;
+	return o;
+}
+
+float4 UnlitFragment(Varyings i) : SV_Target
+{
+	half4 tex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
+	half4 main;
+	#if defined(_STRAIGHT_ALPHA_INPUT)
+	main.rgb = tex.rgb * i.color.rgb * tex.a;
+	#else
+	main.rgb = tex.rgb * i.color.rgb;
+	#endif
+	main.a = tex.a * i.color.a;
+
+	return main;
+}
+
+#endif

+ 10 - 0
spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/2D/Include/Spine-SkeletonLit-UnlitPass-URP-2D.hlsl.meta

@@ -0,0 +1,10 @@
+fileFormatVersion: 2
+guid: 580dd7e812fc63c4a9330abe519946de
+ShaderImporter:
+  externalObjects: {}
+  defaultTextures: []
+  nonModifiableTextures: []
+  preprocessorOverride: 0
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 2 - 42
spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/2D/Spine-SkeletonLit-URP-2D.shader

@@ -193,52 +193,12 @@
 			Blend One OneMinusSrcAlpha
 
 			HLSLPROGRAM
+			#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
 			#pragma prefer_hlslcc gles
 			#pragma vertex UnlitVertex
 			#pragma fragment UnlitFragment
 
-			struct Attributes
-			{
-				float3 positionOS   : POSITION;
-				float4 color		: COLOR;
-				float2 uv			: TEXCOORD0;
-			};
-
-			struct Varyings
-			{
-				float4  positionCS		: SV_POSITION;
-				float4  color			: COLOR;
-				float2	uv				: TEXCOORD0;
-			};
-
-			TEXTURE2D(_MainTex);
-			SAMPLER(sampler_MainTex);
-			float4 _MainTex_ST;
-
-			Varyings UnlitVertex(Attributes attributes)
-			{
-				Varyings o = (Varyings)0;
-
-				o.positionCS = TransformObjectToHClip(attributes.positionOS);
-				o.uv = TRANSFORM_TEX(attributes.uv, _MainTex);
-				o.uv = attributes.uv;
-				o.color = attributes.color;
-				return o;
-			}
-
-			float4 UnlitFragment(Varyings i) : SV_Target
-			{
-				half4 tex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
-				half4 main;
-				#if defined(_STRAIGHT_ALPHA_INPUT)
-				main.rgb = tex.rgb * i.color.rgb * tex.a;
-				#else
-				main.rgb = tex.rgb * i.color.rgb;
-				#endif
-				main.a = tex.a * i.color.a;
-
-				return main;
-			}
+			#include "Include/Spine-SkeletonLit-UnlitPass-URP-2D.hlsl"
 			ENDHLSL
 		}
 	}

+ 22 - 1
spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/2D/Spine-Sprite-URP-2D.shader

@@ -147,7 +147,28 @@ Shader "Universal Render Pipeline/2D/Spine/Sprite"
 			ENDHLSL
 		}
 
-		UsePass "Universal Render Pipeline/2D/Spine/Skeleton Lit/UNLIT"
+		Pass
+		{
+			Name "Unlit"
+			Tags { "LightMode" = "UniversalForward" "Queue" = "Transparent" "RenderType" = "Transparent"}
+
+			ZWrite Off
+			Cull Off
+			Blend One OneMinusSrcAlpha
+
+			HLSLPROGRAM
+			#pragma shader_feature _ _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON _ALPHAPREMULTIPLY_VERTEX_ONLY _ADDITIVEBLEND _ADDITIVEBLEND_SOFT _MULTIPLYBLEND _MULTIPLYBLEND_X2
+			#if defined(_ALPHAPREMULTIPLY_VERTEX_ONLY) || defined(_ALPHABLEND_ON)
+			#define _STRAIGHT_ALPHA_INPUT
+			#endif
+
+			#pragma prefer_hlslcc gles
+			#pragma vertex UnlitVertex
+			#pragma fragment UnlitFragment
+
+			#include "Include/Spine-SkeletonLit-UnlitPass-URP-2D.hlsl"
+			ENDHLSL
+		}
 	}
 
 	FallBack "Universal Render Pipeline/2D/Spine/Skeleton Lit"

+ 31 - 1
spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Spine-Sprite-URP.shader

@@ -113,7 +113,7 @@ Shader "Universal Render Pipeline/Spine/Sprite"
 			#pragma multi_compile _ DIRLIGHTMAP_COMBINED
 			#pragma multi_compile _ LIGHTMAP_ON
 
-	//--------------------------------------
+			//--------------------------------------
 			// GPU Instancing
 			#pragma multi_compile_instancing
 
@@ -202,6 +202,36 @@ Shader "Universal Render Pipeline/Spine/Sprite"
 			#include "Include/Spine-Sprite-DepthOnlyPass-URP.hlsl"
 			ENDHLSL
 		}
+
+		Pass
+		{
+			Name "Unlit"
+			Tags { "LightMode" = "UniversalForward" "Queue" = "Transparent" "RenderType" = "Transparent"}
+
+			ZWrite Off
+			Cull Off
+			Blend One OneMinusSrcAlpha
+
+			HLSLPROGRAM
+			#pragma shader_feature _ _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON _ALPHAPREMULTIPLY_VERTEX_ONLY _ADDITIVEBLEND _ADDITIVEBLEND_SOFT _MULTIPLYBLEND _MULTIPLYBLEND_X2
+			#if defined(_ALPHAPREMULTIPLY_VERTEX_ONLY) || defined(_ALPHABLEND_ON)
+			#define _STRAIGHT_ALPHA_INPUT
+			#endif
+
+			#pragma prefer_hlslcc gles
+			#pragma vertex vert
+			#pragma fragment frag
+
+			#undef LIGHTMAP_ON
+
+			#define USE_URP
+			#define fixed4 half4
+			#define fixed3 half3
+			#define fixed half
+			#include "Include/Spine-Input-URP.hlsl"
+			#include "Include/Spine-Skeleton-ForwardPass-URP.hlsl"
+			ENDHLSL
+		}
 	}
 
 	FallBack "Hidden/InternalErrorShader"