Example of a DOTS Instancing shader that accesses constant data in URP
An example of accessing constant color data in a DOTS Instancing shader.
읽는 시간 1분최근 업데이트: 한 달 전
In this example:
- The metadata value for is
Color.0x00001000 - The instance index is .
5 - Data for instance 0 starts at address 0x1000.
- The most significant bit is not set so data for instance 5 is at the same address as instance 0.
Because the most significant bit is not set, the accessor macros that fall back to defaults don't access . This means that:
unity_DOTSInstanceData- will contain the value from
c0addressunity_DOTSInstanceData.0x1000 - will contain the value of the regular material property Color, and cause a compile error if the Color property doesn't exist.
c1 - will contain
c2because that was passed as the explicit default value.(1, 2, 3, 4)
void ExampleConstant(){ // rawMetadataValue will contain 0x00001000 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));}