Declare DOTS Instancing properties in a custom shader in URP
Declare a DOTS Instancing property block in custom shader code.
読み終わるまでの所要時間 2 分最終更新 1ヶ月前
To load instance data, such as transform matrices, the shader needs to define DOTS Instanced properties. Below is an example of a simple DOTS Instanced property block:
UNITY_DOTS_INSTANCING_START(MaterialPropertyMetadata) UNITY_DOTS_INSTANCED_PROP(float4, Color)UNITY_DOTS_INSTANCING_END(MaterialPropertyMetadata)
To mark the beginning and end of the property block, use the and macros followed by the name of the block. The example uses the name . There are three allowed block names:
UNITY_DOTS_INSTANCING_STARTUNITY_DOTS_INSTANCING_ENDMaterialPropertyMetadata- BuiltinPropertyMetadata
- MaterialPropertyMetadata
- UserPropertyMetadata
The shader can declare one of each, so a DOTS Instanced shader can have between zero and three of such blocks. Unity-defined shader code doesn't use UserPropertyMetadata so this name is guaranteed to be free for you to use. URP and HDRP define BuiltinPropertyMetadata for every shader they provide and define MaterialPropertyMetadata for most of them too, so it's best practice to use UserPropertyMetadata. Your custom shaders can use all three possible names, even all at once.
The block can contain any number of DOTS Instanced property definitions formatted like:
UNITY_DOTS_INSTANCED_PROP(PropertyType, PropertyName)
PropertyTypePropertyNameUNITY_DOTS_INSTANCED_PROPInternally, Unity provides the shader with a 32-bit integer metadata value for every DOTS Instanced property the shader declares. Unity sets the metadata value when your code makes a BatchRendererGroup.AddBatch call to create the batch associated with the draw. The metadata value defaults to if Unity doesn't set it. The shader also has access to which Unity sets to the GraphicsBuffer you pass as an argument to . This buffer is typically where the shader loads the instance data from. Multiple batches can share a single GraphicsBuffer, but it is also possible for each batch to use its own separate GraphicsBuffer for .
0ByteAddressBuffer unity_DOTSInstanceDataBatchRendererGroup.AddBatchunity_DOTSInstanceData