Эх сурвалжийг харах

[unity] Fixed single pass additive slot blend mode for all URP and LWRP shaders (2D and 3D). Closes #1850.

Harald Csaszar 4 жил өмнө
parent
commit
c5c71747c3

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

@@ -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
-
-	#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;
+	return tex * i.color;
 }
 }
 
 
+
 #endif
 #endif

+ 4 - 0
spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-Sprite-ForwardPass-LW.hlsl

@@ -213,6 +213,10 @@ half4 ForwardPassFragmentSprite(VertexOutputLWRP input) : SV_Target
 
 
 	fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
 	fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
 	ALPHA_CLIP(texureColor, input.vertexColor)
 	ALPHA_CLIP(texureColor, input.vertexColor)
+#if !defined(_MULTIPLYBLEND) && !defined(_MULTIPLYBLEND_X2)
+	if (input.vertexColor.a == 0)
+		return texureColor * input.vertexColor;
+#endif
 
 
 	// fill out InputData struct
 	// fill out InputData struct
 	InputData inputData;
 	InputData inputData;

+ 4 - 0
spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/2D/Include/Spine-Sprite-StandardPass-URP-2D.hlsl

@@ -89,6 +89,10 @@ half4 CombinedShapeLightFragment(VertexOutputSpriteURP2D input) : SV_Target
 	fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
 	fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
 	ALPHA_CLIP(texureColor, input.vertexColor)
 	ALPHA_CLIP(texureColor, input.vertexColor)
 	texureColor *= input.vertexColor;
 	texureColor *= input.vertexColor;
+#if !defined(_MULTIPLYBLEND) && !defined(_MULTIPLYBLEND_X2)
+	if (input.vertexColor.a == 0)
+		return texureColor;
+#endif
 
 
 	half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, input.texcoord.xy);
 	half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, input.texcoord.xy);
 	half4 pixel = CombinedShapeLightShared(texureColor, mask, input.lightingUV);
 	half4 pixel = CombinedShapeLightShared(texureColor, mask, input.lightingUV);

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

@@ -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;
-				#else
-				main.rgb = tex.rgb * i.color.rgb;
+				tex.rgb *= tex.a;
 				#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);

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

@@ -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
-
-	#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;
+	return tex * i.color;
 }
 }
 
 
 #endif
 #endif

+ 4 - 0
spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl

@@ -223,6 +223,10 @@ half4 ForwardPassFragmentSprite(VertexOutputLWRP input) : SV_Target
 
 
 	fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
 	fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
 	ALPHA_CLIP(texureColor, input.vertexColor)
 	ALPHA_CLIP(texureColor, input.vertexColor)
+#if !defined(_MULTIPLYBLEND) && !defined(_MULTIPLYBLEND_X2)
+	if (input.vertexColor.a == 0)
+		return texureColor * input.vertexColor;
+#endif
 
 
 	// fill out InputData struct
 	// fill out InputData struct
 	InputData inputData;
 	InputData inputData;