diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common.cginc b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common.cginc index 9dc1709d4..73a6e1875 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common.cginc +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common.cginc @@ -83,7 +83,13 @@ VertexOutput vert (appdata v) { float3 eyePos = UnityObjectToViewPos(float4(v.pos, 1)).xyz; //mul(UNITY_MATRIX_MV, float4(v.pos,1)).xyz; half3 fixedNormal = half3(0,0,-1); half3 eyeNormal = normalize(mul((float3x3)UNITY_MATRIX_IT_MV, fixedNormal)); - //half3 eyeNormal = half3(0,0,1); + +#ifdef _DOUBLE_SIDED_LIGHTING + // unfortunately we have to compute the sign here in the vertex shader + // instead of using VFACE in fragment shader stage. + half faceSign = sign(eyeNormal.z); + eyeNormal *= faceSign; +#endif // Lights half3 lcolor = half4(0,0,0,1).rgb + color.rgb * glstate_lightmodel_ambient.rgb; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Outline/Spine-Skeleton-Lit-Outline.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Outline/Spine-Skeleton-Lit-Outline.shader index 411036fee..75c0a9f5a 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Outline/Spine-Skeleton-Lit-Outline.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Outline/Spine-Skeleton-Lit-Outline.shader @@ -5,6 +5,7 @@ Shader "Spine/Outline/Skeleton Lit" { _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 + [Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0 [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0 [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Outline/Spine-Skeleton-Lit-ZWrite-Outline.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Outline/Spine-Skeleton-Lit-ZWrite-Outline.shader index 4cdf0e7c7..044308562 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Outline/Spine-Skeleton-Lit-ZWrite-Outline.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Outline/Spine-Skeleton-Lit-ZWrite-Outline.shader @@ -6,6 +6,7 @@ Shader "Spine/Outline/Skeleton Lit ZWrite" { _ShadowAlphaCutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 + [Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0 [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0 [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit-ZWrite.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit-ZWrite.shader index c8f43fd3d..95f77b77f 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit-ZWrite.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit-ZWrite.shader @@ -8,6 +8,7 @@ Shader "Spine/Skeleton Lit ZWrite" { _ShadowAlphaCutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 + [Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0 [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0 [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default @@ -42,6 +43,7 @@ Shader "Spine/Skeleton Lit ZWrite" { CGPROGRAM #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT + #pragma shader_feature _ _DOUBLE_SIDED_LIGHTING #pragma vertex vert #pragma fragment frag #pragma target 2.0 diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit.shader index b2e90b031..f10c478fa 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit.shader @@ -7,6 +7,7 @@ Shader "Spine/Skeleton Lit" { _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 + [Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0 [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0 [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default @@ -41,6 +42,7 @@ Shader "Spine/Skeleton Lit" { CGPROGRAM #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT + #pragma shader_feature _ _DOUBLE_SIDED_LIGHTING #pragma vertex vert #pragma fragment frag #pragma target 2.0 diff --git a/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-SkeletonLit-ForwardPass-LW.hlsl b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-SkeletonLit-ForwardPass-LW.hlsl index 53e958fd9..b6b54affb 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-SkeletonLit-ForwardPass-LW.hlsl +++ b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-SkeletonLit-ForwardPass-LW.hlsl @@ -6,7 +6,7 @@ struct appdata { float3 normal : NORMAL; half4 color : COLOR; float2 uv0 : TEXCOORD0; - + UNITY_VERTEX_INPUT_INSTANCE_ID }; @@ -44,6 +44,15 @@ VertexOutput vert(appdata v) { float3 positionWS = TransformObjectToWorld(v.pos); half3 fixedNormal = half3(0, 0, -1); half3 normalWS = normalize(mul((float3x3)unity_ObjectToWorld, fixedNormal)); + +#ifdef _DOUBLE_SIDED_LIGHTING + // unfortunately we have to compute the sign here in the vertex shader + // instead of using VFACE in fragment shader stage. + half3 viewDirWS = UNITY_MATRIX_V[2].xyz; + half faceSign = sign(dot(viewDirWS, normalWS)); + normalWS *= faceSign; +#endif + color.rgb = LightweightLightVertexSimplified(positionWS, normalWS); // Note: ambient light is also handled via SH. diff --git a/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-SkeletonLit-LW.shader b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-SkeletonLit-LW.shader index 14ab34d7b..f03856a19 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-SkeletonLit-LW.shader +++ b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-SkeletonLit-LW.shader @@ -7,6 +7,7 @@ Shader "Lightweight Render Pipeline/Spine/Skeleton Lit" { _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 + [Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0 [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0 [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Compare", Float) = 0.0 // Disabled stencil test by default } @@ -19,7 +20,7 @@ Shader "Lightweight Render Pipeline/Spine/Skeleton Lit" { Cull Off ZWrite Off Blend One OneMinusSrcAlpha - + Stencil { Ref[_StencilRef] Comp[_StencilComp] @@ -48,7 +49,7 @@ Shader "Lightweight Render Pipeline/Spine/Skeleton Lit" { #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS #pragma multi_compile _ _SHADOWS_SOFT #pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE - + // ------------------------------------- // Unity defined keywords #pragma multi_compile_fog @@ -60,6 +61,7 @@ Shader "Lightweight Render Pipeline/Spine/Skeleton Lit" { //-------------------------------------- // Spine related keywords #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT + #pragma shader_feature _ _DOUBLE_SIDED_LIGHTING #pragma vertex vert #pragma fragment frag #pragma target 2.0 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 f0fa20e1b..0fd0c788c 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 @@ -44,6 +44,15 @@ VertexOutput vert(appdata v) { float3 positionWS = TransformObjectToWorld(v.pos); half3 fixedNormal = half3(0, 0, -1); half3 normalWS = normalize(mul((float3x3)unity_ObjectToWorld, fixedNormal)); + +#ifdef _DOUBLE_SIDED_LIGHTING + // unfortunately we have to compute the sign here in the vertex shader + // instead of using VFACE in fragment shader stage. + half3 viewDirWS = UNITY_MATRIX_V[2].xyz; + half faceSign = sign(dot(viewDirWS, normalWS)); + normalWS *= faceSign; +#endif + color.rgb = LightweightLightVertexSimplified(positionWS, normalWS); // Note: ambient light is also handled via SH. 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 166c8d2b5..f8328d65d 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 @@ -3,6 +3,7 @@ _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 + [Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0 [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0 [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Compare", Float) = 0.0 // Disabled stencil test by default } @@ -55,6 +56,7 @@ //-------------------------------------- // Spine related keywords #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT + #pragma shader_feature _ _DOUBLE_SIDED_LIGHTING #pragma vertex vert #pragma fragment frag