今天搜索spine优化,看到一篇文章项目导入多个Spine动画 合批 降低DrawCall -- UWA问答 | 游戏开发者互动问答社区 | 侑虎科技
提供了新思路,打算尝试一下URP。但美术使用的spine版本是3.8,项目用的Unity2021.3.11f1c2,直接导入spine URP包,shader报错:half4 不能转成 SurfaceData2D;遂改下并记录:
Spine-SkeletonLit-URP-2D.shader
#include "Packages/com.unity.render-
pipelines.universal/Shaders/2D/Include/CombinedShapeLightShared.hlsl"
half4 CombinedShapeLightFragment(Varyings i) : SV_Target
{
half4 tex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
half4 main;
#if defined(_STRAIGHT_ALPHA_INPUT)
main.rgb = tex.rgb * i.color.rgb * tex.a;
#else
main.rgb = tex.rgb * i.color.rgb;
#endif
main.a = tex.a * i.color.a;
half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, i.uv);
return CombinedShapeLightShared(main, mask, i.lightingUV);
}
修改后:
文章来源:https://www.toymoban.com/news/detail-518331.html
#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/CombinedShapeLightShared.hlsl"
half4 CombinedShapeLightFragment(Varyings i) : SV_Target
{
half4 tex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
half4 main;
#if defined(_STRAIGHT_ALPHA_INPUT)
main.rgb = tex.rgb * i.color.rgb * tex.a;
#else
main.rgb = tex.rgb * i.color.rgb;
#endif
main.a = tex.a * i.color.a;
half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, i.uv);
#if UNITY_VERSION < 202120
return half4(CombinedShapeLightShared(half4(main.rgb, 1), mask, i.lightingUV).rgb, main.a);
#else
SurfaceData2D surfaceData;
InputData2D inputData;
surfaceData.albedo = main.rgb;
surfaceData.alpha = 1;
surfaceData.mask = mask;
inputData.uv = i.uv;
inputData.lightingUV = i.lightingUV;
return half4(CombinedShapeLightShared(surfaceData, inputData).rgb, main.a);
#endif
//return CombinedShapeLightShared(main, mask, i.lightingUV);
}
Spine-Sprite-StandardPass-URP-2D.hlsl 也报这个错,也是同样的改法即可文章来源地址https://www.toymoban.com/news/detail-518331.html
到了这里,关于Unity Spine 3.8 (URP) 踩坑(Shader报错修改)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!