Access DOTS Instancing properties in a custom shader
Use built-in macros to access DOTS Instancing properties in custom shader code.
읽는 시간 1분최근 업데이트: 한 달 전
To access DOTS Instanced properties, your shader can use one of the access macros that Unity provides. The access macros assume that instance data in uses the following layout:
unity_DOTSInstanceData- The 31 least significant bits of the metadata value contain the byte address of the first instance in the batch within the buffer.
unity_DOTSInstanceData - If the most significant bit of the metadata value is , every instance uses the value from instance index zero. This means each instance loads directly from the byte address in the metadata value. In this case, the buffer only needs to store a single value, instead of one value per instance.
0 - If the most significant bit of the metadata value is , the address should contain an array where you can find the value for instance index
1usinginstanceID. In this case, you should ensure that every rendered instance index has valid data in buffer. Otherwise, out-of-bounds access and undefined behavior can occur.AddressOfInstance0 + sizeof(PropertyType) * instanceID
You can also set the the metadata value directly which is useful if you want to use a custom data source that doesn't use the above layout, such as a texture.
For an example of how to use these macros, see Access macro example.