From 36bc5eb9e8ff12882346f7b4335b27e8ea2243ee Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Wed, 12 Feb 2025 17:49:35 +0100 Subject: [PATCH] [unity] Added support for Unity 6 Adaptive Probe Volumes at URP Skeleton Lit shader. Closes #2750. --- CHANGELOG.md | 1 + .../Spine-SkeletonLit-ForwardPass-URP.hlsl | 41 ++++++++++++++++++- .../Shaders/Spine-SkeletonLit-URP.shader | 5 +++ .../package.json | 2 +- 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94c5f291a..5649cd239 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -167,6 +167,7 @@ - URP Shaders: Added `ZWrite` variant of outline shader `Universal Render Pipeline/Spine/Outline/Skeleton-OutlineOnly ZWrite`. Suitable for e.g. depth of field (DoF) effect where writing to the depth buffer is required. Note that for DoF effect, `Render Queue` needs to be set to `Alpha Test`. - SkeletonGraphic: Exposed `SetScaledPivotOffset` as public method outside of the editor to support programatically moving mesh offsets at runtime based on mesh bounds. - SkeletonMecanim: Added `Scene Preview` option to preview an Animation Clip for e.g. easier event placement. When enabled, the Animation Clip selected in the Animation window is previewed in the Scene and Game views. Lock the `SkeletonMecanim` Inspector window, open the Animation window and select the Animation Clip. Then in the Animation window scrub through the timeline to see the current animation frame previewed. + - `Universal Render Pipeline/Spine/Skeleton Lit` shader now supports [Adaptive Probe Volumes (APV)](https://docs.unity3d.com/6000.0/Documentation/Manual/urp/probevolumes-concept.html) introduced in Unity 6. The shader also provides a new material property `APV per Pixel` to either calculate APV lighting contribution per pixel (the default) or per vertex. - **Breaking changes** diff --git a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-SkeletonLit-ForwardPass-URP.hlsl b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-SkeletonLit-ForwardPass-URP.hlsl index f1f5551aa..8368d66b0 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-SkeletonLit-ForwardPass-URP.hlsl +++ b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-SkeletonLit-ForwardPass-URP.hlsl @@ -12,6 +12,10 @@ #define SKELETONLIT_RECEIVE_SHADOWS #endif +#if !defined(DYNAMICLIGHTMAP_ON) && !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)) +#define USE_ADAPTIVE_PROBE_VOLUMES +#endif + struct appdata { float3 pos : POSITION; float3 normal : NORMAL; @@ -39,6 +43,9 @@ struct VertexOutput { #endif #if defined(_TINT_BLACK_ON) float3 darkColor : TEXCOORD5; +#endif +#if defined(USE_ADAPTIVE_PROBE_VOLUMES) && defined(_ADAPTIVE_PROBE_VOLUMES_PER_PIXEL) + float3 positionCS : TEXCOORD6; #endif UNITY_VERTEX_OUTPUT_STEREO }; @@ -147,10 +154,10 @@ VertexOutput vert(appdata v) { // Note: ambient light is also handled via SH. half3 vertexSH; + float4 ignoredProbeOcclusion; #if IS_URP_15_OR_NEWER #ifdef OUTPUT_SH4 #if IS_URP_17_OR_NEWER - float4 ignoredProbeOcclusion; OUTPUT_SH4(positionWS, normalWS.xyz, GetWorldSpaceNormalizeViewDir(positionWS), vertexSH, ignoredProbeOcclusion); #else // 15 or newer OUTPUT_SH4(positionWS, normalWS.xyz, GetWorldSpaceNormalizeViewDir(positionWS), vertexSH); @@ -161,7 +168,24 @@ VertexOutput vert(appdata v) { #else OUTPUT_SH(normalWS.xyz, vertexSH); #endif + +#if defined(USE_ADAPTIVE_PROBE_VOLUMES) + #if !defined(_ADAPTIVE_PROBE_VOLUMES_PER_PIXEL) + half4 shadowMask = 1.0; + half3 bakedGI = SAMPLE_GI(vertexSH, + GetAbsolutePositionWS(positionWS), + normalWS.xyz, + GetWorldSpaceNormalizeViewDir(positionWS), + o.pos.xy, + ignoredProbeOcclusion, + shadowMask); + #else // _ADAPTIVE_PROBE_VOLUMES_PER_PIXEL + half3 bakedGI = half3(0.0, 0.0, 0.0); + o.positionCS = o.pos; + #endif +#else half3 bakedGI = SAMPLE_GI(v.lightmapUV, vertexSH, normalWS); +#endif color.rgb += bakedGI; o.color = color; @@ -188,6 +212,21 @@ half4 frag(VertexOutput i tex.rgb *= tex.a; #endif +#if defined(USE_ADAPTIVE_PROBE_VOLUMES) && defined(_ADAPTIVE_PROBE_VOLUMES_PER_PIXEL) + half3 vertexSH; + float4 ignoredProbeOcclusion; + OUTPUT_SH4(i.positionWS, i.normalWS.xyz, GetWorldSpaceNormalizeViewDir(i.positionWS), vertexSH, ignoredProbeOcclusion); + half4 shadowMask = 1.0; + half3 bakedGI = SAMPLE_GI(vertexSH, + GetAbsolutePositionWS(i.positionWS), + i.normalWS.xyz, + GetWorldSpaceNormalizeViewDir(i.positionWS), + i.positionCS.xy, + ignoredProbeOcclusion, + shadowMask); + i.color.rgb += bakedGI; +#endif + if (i.color.a == 0) { #if defined(_TINT_BLACK_ON) return fragTintedColor(tex, i.darkColor, i.color, _Color.a, _Black.a); diff --git a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Spine-SkeletonLit-URP.shader b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Spine-SkeletonLit-URP.shader index f043c1f03..9fa6a60b5 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Spine-SkeletonLit-URP.shader +++ b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Spine-SkeletonLit-URP.shader @@ -10,6 +10,7 @@ Shader "Universal Render Pipeline/Spine/Skeleton Lit" { [MaterialToggle(_TINT_BLACK_ON)] _TintBlack("Tint Black", Float) = 0 _Color(" Light Color", Color) = (1,1,1,1) _Black(" Dark Color", Color) = (0,0,0,0) + [MaterialToggle(_ADAPTIVE_PROBE_VOLUMES_PER_PIXEL)] _AdaptiveProbeVolumesPerPixel("APV per Pixel", Float) = 1 [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0 [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Compare", Float) = 8 // Set to Always as default } @@ -56,6 +57,10 @@ Shader "Universal Render Pipeline/Spine/Skeleton Lit" { #pragma multi_compile_fragment _ _LIGHT_LAYERS #pragma multi_compile _ _FORWARD_PLUS #pragma multi_compile_fragment _ _WRITE_RENDERING_LAYERS + #pragma multi_compile _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 + #if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2) + #pragma multi_compile _ _ADAPTIVE_PROBE_VOLUMES_PER_PIXEL + #endif // ------------------------------------- // Unity defined keywords 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 b0bc4f29c..0b480222d 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.2.\n(See http://esotericsoftware.com/git/spine-runtimes/spine-unity)", - "version": "4.2.39", + "version": "4.2.40", "unity": "2019.3", "author": { "name": "Esoteric Software",