Version: Unity 6.1 Alpha (6000.1)
Language : English
DOTS Instancing shader examples in URP
Example of a DOTS Instancing shader that accesses constant data in URP

Example of a DOTS Instancing shader that accesses per-instance data in URP

In this example:

  • The metadata value for Color is 0x80001000.
  • The instance index is 5.
  • Data for instance 0 starts at address 0x1000.
  • Data for instance 5 is at address 0x1000 + 5 * sizeof(float4) = 0x1050

Because the most significant bit is already set, the accessor macros don’t load defaults. This means that c0, c1, and c2 will all have the same value, loaded from unity_DOTSInstanceData address 0x1050.

void ExamplePerInstance()
{
    // rawMetadataValue will contain 0x80001000
    uint rawMetadataValue = UNITY_DOTS_INSTANCED_METADATA_NAME(float4, Color);

    float4 c0 = UNITY_ACCESS_DOTS_INSTANCED_PROP(float4, Color);
    float4 c1 = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4, Color);
    float4 c2 = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_CUSTOM_DEFAULT(float4, Color, float4(1, 2, 3, 4));
}
DOTS Instancing shader examples in URP
Example of a DOTS Instancing shader that accesses constant data in URP
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961