From 1979b03df249f11d367aed73f26af34f6f585ab8 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Thu, 1 Jun 2023 17:35:11 +0200 Subject: [PATCH 1/2] [unity] URP shaders: Fixed more shader compile errors at some project configurations. --- .../Shaders/Include/Spine-Common-URP.hlsl | 13 +++++++++++++ .../Include/Spine-SkeletonLit-ForwardPass-URP.hlsl | 2 +- .../Include/Spine-Sprite-ForwardPass-URP.hlsl | 12 ++++++------ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Common-URP.hlsl b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Common-URP.hlsl index a56e218ea..66b2fc9a1 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Common-URP.hlsl +++ b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Common-URP.hlsl @@ -43,6 +43,19 @@ uint GetMeshRenderingLayerBackwardsCompatible() } #endif +// copy of an older version of InputData before additional members were added in more recent URP versions. +struct InputDataBackwardsCompatible { + float3 positionWS; + half3 normalWS; + half3 viewDirectionWS; + float4 shadowCoord; + //half fogCoord; + half3 vertexLighting; + half3 bakedGI; + float2 normalizedScreenSpaceUV; + half4 shadowMask; +}; + #if USE_FORWARD_PLUS // note: LIGHT_LOOP_BEGIN accesses inputData.normalizedScreenSpaceUV and inputData.positionWS. #define LIGHT_LOOP_BEGIN_SPINE LIGHT_LOOP_BEGIN 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 560259251..2f3bc80ca 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 @@ -87,7 +87,7 @@ half3 LightweightLightFragmentSimplified(float3 positionWS, float2 positionCS, h half3 additionalLightColor = half3(0, 0, 0); shadowedColor = half3(0, 0, 0); - InputData inputData; // LIGHT_LOOP_BEGIN macro requires InputData struct in USE_FORWARD_PLUS branch + InputDataBackwardsCompatible inputData; // LIGHT_LOOP_BEGIN macro requires InputData struct in USE_FORWARD_PLUS branch inputData.positionWS = positionWS; inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(positionCS); diff --git a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl index c835aa00e..627afbd55 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl +++ b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl @@ -56,7 +56,7 @@ struct VertexOutputLWRP // Vertex and Fragment functions // /////////////////////////////////////////////////////////////////////////////// #if defined(_ADDITIONAL_LIGHT_SHADOWS) && !defined(_RECEIVE_SHADOWS_OFF) -half4 CalculateShadowMaskBackwardsCompatible(InputData inputData) +half4 CalculateShadowMaskBackwardsCompatible(InputDataBackwardsCompatible inputData) { // To ensure backward compatibility we have to avoid using shadowMask input, as it is not present in older shaders #if defined(SHADOWS_SHADOWMASK) && defined(LIGHTMAP_ON) @@ -102,7 +102,7 @@ half3 LightingLambertRamped(half3 lightColor, float attenuation, half3 lightDir, #if defined(SPECULAR) -half3 ProcessLightPBRSimplified(InputData inputData, BRDFData brdfData, half4 shadowMask, uint meshRenderingLayers, int lightIndex) +half3 ProcessLightPBRSimplified(InputDataBackwardsCompatible inputData, BRDFData brdfData, half4 shadowMask, uint meshRenderingLayers, int lightIndex) { #if defined(_ADDITIONAL_LIGHT_SHADOWS) && !defined(_RECEIVE_SHADOWS_OFF) Light light = GetAdditionalLight(lightIndex, inputData.positionWS, shadowMask); @@ -116,7 +116,7 @@ half3 ProcessLightPBRSimplified(InputData inputData, BRDFData brdfData, half4 sh return LightingPhysicallyBased(brdfData, light, inputData.normalWS, inputData.viewDirectionWS); } -half4 LightweightFragmentPBRSimplified(InputData inputData, half4 texAlbedoAlpha, half metallic, half3 specular, +half4 LightweightFragmentPBRSimplified(InputDataBackwardsCompatible inputData, half4 texAlbedoAlpha, half metallic, half3 specular, half smoothness, half3 emission, half4 vertexColor) { #if !defined(_TINT_BLACK_ON) @@ -179,7 +179,7 @@ half4 LightweightFragmentPBRSimplified(InputData inputData, half4 texAlbedoAlpha #else // !SPECULAR -half3 ProcessLightLambert(InputData inputData, half4 shadowMask, uint meshRenderingLayers, int lightIndex) +half3 ProcessLightLambert(InputDataBackwardsCompatible inputData, half4 shadowMask, uint meshRenderingLayers, int lightIndex) { #if defined(_ADDITIONAL_LIGHT_SHADOWS) && !defined(_RECEIVE_SHADOWS_OFF) Light light = GetAdditionalLight(lightIndex, inputData.positionWS, shadowMask); @@ -201,7 +201,7 @@ half3 ProcessLightLambert(InputData inputData, half4 shadowMask, uint meshRender #endif } -half4 LightweightFragmentBlinnPhongSimplified(InputData inputData, half4 texDiffuseAlpha, half3 emission, half4 vertexColor) +half4 LightweightFragmentBlinnPhongSimplified(InputDataBackwardsCompatible inputData, half4 texDiffuseAlpha, half3 emission, half4 vertexColor) { #if !defined(_TINT_BLACK_ON) half4 diffuse = texDiffuseAlpha * vertexColor; @@ -334,7 +334,7 @@ half4 ForwardPassFragmentSprite(VertexOutputLWRP input #endif // fill out InputData struct - InputData inputData; + InputDataBackwardsCompatible inputData; #if !defined(_RECEIVE_SHADOWS_OFF) #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) inputData.shadowCoord = input.shadowCoord; From ea1f8021d947b0a3c741cd98eee539a86d7b0ac9 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Thu, 1 Jun 2023 18:09:33 +0200 Subject: [PATCH 2/2] [unity] URP shaders: Improvement of previous commit 1979b03, was unnecessary. Fixed final shader compile errors. --- .../Shaders/Include/Spine-Common-URP.hlsl | 13 ------------- .../Spine-SkeletonLit-ForwardPass-URP.hlsl | 2 +- .../Include/Spine-Sprite-ForwardPass-URP.hlsl | 16 ++++++++-------- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Common-URP.hlsl b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Common-URP.hlsl index 66b2fc9a1..a56e218ea 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Common-URP.hlsl +++ b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Common-URP.hlsl @@ -43,19 +43,6 @@ uint GetMeshRenderingLayerBackwardsCompatible() } #endif -// copy of an older version of InputData before additional members were added in more recent URP versions. -struct InputDataBackwardsCompatible { - float3 positionWS; - half3 normalWS; - half3 viewDirectionWS; - float4 shadowCoord; - //half fogCoord; - half3 vertexLighting; - half3 bakedGI; - float2 normalizedScreenSpaceUV; - half4 shadowMask; -}; - #if USE_FORWARD_PLUS // note: LIGHT_LOOP_BEGIN accesses inputData.normalizedScreenSpaceUV and inputData.positionWS. #define LIGHT_LOOP_BEGIN_SPINE LIGHT_LOOP_BEGIN 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 2f3bc80ca..560259251 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 @@ -87,7 +87,7 @@ half3 LightweightLightFragmentSimplified(float3 positionWS, float2 positionCS, h half3 additionalLightColor = half3(0, 0, 0); shadowedColor = half3(0, 0, 0); - InputDataBackwardsCompatible inputData; // LIGHT_LOOP_BEGIN macro requires InputData struct in USE_FORWARD_PLUS branch + InputData inputData; // LIGHT_LOOP_BEGIN macro requires InputData struct in USE_FORWARD_PLUS branch inputData.positionWS = positionWS; inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(positionCS); diff --git a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl index 627afbd55..df7b69dd6 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl +++ b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl @@ -14,7 +14,7 @@ #endif #include "SpineCoreShaders/Spine-Skeleton-Tint-Common.cginc" -#if defined(_RIM_LIGHTING) || defined(_ADDITIONAL_LIGHTS) || defined(MAIN_LIGHT_CALCULATE_SHADOWS) || defined(_LIGHT_COOKIES) +#if defined(_RIM_LIGHTING) || defined(_ADDITIONAL_LIGHTS) || defined(MAIN_LIGHT_CALCULATE_SHADOWS) || defined(USE_LIGHT_COOKIES) #define NEEDS_POSITION_WS #endif @@ -56,7 +56,7 @@ struct VertexOutputLWRP // Vertex and Fragment functions // /////////////////////////////////////////////////////////////////////////////// #if defined(_ADDITIONAL_LIGHT_SHADOWS) && !defined(_RECEIVE_SHADOWS_OFF) -half4 CalculateShadowMaskBackwardsCompatible(InputDataBackwardsCompatible inputData) +half4 CalculateShadowMaskBackwardsCompatible(InputData inputData) { // To ensure backward compatibility we have to avoid using shadowMask input, as it is not present in older shaders #if defined(SHADOWS_SHADOWMASK) && defined(LIGHTMAP_ON) @@ -102,7 +102,7 @@ half3 LightingLambertRamped(half3 lightColor, float attenuation, half3 lightDir, #if defined(SPECULAR) -half3 ProcessLightPBRSimplified(InputDataBackwardsCompatible inputData, BRDFData brdfData, half4 shadowMask, uint meshRenderingLayers, int lightIndex) +half3 ProcessLightPBRSimplified(InputData inputData, BRDFData brdfData, half4 shadowMask, uint meshRenderingLayers, int lightIndex) { #if defined(_ADDITIONAL_LIGHT_SHADOWS) && !defined(_RECEIVE_SHADOWS_OFF) Light light = GetAdditionalLight(lightIndex, inputData.positionWS, shadowMask); @@ -116,7 +116,7 @@ half3 ProcessLightPBRSimplified(InputDataBackwardsCompatible inputData, BRDFData return LightingPhysicallyBased(brdfData, light, inputData.normalWS, inputData.viewDirectionWS); } -half4 LightweightFragmentPBRSimplified(InputDataBackwardsCompatible inputData, half4 texAlbedoAlpha, half metallic, half3 specular, +half4 LightweightFragmentPBRSimplified(InputData inputData, half4 texAlbedoAlpha, half metallic, half3 specular, half smoothness, half3 emission, half4 vertexColor) { #if !defined(_TINT_BLACK_ON) @@ -179,7 +179,7 @@ half4 LightweightFragmentPBRSimplified(InputDataBackwardsCompatible inputData, h #else // !SPECULAR -half3 ProcessLightLambert(InputDataBackwardsCompatible inputData, half4 shadowMask, uint meshRenderingLayers, int lightIndex) +half3 ProcessLightLambert(InputData inputData, half4 shadowMask, uint meshRenderingLayers, int lightIndex) { #if defined(_ADDITIONAL_LIGHT_SHADOWS) && !defined(_RECEIVE_SHADOWS_OFF) Light light = GetAdditionalLight(lightIndex, inputData.positionWS, shadowMask); @@ -201,7 +201,7 @@ half3 ProcessLightLambert(InputDataBackwardsCompatible inputData, half4 shadowMa #endif } -half4 LightweightFragmentBlinnPhongSimplified(InputDataBackwardsCompatible inputData, half4 texDiffuseAlpha, half3 emission, half4 vertexColor) +half4 LightweightFragmentBlinnPhongSimplified(InputData inputData, half4 texDiffuseAlpha, half3 emission, half4 vertexColor) { #if !defined(_TINT_BLACK_ON) half4 diffuse = texDiffuseAlpha * vertexColor; @@ -334,7 +334,7 @@ half4 ForwardPassFragmentSprite(VertexOutputLWRP input #endif // fill out InputData struct - InputDataBackwardsCompatible inputData; + InputData inputData; #if !defined(_RECEIVE_SHADOWS_OFF) #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) inputData.shadowCoord = input.shadowCoord; @@ -358,7 +358,7 @@ half4 ForwardPassFragmentSprite(VertexOutputLWRP input inputData.normalWS = normalWS; inputData.bakedGI = SAMPLE_GI(input.lightmapUV, input.vertexSH, inputData.normalWS); -#if defined(_RIM_LIGHTING) || defined(_ADDITIONAL_LIGHTS) +#if defined(_RIM_LIGHTING) || defined(_ADDITIONAL_LIGHTS) || defined(USE_LIGHT_COOKIES) inputData.positionWS = input.positionWS.rgb; #endif #if defined(_ADDITIONAL_LIGHTS) && USE_FORWARD_PLUS