From b64942b25793b7f6e763b0544a65731392a401bb Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Tue, 14 Feb 2023 19:40:00 +0100 Subject: [PATCH] [unity] Fixed URP 2D shaders ignoring texture alpha at Additive light blend style. Closes #2250. --- .../Include/Spine-Sprite-StandardPass-URP-2D.hlsl | 5 +++-- .../Shaders/2D/Spine-SkeletonLit-URP-2D.shader | 15 +++++++++------ .../package.json | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) 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 9556108c5..a3c41e5de 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 @@ -92,8 +92,9 @@ half4 CombinedShapeLightFragment(VertexOutputSpriteURP2D input) : SV_Target half4 main = texureColor * input.vertexColor; half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, input.texcoord.xy); + main.rgb = main.a == 0 ? main.rgb : main.rgb / main.a; // un-premultiply for additive lights in CombinedShapeLightShared, reapply afterwards #if UNITY_VERSION < 202120 - half4 pixel = half4(CombinedShapeLightShared(half4(main.rgb, 1), mask, input.lightingUV).rgb, main.a); + half4 pixel = half4(CombinedShapeLightShared(half4(main.rgb, 1), mask, input.lightingUV).rgb * main.a, main.a); #else SurfaceData2D surfaceData; InputData2D inputData; @@ -102,7 +103,7 @@ half4 CombinedShapeLightFragment(VertexOutputSpriteURP2D input) : SV_Target surfaceData.mask = mask; inputData.uv = input.texcoord; inputData.lightingUV = input.lightingUV; - half4 pixel = half4(CombinedShapeLightShared(surfaceData, inputData).rgb, main.a); + half4 pixel = half4(CombinedShapeLightShared(surfaceData, inputData).rgb * main.a, main.a); #endif #if defined(_RIM_LIGHTING) diff --git a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/2D/Spine-SkeletonLit-URP-2D.shader b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/2D/Spine-SkeletonLit-URP-2D.shader index d6731c66a..551e64c62 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/2D/Spine-SkeletonLit-URP-2D.shader +++ b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/2D/Spine-SkeletonLit-URP-2D.shader @@ -94,6 +94,8 @@ float4 clipVertex = o.positionCS / o.positionCS.w; o.lightingUV = ComputeScreenPos(clipVertex).xy; o.color = PMAGammaToTargetSpace(v.color); + // un-premultiply for additive lights in CombinedShapeLightShared, reapply afterwards + o.color.rgb = o.color.a == 0 ? o.color.rgb : o.color.rgb / o.color.a; return o; } @@ -102,18 +104,19 @@ half4 CombinedShapeLightFragment(Varyings i) : SV_Target { half4 tex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv); - #if defined(_STRAIGHT_ALPHA_INPUT) - tex.rgb *= tex.a; - #endif + #if !defined(_STRAIGHT_ALPHA_INPUT) + // un-premultiply for additive lights in CombinedShapeLightShared, reapply afterwards + tex.rgb = tex.a == 0 ? tex.rgb : tex.rgb / tex.a; + #endif half4 main = tex * i.color; #if !defined(_LIGHT_AFFECTS_ADDITIVE) if (i.color.a == 0) - return main; + return half4(main.rgb * main.a, main.a); #endif half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, i.uv); #if UNITY_VERSION < 202120 - return half4(CombinedShapeLightShared(half4(main.rgb, 1), mask, i.lightingUV).rgb, main.a); + return half4(CombinedShapeLightShared(half4(main.rgb, 1), mask, i.lightingUV).rgb * main.a, main.a); #else SurfaceData2D surfaceData; InputData2D inputData; @@ -122,7 +125,7 @@ surfaceData.mask = mask; inputData.uv = i.uv; inputData.lightingUV = i.lightingUV; - return half4(CombinedShapeLightShared(surfaceData, inputData).rgb, main.a); + return half4(CombinedShapeLightShared(surfaceData, inputData).rgb * main.a, main.a); #endif } 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 c4fd437dd..869671a6c 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.7", + "version": "4.1.8", "unity": "2019.3", "author": { "name": "Esoteric Software",