UnityInstancing.hlsl 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. #ifndef UNITY_INSTANCING_INCLUDED
  2. #define UNITY_INSTANCING_INCLUDED
  3. #if SHADER_TARGET >= 35 && (defined(SHADER_API_D3D11) || defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE) || defined(SHADER_API_XBOXONE) || defined(SHADER_API_PSSL) || defined(SHADER_API_VULKAN) || defined(SHADER_API_METAL))
  4. #define UNITY_SUPPORT_INSTANCING
  5. #endif
  6. #if defined(SHADER_API_SWITCH)
  7. #define UNITY_SUPPORT_INSTANCING
  8. #endif
  9. #if defined(SHADER_API_D3D11) || defined(SHADER_API_GLCORE) || defined(SHADER_API_GLES3) || defined(SHADER_API_VULKAN)
  10. #define UNITY_SUPPORT_STEREO_INSTANCING
  11. #endif
  12. // These platforms support dynamically adjusting the instancing CB size according to the current batch.
  13. #if defined(SHADER_API_D3D11) || defined(SHADER_API_GLCORE) || defined(SHADER_API_GLES3) || defined(SHADER_API_METAL) || defined(SHADER_API_PSSL) || defined(SHADER_API_VULKAN) || defined(SHADER_API_SWITCH)
  14. #define UNITY_INSTANCING_SUPPORT_FLEXIBLE_ARRAY_SIZE
  15. #endif
  16. #if defined(SHADER_TARGET_SURFACE_ANALYSIS) && defined(UNITY_SUPPORT_INSTANCING)
  17. #undef UNITY_SUPPORT_INSTANCING
  18. #endif
  19. ////////////////////////////////////////////////////////
  20. // instancing paths
  21. // - UNITY_INSTANCING_ENABLED Defined if instancing path is taken.
  22. // - UNITY_PROCEDURAL_INSTANCING_ENABLED Defined if procedural instancing path is taken.
  23. // - UNITY_STEREO_INSTANCING_ENABLED Defined if stereo instancing path is taken.
  24. // - UNITY_ANY_INSTANCING_ENABLED Defined if any instancing path is taken
  25. #if defined(UNITY_SUPPORT_INSTANCING) && defined(INSTANCING_ON)
  26. #define UNITY_INSTANCING_ENABLED
  27. #endif
  28. #if defined(UNITY_SUPPORT_INSTANCING) && defined(PROCEDURAL_INSTANCING_ON)
  29. #define UNITY_PROCEDURAL_INSTANCING_ENABLED
  30. #endif
  31. #if defined(UNITY_SUPPORT_STEREO_INSTANCING) && defined(STEREO_INSTANCING_ON)
  32. #define UNITY_STEREO_INSTANCING_ENABLED
  33. #endif
  34. #if defined(UNITY_INSTANCING_ENABLED) || defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) || defined(UNITY_STEREO_INSTANCING_ENABLED)
  35. #define UNITY_ANY_INSTANCING_ENABLED 1
  36. #else
  37. #define UNITY_ANY_INSTANCING_ENABLED 0
  38. #endif
  39. #if defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE) || defined(SHADER_API_METAL) || defined(SHADER_API_VULKAN)
  40. // These platforms have constant buffers disabled normally, but not here (see CBUFFER_START/CBUFFER_END in HLSLSupport.cginc).
  41. #define UNITY_INSTANCING_CBUFFER_SCOPE_BEGIN(name) cbuffer name {
  42. #define UNITY_INSTANCING_CBUFFER_SCOPE_END }
  43. #else
  44. #define UNITY_INSTANCING_CBUFFER_SCOPE_BEGIN(name) CBUFFER_START(name)
  45. #define UNITY_INSTANCING_CBUFFER_SCOPE_END CBUFFER_END
  46. #endif
  47. ////////////////////////////////////////////////////////
  48. // basic instancing setups
  49. // - UNITY_VERTEX_INPUT_INSTANCE_ID Declare instance ID field in vertex shader input / output struct.
  50. // - UNITY_GET_INSTANCE_ID (Internal) Get the instance ID from input struct.
  51. #if defined(UNITY_INSTANCING_ENABLED) || defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) || defined(UNITY_STEREO_INSTANCING_ENABLED)
  52. // A global instance ID variable that functions can directly access.
  53. static uint unity_InstanceID;
  54. // Don't make UnityDrawCallInfo an actual CB on GL
  55. #if !defined(SHADER_API_GLES3) && !defined(SHADER_API_GLCORE)
  56. UNITY_INSTANCING_CBUFFER_SCOPE_BEGIN(UnityDrawCallInfo)
  57. #endif
  58. int unity_BaseInstanceID;
  59. int unity_InstanceCount;
  60. #if !defined(SHADER_API_GLES3) && !defined(SHADER_API_GLCORE)
  61. UNITY_INSTANCING_CBUFFER_SCOPE_END
  62. #endif
  63. #ifdef SHADER_API_PSSL
  64. #define DEFAULT_UNITY_VERTEX_INPUT_INSTANCE_ID uint instanceID;
  65. #define UNITY_GET_INSTANCE_ID(input) _GETINSTANCEID(input)
  66. #else
  67. #define DEFAULT_UNITY_VERTEX_INPUT_INSTANCE_ID uint instanceID : SV_InstanceID;
  68. #define UNITY_GET_INSTANCE_ID(input) input.instanceID
  69. #endif
  70. #else
  71. #define DEFAULT_UNITY_VERTEX_INPUT_INSTANCE_ID
  72. #endif // UNITY_INSTANCING_ENABLED || UNITY_PROCEDURAL_INSTANCING_ENABLED || UNITY_STEREO_INSTANCING_ENABLED
  73. #if !defined(UNITY_VERTEX_INPUT_INSTANCE_ID)
  74. # define UNITY_VERTEX_INPUT_INSTANCE_ID DEFAULT_UNITY_VERTEX_INPUT_INSTANCE_ID
  75. #endif
  76. ////////////////////////////////////////////////////////
  77. // basic stereo instancing setups
  78. // - UNITY_VERTEX_OUTPUT_STEREO Declare stereo target eye field in vertex shader output struct.
  79. // - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO Assign the stereo target eye.
  80. // - UNITY_TRANSFER_VERTEX_OUTPUT_STEREO Copy stero target from input struct to output struct. Used in vertex shader.
  81. // - UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX
  82. #ifdef UNITY_STEREO_INSTANCING_ENABLED
  83. #if defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)
  84. #define DEFAULT_UNITY_VERTEX_OUTPUT_STEREO uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
  85. #define DEFAULT_UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output) output.stereoTargetEyeIndexAsRTArrayIdx = unity_StereoEyeIndex; output.stereoTargetEyeIndexAsBlendIdx0 = unity_StereoEyeIndex;
  86. #define DEFAULT_UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(input, output) output.stereoTargetEyeIndexAsBlendIdx0 = input.stereoTargetEyeIndexAsBlendIdx0;
  87. #define DEFAULT_UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input) unity_StereoEyeIndex = input.stereoTargetEyeIndexAsBlendIdx0;
  88. #elif defined(SHADER_API_PSSL) && defined(TESSELLATION_ON)
  89. // Use of SV_RenderTargetArrayIndex is a little more complicated if we have tessellation stages involved
  90. // This will add an extra instructions which we might be able to optimize away in some stages if we are careful.
  91. #if defined(SHADER_STAGE_VERTEX)
  92. #define DEFAULT_UNITY_VERTEX_OUTPUT_STEREO uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
  93. #define DEFAULT_UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output) output.stereoTargetEyeIndexAsBlendIdx0 = unity_StereoEyeIndex;
  94. #define DEFAULT_UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(input, output) output.stereoTargetEyeIndexAsBlendIdx0 = input.stereoTargetEyeIndexAsBlendIdx0;
  95. #define DEFAULT_UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input) unity_StereoEyeIndex = input.stereoTargetEyeIndexAsBlendIdx0;
  96. #else
  97. #define DEFAULT_UNITY_VERTEX_OUTPUT_STEREO uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
  98. #define DEFAULT_UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output) output.stereoTargetEyeIndexAsRTArrayIdx = unity_StereoEyeIndex; output.stereoTargetEyeIndexAsBlendIdx0 = unity_StereoEyeIndex;
  99. #define DEFAULT_UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(input, output) output.stereoTargetEyeIndexAsBlendIdx0 = input.stereoTargetEyeIndexAsBlendIdx0;
  100. #define DEFAULT_UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input) unity_StereoEyeIndex = input.stereoTargetEyeIndexAsBlendIdx0;
  101. #endif
  102. #else
  103. #define DEFAULT_UNITY_VERTEX_OUTPUT_STEREO uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex;
  104. #define DEFAULT_UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output) output.stereoTargetEyeIndexAsRTArrayIdx = unity_StereoEyeIndex
  105. #define DEFAULT_UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(input, output) output.stereoTargetEyeIndexAsRTArrayIdx = input.stereoTargetEyeIndexAsRTArrayIdx;
  106. #define DEFAULT_UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input) unity_StereoEyeIndex = input.stereoTargetEyeIndexAsRTArrayIdx;
  107. #endif
  108. #elif defined(UNITY_STEREO_MULTIVIEW_ENABLED)
  109. #define DEFAULT_UNITY_VERTEX_OUTPUT_STEREO float stereoTargetEyeIndexAsBlendIdx0 : BLENDWEIGHT0;
  110. // HACK: Workaround for Mali shader compiler issues with directly using GL_ViewID_OVR (GL_OVR_multiview). This array just contains the values 0 and 1.
  111. #define DEFAULT_UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output) output.stereoTargetEyeIndexAsBlendIdx0 = unity_StereoEyeIndices[unity_StereoEyeIndex].x;
  112. #define DEFAULT_UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(input, output) output.stereoTargetEyeIndexAsBlendIdx0 = input.stereoTargetEyeIndexAsBlendIdx0;
  113. #if defined(SHADER_STAGE_VERTEX)
  114. #define DEFAULT_UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input)
  115. #else
  116. #define DEFAULT_UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input) unity_StereoEyeIndex = (uint) input.stereoTargetEyeIndexAsBlendIdx0;
  117. #endif
  118. #else
  119. #define DEFAULT_UNITY_VERTEX_OUTPUT_STEREO
  120. #define DEFAULT_UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output)
  121. #define DEFAULT_UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(input, output)
  122. #define DEFAULT_UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input)
  123. #endif
  124. #if !defined(UNITY_VERTEX_OUTPUT_STEREO)
  125. # define UNITY_VERTEX_OUTPUT_STEREO DEFAULT_UNITY_VERTEX_OUTPUT_STEREO
  126. #endif
  127. #if !defined(UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO)
  128. # define UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output) DEFAULT_UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output)
  129. #endif
  130. #if !defined(UNITY_TRANSFER_VERTEX_OUTPUT_STEREO)
  131. # define UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(input, output) DEFAULT_UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(input, output)
  132. #endif
  133. #if !defined(UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX)
  134. # define UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input) DEFAULT_UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input)
  135. #endif
  136. ////////////////////////////////////////////////////////
  137. // - UNITY_SETUP_INSTANCE_ID Should be used at the very beginning of the vertex shader / fragment shader,
  138. // so that succeeding code can have access to the global unity_InstanceID.
  139. // Also procedural function is called to setup instance data.
  140. // - UNITY_TRANSFER_INSTANCE_ID Copy instance ID from input struct to output struct. Used in vertex shader.
  141. #if defined(UNITY_INSTANCING_ENABLED) || defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) || defined(UNITY_STEREO_INSTANCING_ENABLED)
  142. void UnitySetupInstanceID(uint inputInstanceID)
  143. {
  144. #ifdef UNITY_STEREO_INSTANCING_ENABLED
  145. #if !defined(SHADEROPTIONS_XR_MAX_VIEWS) || SHADEROPTIONS_XR_MAX_VIEWS <= 2
  146. #if defined(SHADER_API_GLES3)
  147. // We must calculate the stereo eye index differently for GLES3
  148. // because otherwise, the unity shader compiler will emit a bitfieldInsert function.
  149. // bitfieldInsert requires support for glsl version 400 or later. Therefore the
  150. // generated glsl code will fail to compile on lower end devices. By changing the
  151. // way we calculate the stereo eye index, we can help the shader compiler to avoid
  152. // emitting the bitfieldInsert function and thereby increase the number of devices we
  153. // can run stereo instancing on.
  154. unity_StereoEyeIndex = round(fmod(inputInstanceID, 2.0));
  155. unity_InstanceID = unity_BaseInstanceID + (inputInstanceID >> 1);
  156. #else
  157. // stereo eye index is automatically figured out from the instance ID
  158. unity_StereoEyeIndex = inputInstanceID & 0x01;
  159. unity_InstanceID = unity_BaseInstanceID + (inputInstanceID >> 1);
  160. #endif
  161. #else
  162. unity_StereoEyeIndex = inputInstanceID % _XRViewCount;
  163. unity_InstanceID = unity_BaseInstanceID + (inputInstanceID / _XRViewCount);
  164. #endif
  165. #else
  166. unity_InstanceID = inputInstanceID + unity_BaseInstanceID;
  167. #endif
  168. }
  169. #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
  170. #ifndef UNITY_INSTANCING_PROCEDURAL_FUNC
  171. #error "UNITY_INSTANCING_PROCEDURAL_FUNC must be defined."
  172. #else
  173. void UNITY_INSTANCING_PROCEDURAL_FUNC(); // forward declaration of the procedural function
  174. #define DEFAULT_UNITY_SETUP_INSTANCE_ID(input) { UnitySetupInstanceID(UNITY_GET_INSTANCE_ID(input)); UNITY_INSTANCING_PROCEDURAL_FUNC();}
  175. #endif
  176. #else
  177. #define DEFAULT_UNITY_SETUP_INSTANCE_ID(input) { UnitySetupInstanceID(UNITY_GET_INSTANCE_ID(input));}
  178. #endif
  179. #define UNITY_TRANSFER_INSTANCE_ID(input, output) output.instanceID = UNITY_GET_INSTANCE_ID(input)
  180. #else
  181. #define DEFAULT_UNITY_SETUP_INSTANCE_ID(input)
  182. #define UNITY_TRANSFER_INSTANCE_ID(input, output)
  183. #endif
  184. #if !defined(UNITY_SETUP_INSTANCE_ID)
  185. # define UNITY_SETUP_INSTANCE_ID(input) DEFAULT_UNITY_SETUP_INSTANCE_ID(input)
  186. #endif
  187. ////////////////////////////////////////////////////////
  188. // instanced property arrays
  189. #if defined(UNITY_INSTANCING_ENABLED)
  190. #ifdef UNITY_FORCE_MAX_INSTANCE_COUNT
  191. #define UNITY_INSTANCED_ARRAY_SIZE UNITY_FORCE_MAX_INSTANCE_COUNT
  192. #elif defined(UNITY_INSTANCING_SUPPORT_FLEXIBLE_ARRAY_SIZE)
  193. #define UNITY_INSTANCED_ARRAY_SIZE 2 // minimum array size that ensures dynamic indexing
  194. #elif defined(UNITY_MAX_INSTANCE_COUNT)
  195. #define UNITY_INSTANCED_ARRAY_SIZE UNITY_MAX_INSTANCE_COUNT
  196. #else
  197. #if (defined(SHADER_API_VULKAN) && defined(SHADER_API_MOBILE)) || defined(SHADER_API_SWITCH)
  198. #define UNITY_INSTANCED_ARRAY_SIZE 250
  199. #else
  200. #define UNITY_INSTANCED_ARRAY_SIZE 500
  201. #endif
  202. #endif
  203. #define UNITY_INSTANCING_BUFFER_START(buf) UNITY_INSTANCING_CBUFFER_SCOPE_BEGIN(UnityInstancing_##buf) struct {
  204. #define UNITY_INSTANCING_BUFFER_END(arr) } arr##Array[UNITY_INSTANCED_ARRAY_SIZE]; UNITY_INSTANCING_CBUFFER_SCOPE_END
  205. #define UNITY_DEFINE_INSTANCED_PROP(type, var) type var;
  206. #define UNITY_ACCESS_INSTANCED_PROP(arr, var) arr##Array[unity_InstanceID].var
  207. // Put worldToObject array to a separate CB if UNITY_ASSUME_UNIFORM_SCALING is defined. Most of the time it will not be used.
  208. #ifdef UNITY_ASSUME_UNIFORM_SCALING
  209. #define UNITY_WORLDTOOBJECTARRAY_CB 1
  210. #else
  211. #define UNITY_WORLDTOOBJECTARRAY_CB 0
  212. #endif
  213. #if defined(UNITY_INSTANCED_LOD_FADE) && (defined(LOD_FADE_PERCENTAGE) || defined(LOD_FADE_CROSSFADE))
  214. #define UNITY_USE_LODFADE_ARRAY
  215. #endif
  216. #if defined(UNITY_INSTANCED_RENDERING_LAYER)
  217. #define UNITY_USE_RENDERINGLAYER_ARRAY
  218. #endif
  219. #ifdef UNITY_INSTANCED_LIGHTMAPSTS
  220. #ifdef LIGHTMAP_ON
  221. #define UNITY_USE_LIGHTMAPST_ARRAY
  222. #endif
  223. #ifdef DYNAMICLIGHTMAP_ON
  224. #define UNITY_USE_DYNAMICLIGHTMAPST_ARRAY
  225. #endif
  226. #endif
  227. #if defined(UNITY_INSTANCED_SH) && !defined(LIGHTMAP_ON)
  228. #if !defined(DYNAMICLIGHTMAP_ON)
  229. #define UNITY_USE_SHCOEFFS_ARRAYS
  230. #endif
  231. #if defined(SHADOWS_SHADOWMASK)
  232. #define UNITY_USE_PROBESOCCLUSION_ARRAY
  233. #endif
  234. #endif
  235. UNITY_INSTANCING_BUFFER_START(PerDraw0)
  236. #ifndef UNITY_DONT_INSTANCE_OBJECT_MATRICES
  237. UNITY_DEFINE_INSTANCED_PROP(float4x4, unity_ObjectToWorldArray)
  238. #if UNITY_WORLDTOOBJECTARRAY_CB == 0
  239. UNITY_DEFINE_INSTANCED_PROP(float4x4, unity_WorldToObjectArray)
  240. #endif
  241. #endif
  242. #if defined(UNITY_USE_LODFADE_ARRAY) && defined(UNITY_INSTANCING_SUPPORT_FLEXIBLE_ARRAY_SIZE)
  243. UNITY_DEFINE_INSTANCED_PROP(float2, unity_LODFadeArray)
  244. #define unity_LODFade UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_LODFadeArray).xyxx
  245. #endif
  246. #if defined(UNITY_USE_RENDERINGLAYER_ARRAY) && defined(UNITY_INSTANCING_SUPPORT_FLEXIBLE_ARRAY_SIZE)
  247. UNITY_DEFINE_INSTANCED_PROP(float, unity_RenderingLayerArray)
  248. #define unity_RenderingLayer UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_RenderingLayerArray).xxxx
  249. #endif
  250. #if defined(SHADER_GRAPH_GENERATED)
  251. DOTS_CUSTOM_ADDITIONAL_MATERIAL_VARS
  252. #endif
  253. UNITY_INSTANCING_BUFFER_END(unity_Builtins0)
  254. UNITY_INSTANCING_BUFFER_START(PerDraw1)
  255. #if !defined(UNITY_DONT_INSTANCE_OBJECT_MATRICES) && UNITY_WORLDTOOBJECTARRAY_CB == 1
  256. UNITY_DEFINE_INSTANCED_PROP(float4x4, unity_WorldToObjectArray)
  257. #endif
  258. #if defined(UNITY_USE_LODFADE_ARRAY) && !defined(UNITY_INSTANCING_SUPPORT_FLEXIBLE_ARRAY_SIZE)
  259. UNITY_DEFINE_INSTANCED_PROP(float2, unity_LODFadeArray)
  260. #define unity_LODFade UNITY_ACCESS_INSTANCED_PROP(unity_Builtins1, unity_LODFadeArray).xyxx
  261. #endif
  262. #if defined(UNITY_USE_RENDERINGLAYER_ARRAY) && !defined(UNITY_INSTANCING_SUPPORT_FLEXIBLE_ARRAY_SIZE)
  263. UNITY_DEFINE_INSTANCED_PROP(float, unity_RenderingLayerArray)
  264. #define unity_RenderingLayer UNITY_ACCESS_INSTANCED_PROP(unity_Builtins1, unity_RenderingLayerArray).xxxx
  265. #endif
  266. UNITY_INSTANCING_BUFFER_END(unity_Builtins1)
  267. UNITY_INSTANCING_BUFFER_START(PerDraw2)
  268. #ifdef UNITY_USE_LIGHTMAPST_ARRAY
  269. UNITY_DEFINE_INSTANCED_PROP(float4, unity_LightmapSTArray)
  270. #define unity_LightmapST UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_LightmapSTArray)
  271. #endif
  272. #ifdef UNITY_USE_DYNAMICLIGHTMAPST_ARRAY
  273. UNITY_DEFINE_INSTANCED_PROP(float4, unity_DynamicLightmapSTArray)
  274. #define unity_DynamicLightmapST UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_DynamicLightmapSTArray)
  275. #endif
  276. #ifdef UNITY_USE_SHCOEFFS_ARRAYS
  277. UNITY_DEFINE_INSTANCED_PROP(half4, unity_SHArArray)
  278. UNITY_DEFINE_INSTANCED_PROP(half4, unity_SHAgArray)
  279. UNITY_DEFINE_INSTANCED_PROP(half4, unity_SHAbArray)
  280. UNITY_DEFINE_INSTANCED_PROP(half4, unity_SHBrArray)
  281. UNITY_DEFINE_INSTANCED_PROP(half4, unity_SHBgArray)
  282. UNITY_DEFINE_INSTANCED_PROP(half4, unity_SHBbArray)
  283. UNITY_DEFINE_INSTANCED_PROP(half4, unity_SHCArray)
  284. #define unity_SHAr UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_SHArArray)
  285. #define unity_SHAg UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_SHAgArray)
  286. #define unity_SHAb UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_SHAbArray)
  287. #define unity_SHBr UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_SHBrArray)
  288. #define unity_SHBg UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_SHBgArray)
  289. #define unity_SHBb UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_SHBbArray)
  290. #define unity_SHC UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_SHCArray)
  291. #endif
  292. #ifdef UNITY_USE_PROBESOCCLUSION_ARRAY
  293. UNITY_DEFINE_INSTANCED_PROP(half4, unity_ProbesOcclusionArray)
  294. #define unity_ProbesOcclusion UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_ProbesOcclusionArray)
  295. #endif
  296. UNITY_INSTANCING_BUFFER_END(unity_Builtins2)
  297. #ifndef UNITY_DONT_INSTANCE_OBJECT_MATRICES
  298. #undef UNITY_MATRIX_M
  299. #undef UNITY_MATRIX_I_M
  300. #define MERGE_UNITY_BUILTINS_INDEX(X) unity_Builtins##X
  301. #define CALL_MERGE_UNITY_BUILTINS_INDEX(X) MERGE_UNITY_BUILTINS_INDEX(X)
  302. #ifdef MODIFY_MATRIX_FOR_CAMERA_RELATIVE_RENDERING
  303. #define UNITY_MATRIX_M ApplyCameraTranslationToMatrix(UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_ObjectToWorldArray))
  304. #define UNITY_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(UNITY_ACCESS_INSTANCED_PROP(CALL_MERGE_UNITY_BUILTINS_INDEX(UNITY_WORLDTOOBJECTARRAY_CB), unity_WorldToObjectArray))
  305. #else
  306. #define UNITY_MATRIX_M UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_ObjectToWorldArray)
  307. #define UNITY_MATRIX_I_M UNITY_ACCESS_INSTANCED_PROP(CALL_MERGE_UNITY_BUILTINS_INDEX(UNITY_WORLDTOOBJECTARRAY_CB), unity_WorldToObjectArray)
  308. #endif
  309. #endif
  310. #else // UNITY_INSTANCING_ENABLED
  311. // in procedural mode we don't need cbuffer, and properties are not uniforms
  312. #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
  313. #define UNITY_INSTANCING_BUFFER_START(buf)
  314. #define UNITY_INSTANCING_BUFFER_END(arr)
  315. #define UNITY_DEFINE_INSTANCED_PROP(type, var) static type var;
  316. #else
  317. #define UNITY_INSTANCING_BUFFER_START(buf) CBUFFER_START(buf)
  318. #define UNITY_INSTANCING_BUFFER_END(arr) CBUFFER_END
  319. #define UNITY_DEFINE_INSTANCED_PROP(type, var) type var;
  320. #endif
  321. #define UNITY_ACCESS_INSTANCED_PROP(arr, var) var
  322. #endif // UNITY_INSTANCING_ENABLED
  323. #endif // UNITY_INSTANCING_INCLUDED