fairygui / FairyGUI-unity

A flexible UI framework for Unity
https://fairygui.com
MIT License
2.68k stars 636 forks source link

在URP中fairyGUI不能开启SRP Batcher的优化 #212

Open lumieru opened 1 year ago

lumieru commented 1 year ago

有好几个shader显示不是SRP Batcher compatible的,具体如下: FairyGUI-TMP: Material property is found in another cbuffer than "UnityPerMaterial" (_FaceUVSpeedX) FairyGUI-Image: UnityPerMaterial var is not declared in shader property section (_ClipBox) FairyGUI-Text: UnityPerMaterial var is not declared in shader property section(_ClipBox)

SunHowe commented 7 months ago

可根据提示自行修改。改动原则:

  1. cbuffer包含的字段需要暴露在Properties下
  2. cbuffer包含的字段不允许使用宏定义声明(会破坏数据布局)

例如FariyGUI-Image的改动:

Properties
{
     // ....
     // 省略原本就声明的属性

     _ClipBox ("ClipBox", Vector) = (-2, -2, 0, 0)
     _ClipSoftness ("ClipSoftness", Vector) = (0, 0, 0, 0)
}

SubShader
{
    // 下面将CLIPPED和SOFTCLIPPED的宏定义去除,直接声明这两个字段,vert函数内的宏定义保留
    CBUFFER_START(UnityPerMaterial)
    // #ifdef CLIPPED
    // float4 _ClipBox = float4(-2, -2, 0, 0);
    // #endif

    // #ifdef SOFT_CLIPPED
    float4 _ClipBox = float4(-2, -2, 0, 0);
    float4 _ClipSoftness = float4(0, 0, 0, 0);
    // #endif
    CBUFFER_END
}
xiaoguzhu commented 7 months ago

我们不支持SPR Batcher的,开启了会导致渲染错误。

SunHowe commented 7 months ago

我们不支持SPR Batcher的,开启了会导致渲染错误。

哦哦 好的