[unity] Added support for Unity 6 Adaptive Probe Volumes at URP Skeleton Lit shader. Closes #2750.

This commit is contained in:
Harald Csaszar 2025-02-12 17:49:35 +01:00
parent 1cdbf9be1a
commit 36bc5eb9e8
4 changed files with 47 additions and 2 deletions

View File

@ -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**

View File

@ -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);

View File

@ -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

View File

@ -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",