mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[unity] Fixed incorrect normal orientation for lighting in URP 2D shaders. Closes #2023. Fixed compile error of URP/2D/Spine/Sprite shader on Unity 2021.2. Closes #2022.
This commit is contained in:
parent
0407bd8302
commit
8a30203ab9
@ -51,16 +51,15 @@ half4 NormalsRenderingFragment(Varyings i) : SV_Target
|
|||||||
half4 mainTex = i.color * tex2D(_MainTex, i.uv);
|
half4 mainTex = i.color * tex2D(_MainTex, i.uv);
|
||||||
|
|
||||||
#if defined(_NORMALMAP)
|
#if defined(_NORMALMAP)
|
||||||
half3 normalWS = calculateNormalFromBumpMap(i.uv.xy, i.tangentWS.xyz, i.bitangentWS.xyz, i.normalWS.xyz);
|
half3 normalTS = normalize(UnpackScaleNormal(tex2D(_BumpMap, i.uv.xy), _BumpScale));
|
||||||
|
return NormalsRenderingShared(mainTex, normalTS, i.tangentWS.xyz, i.bitangentWS.xyz, i.normalWS.xyz);
|
||||||
#else
|
#else
|
||||||
|
half3 normalTS = half3(0, 0, 1);
|
||||||
|
half3 tangentWS = half3(0, 0, 0);
|
||||||
|
half3 bitangentWS = half3(0, 0, 0);
|
||||||
half3 normalWS = i.normalWS.xyz;
|
half3 normalWS = i.normalWS.xyz;
|
||||||
|
return NormalsRenderingShared(mainTex, normalTS, tangentWS, bitangentWS, normalWS);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
half3 normalVS = TransformWorldToViewDir(normalWS);
|
|
||||||
float4 normalColor;
|
|
||||||
normalColor.rgb = 0.5 * ((normalVS) + 1);
|
|
||||||
normalColor.a = mainTex.a;
|
|
||||||
return normalColor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -92,7 +92,18 @@ half4 CombinedShapeLightFragment(VertexOutputSpriteURP2D input) : SV_Target
|
|||||||
half4 main = texureColor * input.vertexColor;
|
half4 main = texureColor * input.vertexColor;
|
||||||
|
|
||||||
half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, input.texcoord.xy);
|
half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, input.texcoord.xy);
|
||||||
|
#if UNITY_VERSION < 202120
|
||||||
half4 pixel = half4(CombinedShapeLightShared(half4(main.rgb, 1), mask, input.lightingUV).rgb, main.a);
|
half4 pixel = half4(CombinedShapeLightShared(half4(main.rgb, 1), mask, input.lightingUV).rgb, main.a);
|
||||||
|
#else
|
||||||
|
SurfaceData2D surfaceData;
|
||||||
|
InputData2D inputData;
|
||||||
|
surfaceData.albedo = main.rgb;
|
||||||
|
surfaceData.alpha = 1;
|
||||||
|
surfaceData.mask = mask;
|
||||||
|
inputData.uv = input.texcoord;
|
||||||
|
inputData.lightingUV = input.lightingUV;
|
||||||
|
half4 pixel = half4(CombinedShapeLightShared(surfaceData, inputData).rgb, main.a);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(_RIM_LIGHTING)
|
#if defined(_RIM_LIGHTING)
|
||||||
#if defined(_NORMALMAP)
|
#if defined(_NORMALMAP)
|
||||||
|
|||||||
@ -153,7 +153,7 @@
|
|||||||
float4 positionCS : SV_POSITION;
|
float4 positionCS : SV_POSITION;
|
||||||
float4 color : COLOR;
|
float4 color : COLOR;
|
||||||
float2 uv : TEXCOORD0;
|
float2 uv : TEXCOORD0;
|
||||||
float3 normalVS : TEXCOORD1;
|
float3 normalWS : TEXCOORD1;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEXTURE2D(_MainTex);
|
TEXTURE2D(_MainTex);
|
||||||
@ -166,8 +166,7 @@
|
|||||||
o.positionCS = TransformObjectToHClip(attributes.positionOS);
|
o.positionCS = TransformObjectToHClip(attributes.positionOS);
|
||||||
o.uv = attributes.uv;
|
o.uv = attributes.uv;
|
||||||
o.color = attributes.color;
|
o.color = attributes.color;
|
||||||
float3 normalWS = TransformObjectToWorldDir(float3(0, 0, -1));
|
o.normalWS = TransformObjectToWorldDir(float3(0, 0, -1));
|
||||||
o.normalVS = TransformWorldToViewDir(normalWS);
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,11 +175,10 @@
|
|||||||
float4 NormalsRenderingFragment(Varyings i) : SV_Target
|
float4 NormalsRenderingFragment(Varyings i) : SV_Target
|
||||||
{
|
{
|
||||||
float4 mainTex = i.color * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
|
float4 mainTex = i.color * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
|
||||||
|
half3 normalTS = half3(0, 0, 1);
|
||||||
float4 normalColor;
|
half3 tangentWS = half3(0, 0, 0);
|
||||||
normalColor.rgb = 0.5 * ((i.normalVS)+1);
|
half3 bitangentWS = half3(0, 0, 0);
|
||||||
normalColor.a = mainTex.a;
|
return NormalsRenderingShared(mainTex, normalTS, tangentWS, bitangentWS, i.normalWS);
|
||||||
return normalColor;
|
|
||||||
}
|
}
|
||||||
ENDHLSL
|
ENDHLSL
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user