[unity] Fixed "Universal Render Pipeline/Spine/Skeleton Lit" shader ignoring fog. Closes #2959.

This commit is contained in:
Harald Csaszar 2025-10-23 11:19:30 +02:00
parent 990ff34747
commit 49abbdc458
2 changed files with 31 additions and 6 deletions

View File

@ -16,6 +16,10 @@
#define USE_ADAPTIVE_PROBE_VOLUMES
#endif
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
#define _FOG
#endif
struct appdata {
float3 pos : POSITION;
float3 normal : NORMAL;
@ -30,7 +34,11 @@ struct appdata {
struct VertexOutput {
half4 color : COLOR0;
#if defined(_FOG)
float3 uv0AndFog : TEXCOORD0;
#else
float2 uv0 : TEXCOORD0;
#endif
float4 pos : SV_POSITION;
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
@ -50,6 +58,13 @@ struct VertexOutput {
UNITY_VERTEX_OUTPUT_STEREO
};
#if defined(_FOG)
#define PackedUV0(i) i.uv0AndFog.xy
#define PackedFog(i) i.uv0AndFog.z
#else
#define PackedUV0(i) i.uv0.xy
#endif
half3 ProcessLight(float3 positionWS, half3 normalWS, uint meshRenderingLayers, int lightIndex)
{
Light light = GetAdditionalLight(lightIndex, positionWS);
@ -116,8 +131,13 @@ VertexOutput vert(appdata v) {
float3 positionWS = TransformObjectToWorld(v.pos);
half3 fixedNormal = half3(0, 0, -1);
half3 normalWS = normalize(mul((float3x3)unity_ObjectToWorld, fixedNormal));
o.uv0 = v.uv0;
o.pos = TransformWorldToHClip(positionWS);
#if defined(_FOG)
half fogFactor = ComputeFogFactor(o.pos.z);
PackedFog(o) = fogFactor;
#endif
PackedUV0(o) = v.uv0;
#ifdef _DOUBLE_SIDED_LIGHTING
// unfortunately we have to compute the sign here in the vertex shader
@ -207,7 +227,7 @@ half4 frag(VertexOutput i
#endif
) : SV_Target0
{
half4 tex = tex2D(_MainTex, i.uv0);
half4 tex = tex2D(_MainTex, PackedUV0(i));
#if !defined(_TINT_BLACK_ON) && defined(_STRAIGHT_ALPHA_INPUT)
tex.rgb *= tex.a;
#endif
@ -256,10 +276,15 @@ half4 frag(VertexOutput i
#endif
#if defined(_TINT_BLACK_ON)
return fragTintedColor(tex, i.darkColor, i.color, _Color.a, _Black.a);
half4 pixel = fragTintedColor(tex, i.darkColor, i.color, _Color.a, _Black.a);
#else
return tex * i.color;
half4 pixel = tex * i.color;
#endif
#if defined(_FOG)
pixel.rgb = MixFogColor(pixel.rgb, unity_FogColor.rgb * pixel.a, PackedFog(i));
#endif
return pixel;
}
#endif

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.47",
"version": "4.2.48",
"unity": "2019.3",
"author": {
"name": "Esoteric Software",