Dbg.cpp 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <AnKi/Renderer/Dbg.h>
  6. #include <AnKi/Renderer/Renderer.h>
  7. #include <AnKi/Renderer/GBuffer.h>
  8. #include <AnKi/Renderer/LightShading.h>
  9. #include <AnKi/Renderer/FinalComposite.h>
  10. #include <AnKi/Renderer/ForwardShading.h>
  11. #include <AnKi/Renderer/ClusterBinning.h>
  12. #include <AnKi/Renderer/PrimaryNonRenderableVisibility.h>
  13. #include <AnKi/Scene.h>
  14. #include <AnKi/Util/Logger.h>
  15. #include <AnKi/Util/Enum.h>
  16. #include <AnKi/Util/Tracer.h>
  17. #include <AnKi/Util/CVarSet.h>
  18. #include <AnKi/Collision/ConvexHullShape.h>
  19. #include <AnKi/Physics/PhysicsWorld.h>
  20. #include <AnKi/GpuMemory/GpuVisibleTransientMemoryPool.h>
  21. #include <AnKi/Shaders/Include/GpuVisibilityTypes.h>
  22. #include <AnKi/Window/Input.h>
  23. namespace anki {
  24. static const F32 g_gizmoArrowPositions[13][3] = {{-0.016779f, -0.016779f, 0.779639f},
  25. {-0.016779f, 0.016779f, 0.779639f},
  26. {-0.016779f, -0.016779f, 0.0f},
  27. {-0.016779f, 0.016779f, 0.0f},
  28. {0.016779f, -0.016779f, 0.779639f},
  29. {0.016779f, 0.016779f, 0.779639f},
  30. {0.016779f, -0.016779f, 0.0f},
  31. {0.016779f, 0.016779f, 0.0f},
  32. {-0.056151f, -0.056151f, 0.787911f},
  33. {-0.056151f, 0.056151f, 0.787911f},
  34. {0.056151f, -0.056151f, 0.787911f},
  35. {0.056151f, 0.056151f, 0.787911f},
  36. {0.0f, 0.0f, 1.0f}};
  37. static const U16 g_gizmoArrowIndices[22][3] = {{1, 2, 0}, {3, 6, 2}, {7, 4, 6}, {1, 8, 9}, {6, 0, 2}, {3, 5, 7}, {8, 10, 12}, {4, 8, 0},
  38. {1, 11, 5}, {5, 10, 4}, {9, 8, 12}, {11, 9, 12}, {10, 11, 12}, {1, 3, 2}, {3, 7, 6}, {7, 5, 4},
  39. {1, 0, 8}, {6, 4, 0}, {3, 1, 5}, {4, 10, 8}, {1, 9, 11}, {5, 11, 10}};
  40. static const F32 g_gizmoScalePositions[8][3] = {
  41. {-0.056151f, -0.056151f, 0.651073f}, {-0.056151f, 0.056151f, 0.651073f}, {-0.056151f, -0.056151f, 0.520279f}, {-0.056151f, 0.056151f, 0.520279f},
  42. {0.056151f, -0.056151f, 0.651073f}, {0.056151f, 0.056151f, 0.651073f}, {0.056151f, -0.056151f, 0.520279f}, {0.056151f, 0.056151f, 0.520279f}};
  43. static const U16 g_gizmoScaleIndices[12][3] = {
  44. {1, 2, 0}, {3, 6, 2}, {7, 4, 6}, {5, 0, 4}, {6, 0, 2}, {3, 5, 7}, {1, 3, 2}, {3, 7, 6}, {7, 5, 4}, {5, 1, 0}, {6, 4, 0}, {3, 1, 5},
  45. };
  46. static const F32 g_gizmoRingPositions[256][3] = {{0.0f, 1.0f, -0.005991f},
  47. {0.0f, 1.0f, 0.005991f},
  48. {0.098017f, 0.995185f, -0.005991f},
  49. {0.098017f, 0.995185f, 0.005991f},
  50. {0.19509f, 0.980785f, -0.005991f},
  51. {0.19509f, 0.980785f, 0.005991f},
  52. {0.290285f, 0.95694f, -0.005991f},
  53. {0.290285f, 0.95694f, 0.005991f},
  54. {0.382683f, 0.92388f, -0.005991f},
  55. {0.382683f, 0.923879f, 0.005991f},
  56. {0.471397f, 0.881921f, -0.005991f},
  57. {0.471397f, 0.881921f, 0.005991f},
  58. {0.55557f, 0.83147f, -0.005991f},
  59. {0.55557f, 0.83147f, 0.005991f},
  60. {0.634393f, 0.77301f, -0.005991f},
  61. {0.634393f, 0.77301f, 0.005991f},
  62. {0.707107f, 0.707107f, -0.005991f},
  63. {0.707107f, 0.707107f, 0.005991f},
  64. {0.77301f, 0.634393f, -0.005991f},
  65. {0.77301f, 0.634393f, 0.005991f},
  66. {0.83147f, 0.55557f, -0.005991f},
  67. {0.83147f, 0.55557f, 0.005991f},
  68. {0.881921f, 0.471397f, -0.005991f},
  69. {0.881921f, 0.471397f, 0.005991f},
  70. {0.92388f, 0.382683f, -0.005991f},
  71. {0.92388f, 0.382683f, 0.005991f},
  72. {0.95694f, 0.290285f, -0.005991f},
  73. {0.95694f, 0.290285f, 0.005991f},
  74. {0.980785f, 0.19509f, -0.005991f},
  75. {0.980785f, 0.19509f, 0.005991f},
  76. {0.995185f, 0.098017f, -0.005991f},
  77. {0.995185f, 0.098017f, 0.005991f},
  78. {1.0f, 0.0f, -0.005991f},
  79. {1.0f, -0.0f, 0.005991f},
  80. {0.995185f, -0.098017f, -0.005991f},
  81. {0.995185f, -0.098017f, 0.005991f},
  82. {0.980785f, -0.19509f, -0.005991f},
  83. {0.980785f, -0.19509f, 0.005991f},
  84. {0.95694f, -0.290285f, -0.005991f},
  85. {0.95694f, -0.290285f, 0.005991f},
  86. {0.92388f, -0.382683f, -0.005991f},
  87. {0.92388f, -0.382683f, 0.005991f},
  88. {0.881921f, -0.471397f, -0.005991f},
  89. {0.881921f, -0.471397f, 0.005991f},
  90. {0.83147f, -0.55557f, -0.005991f},
  91. {0.83147f, -0.55557f, 0.005991f},
  92. {0.77301f, -0.634393f, -0.005991f},
  93. {0.77301f, -0.634393f, 0.005991f},
  94. {0.707107f, -0.707107f, -0.005991f},
  95. {0.707107f, -0.707107f, 0.005991f},
  96. {0.634393f, -0.77301f, -0.005991f},
  97. {0.634393f, -0.77301f, 0.005991f},
  98. {0.55557f, -0.83147f, -0.005991f},
  99. {0.55557f, -0.83147f, 0.005991f},
  100. {0.471397f, -0.881921f, -0.005991f},
  101. {0.471397f, -0.881921f, 0.005991f},
  102. {0.382683f, -0.923879f, -0.005991f},
  103. {0.382683f, -0.92388f, 0.005991f},
  104. {0.290285f, -0.95694f, -0.005991f},
  105. {0.290285f, -0.95694f, 0.005991f},
  106. {0.19509f, -0.980785f, -0.005991f},
  107. {0.19509f, -0.980785f, 0.005991f},
  108. {0.098017f, -0.995185f, -0.005991f},
  109. {0.098017f, -0.995185f, 0.005991f},
  110. {0.0f, -1.0f, -0.005991f},
  111. {0.0f, -1.0f, 0.005991f},
  112. {-0.098017f, -0.995185f, -0.005991f},
  113. {-0.098017f, -0.995185f, 0.005991f},
  114. {-0.19509f, -0.980785f, -0.005991f},
  115. {-0.19509f, -0.980785f, 0.005991f},
  116. {-0.290285f, -0.95694f, -0.005991f},
  117. {-0.290285f, -0.95694f, 0.005991f},
  118. {-0.382683f, -0.923879f, -0.005991f},
  119. {-0.382683f, -0.92388f, 0.005991f},
  120. {-0.471397f, -0.881921f, -0.005991f},
  121. {-0.471397f, -0.881921f, 0.005991f},
  122. {-0.55557f, -0.83147f, -0.005991f},
  123. {-0.55557f, -0.83147f, 0.005991f},
  124. {-0.634393f, -0.77301f, -0.005991f},
  125. {-0.634393f, -0.77301f, 0.005991f},
  126. {-0.707107f, -0.707107f, -0.005991f},
  127. {-0.707107f, -0.707107f, 0.005991f},
  128. {-0.77301f, -0.634393f, -0.005991f},
  129. {-0.77301f, -0.634393f, 0.005991f},
  130. {-0.83147f, -0.55557f, -0.005991f},
  131. {-0.83147f, -0.55557f, 0.005991f},
  132. {-0.881921f, -0.471397f, -0.005991f},
  133. {-0.881921f, -0.471397f, 0.005991f},
  134. {-0.92388f, -0.382683f, -0.005991f},
  135. {-0.92388f, -0.382683f, 0.005991f},
  136. {-0.95694f, -0.290285f, -0.005991f},
  137. {-0.95694f, -0.290285f, 0.005991f},
  138. {-0.980785f, -0.19509f, -0.005991f},
  139. {-0.980785f, -0.19509f, 0.005991f},
  140. {-0.995185f, -0.098017f, -0.005991f},
  141. {-0.995185f, -0.098017f, 0.005991f},
  142. {-1.0f, 0.0f, -0.005991f},
  143. {-1.0f, -0.0f, 0.005991f},
  144. {-0.995185f, 0.098017f, -0.005991f},
  145. {-0.995185f, 0.098017f, 0.005991f},
  146. {-0.980785f, 0.19509f, -0.005991f},
  147. {-0.980785f, 0.19509f, 0.005991f},
  148. {-0.95694f, 0.290285f, -0.005991f},
  149. {-0.95694f, 0.290285f, 0.005991f},
  150. {-0.92388f, 0.382683f, -0.005991f},
  151. {-0.92388f, 0.382683f, 0.005991f},
  152. {-0.881921f, 0.471397f, -0.005991f},
  153. {-0.881921f, 0.471397f, 0.005991f},
  154. {-0.83147f, 0.55557f, -0.005991f},
  155. {-0.83147f, 0.55557f, 0.005991f},
  156. {-0.77301f, 0.634393f, -0.005991f},
  157. {-0.77301f, 0.634393f, 0.005991f},
  158. {-0.707107f, 0.707107f, -0.005991f},
  159. {-0.707107f, 0.707107f, 0.005991f},
  160. {-0.634393f, 0.77301f, -0.005991f},
  161. {-0.634393f, 0.77301f, 0.005991f},
  162. {-0.55557f, 0.83147f, -0.005991f},
  163. {-0.55557f, 0.83147f, 0.005991f},
  164. {-0.471397f, 0.881921f, -0.005991f},
  165. {-0.471397f, 0.881921f, 0.005991f},
  166. {-0.382683f, 0.92388f, -0.005991f},
  167. {-0.382683f, 0.923879f, 0.005991f},
  168. {-0.290285f, 0.95694f, -0.005991f},
  169. {-0.290285f, 0.95694f, 0.005991f},
  170. {-0.19509f, 0.980785f, -0.005991f},
  171. {-0.19509f, 0.980785f, 0.005991f},
  172. {-0.098017f, 0.995185f, -0.005991f},
  173. {-0.098017f, 0.995185f, 0.005991f},
  174. {-0.695875f, 0.464969f, 0.005991f},
  175. {-0.738099f, 0.394522f, 0.005991f},
  176. {-0.530937f, 0.646949f, 0.005991f},
  177. {-0.591793f, 0.591793f, 0.005991f},
  178. {-0.646949f, 0.530937f, 0.005991f},
  179. {-0.320276f, 0.773215f, 0.005991f},
  180. {-0.394522f, 0.738099f, 0.005991f},
  181. {-0.163275f, 0.82084f, 0.005991f},
  182. {-0.082033f, 0.832891f, 0.005991f},
  183. {-0.242945f, 0.800884f, 0.005991f},
  184. {-0.464969f, 0.695875f, 0.005991f},
  185. {-0.82084f, -0.163275f, 0.005991f},
  186. {-0.832891f, -0.082033f, 0.005991f},
  187. {-0.800884f, -0.242945f, 0.005991f},
  188. {-0.738099f, -0.394522f, 0.005991f},
  189. {-0.773215f, -0.320276f, 0.005991f},
  190. {-0.591793f, -0.591793f, 0.005991f},
  191. {-0.646949f, -0.530937f, 0.005991f},
  192. {-0.464969f, -0.695875f, 0.005991f},
  193. {-0.394522f, -0.738099f, 0.005991f},
  194. {-0.530937f, -0.646949f, 0.005991f},
  195. {-0.695875f, -0.464969f, 0.005991f},
  196. {0.163275f, -0.82084f, 0.005991f},
  197. {0.082033f, -0.832891f, 0.005991f},
  198. {0.394522f, -0.738099f, 0.005991f},
  199. {0.320276f, -0.773215f, 0.005991f},
  200. {0.242945f, -0.800884f, 0.005991f},
  201. {0.530937f, -0.646949f, 0.005991f},
  202. {0.591793f, -0.591793f, 0.005991f},
  203. {0.646949f, -0.530937f, 0.005991f},
  204. {0.695875f, -0.464969f, 0.005991f},
  205. {0.738099f, -0.394522f, 0.005991f},
  206. {0.464969f, -0.695875f, 0.005991f},
  207. {0.464969f, 0.695875f, 0.005991f},
  208. {0.394522f, 0.738099f, 0.005991f},
  209. {0.646949f, 0.530937f, 0.005991f},
  210. {0.591793f, 0.591793f, 0.005991f},
  211. {0.530937f, 0.646949f, 0.005991f},
  212. {0.738099f, 0.394522f, 0.005991f},
  213. {0.800884f, 0.242945f, 0.005991f},
  214. {0.773215f, 0.320276f, 0.005991f},
  215. {0.832891f, 0.082033f, 0.005991f},
  216. {0.82084f, 0.163275f, 0.005991f},
  217. {0.695875f, 0.464969f, 0.005991f},
  218. {-0.836921f, -0.0f, 0.005991f},
  219. {-0.832891f, 0.082033f, 0.005991f},
  220. {-0.82084f, 0.163275f, 0.005991f},
  221. {-0.800884f, 0.242945f, 0.005991f},
  222. {-0.773215f, 0.320276f, 0.005991f},
  223. {-0.242945f, -0.800884f, 0.005991f},
  224. {-0.163275f, -0.82084f, 0.005991f},
  225. {0.163275f, 0.82084f, 0.005991f},
  226. {0.082033f, 0.832891f, 0.005991f},
  227. {0.0f, 0.836921f, 0.005991f},
  228. {-0.320276f, -0.773215f, 0.005991f},
  229. {0.0f, -0.836921f, 0.005991f},
  230. {-0.082033f, -0.832891f, 0.005991f},
  231. {0.242945f, 0.800884f, 0.005991f},
  232. {0.320276f, 0.773215f, 0.005991f},
  233. {0.800884f, -0.242945f, 0.005991f},
  234. {0.773215f, -0.320276f, 0.005991f},
  235. {0.836921f, -0.0f, 0.005991f},
  236. {0.82084f, -0.163275f, 0.005991f},
  237. {0.832891f, -0.082033f, 0.005991f},
  238. {0.242945f, 0.800884f, -0.005991f},
  239. {0.163275f, 0.82084f, -0.005991f},
  240. {0.464969f, 0.695875f, -0.005991f},
  241. {0.394522f, 0.738099f, -0.005991f},
  242. {0.320276f, 0.773215f, -0.005991f},
  243. {0.591793f, 0.591793f, -0.005991f},
  244. {0.646949f, 0.530937f, -0.005991f},
  245. {0.695875f, 0.464969f, -0.005991f},
  246. {0.738099f, 0.394522f, -0.005991f},
  247. {0.773215f, 0.320276f, -0.005991f},
  248. {0.530937f, 0.646949f, -0.005991f},
  249. {0.394522f, -0.738099f, -0.005991f},
  250. {0.320276f, -0.773215f, -0.005991f},
  251. {0.591793f, -0.591793f, -0.005991f},
  252. {0.530937f, -0.646949f, -0.005991f},
  253. {0.464969f, -0.695875f, -0.005991f},
  254. {0.695875f, -0.464969f, -0.005991f},
  255. {0.738099f, -0.394522f, -0.005991f},
  256. {0.773215f, -0.320276f, -0.005991f},
  257. {0.800884f, -0.242945f, -0.005991f},
  258. {0.82084f, -0.163275f, -0.005991f},
  259. {0.646949f, -0.530937f, -0.005991f},
  260. {-0.738099f, -0.394522f, -0.005991f},
  261. {-0.773215f, -0.320276f, -0.005991f},
  262. {-0.591793f, -0.591793f, -0.005991f},
  263. {-0.695875f, -0.464969f, -0.005991f},
  264. {-0.646949f, -0.530937f, -0.005991f},
  265. {-0.394522f, -0.738099f, -0.005991f},
  266. {-0.464969f, -0.695875f, -0.005991f},
  267. {-0.242945f, -0.800884f, -0.005991f},
  268. {-0.163275f, -0.82084f, -0.005991f},
  269. {-0.320276f, -0.773215f, -0.005991f},
  270. {-0.530937f, -0.646949f, -0.005991f},
  271. {-0.800884f, 0.242945f, -0.005991f},
  272. {-0.82084f, 0.163275f, -0.005991f},
  273. {-0.773215f, 0.320276f, -0.005991f},
  274. {-0.695875f, 0.464969f, -0.005991f},
  275. {-0.738099f, 0.394522f, -0.005991f},
  276. {-0.530937f, 0.646949f, -0.005991f},
  277. {-0.591793f, 0.591793f, -0.005991f},
  278. {-0.394522f, 0.738099f, -0.005991f},
  279. {-0.320276f, 0.773215f, -0.005991f},
  280. {-0.464969f, 0.695875f, -0.005991f},
  281. {-0.646949f, 0.530937f, -0.005991f},
  282. {0.0f, 0.836921f, -0.005991f},
  283. {0.082033f, 0.832891f, -0.005991f},
  284. {0.163275f, -0.82084f, -0.005991f},
  285. {0.242945f, -0.800884f, -0.005991f},
  286. {0.82084f, 0.163275f, -0.005991f},
  287. {0.800884f, 0.242945f, -0.005991f},
  288. {0.836921f, 0.0f, -0.005991f},
  289. {0.832891f, -0.082033f, -0.005991f},
  290. {0.832891f, 0.082033f, -0.005991f},
  291. {-0.836921f, 0.0f, -0.005991f},
  292. {-0.832891f, -0.082033f, -0.005991f},
  293. {-0.832891f, 0.082033f, -0.005991f},
  294. {-0.82084f, -0.163275f, -0.005991f},
  295. {-0.800884f, -0.242945f, -0.005991f},
  296. {-0.163275f, 0.82084f, -0.005991f},
  297. {-0.082033f, 0.832891f, -0.005991f},
  298. {0.082033f, -0.832891f, -0.005991f},
  299. {0.0f, -0.836921f, -0.005991f},
  300. {-0.082033f, -0.832891f, -0.005991f},
  301. {-0.242945f, 0.800884f, -0.005991f}};
  302. static const U16 g_gizmoRingIndices[512][3] = {
  303. {1, 2, 0}, {3, 4, 2}, {5, 6, 4}, {7, 8, 6}, {9, 10, 8}, {11, 12, 10}, {13, 14, 12}, {15, 16, 14},
  304. {17, 18, 16}, {19, 20, 18}, {21, 22, 20}, {23, 24, 22}, {25, 26, 24}, {27, 28, 26}, {29, 30, 28}, {31, 32, 30},
  305. {33, 34, 32}, {35, 36, 34}, {37, 38, 36}, {39, 40, 38}, {41, 42, 40}, {43, 44, 42}, {45, 46, 44}, {47, 48, 46},
  306. {49, 50, 48}, {51, 52, 50}, {53, 54, 52}, {55, 56, 54}, {57, 58, 56}, {59, 60, 58}, {61, 62, 60}, {63, 64, 62},
  307. {64, 67, 66}, {66, 69, 68}, {68, 71, 70}, {70, 73, 72}, {72, 75, 74}, {74, 77, 76}, {76, 79, 78}, {78, 81, 80},
  308. {80, 83, 82}, {82, 85, 84}, {84, 87, 86}, {86, 89, 88}, {88, 91, 90}, {90, 93, 92}, {92, 95, 94}, {94, 97, 96},
  309. {96, 99, 98}, {98, 101, 100}, {100, 103, 102}, {102, 105, 104}, {104, 107, 106}, {106, 109, 108}, {108, 111, 110}, {110, 113, 112},
  310. {112, 115, 114}, {114, 117, 116}, {116, 119, 118}, {118, 121, 120}, {120, 123, 122}, {122, 125, 124}, {63, 150, 151}, {133, 137, 121},
  311. {124, 127, 126}, {126, 1, 0}, {193, 6, 192}, {219, 223, 74}, {237, 181, 236}, {193, 180, 237}, {192, 179, 193}, {196, 185, 192},
  312. {162, 196, 195}, {161, 195, 194}, {202, 161, 194}, {197, 165, 202}, {164, 198, 163}, {163, 199, 171}, {171, 200, 166}, {166, 201, 168},
  313. {168, 241, 167}, {167, 240, 170}, {170, 244, 169}, {169, 242, 189}, {189, 243, 191}, {191, 212, 190}, {190, 211, 187}, {187, 210, 188},
  314. {188, 209, 159}, {159, 208, 158}, {158, 213, 157}, {157, 205, 156}, {156, 206, 155}, {155, 207, 160}, {160, 203, 152}, {152, 204, 153},
  315. {153, 239, 154}, {154, 238, 150}, {150, 252, 151}, {151, 253, 183}, {184, 253, 254}, {178, 254, 222}, {177, 222, 221}, {182, 221, 223},
  316. {182, 219, 147}, {147, 220, 146}, {148, 220, 224}, {144, 224, 216}, {145, 216, 218}, {149, 218, 217}, {142, 217, 214}, {143, 214, 215},
  317. {141, 215, 249}, {139, 249, 248}, {140, 248, 246}, {172, 246, 245}, {173, 245, 247}, {174, 247, 226}, {175, 226, 225}, {176, 225, 227},
  318. {129, 227, 229}, {128, 229, 228}, {132, 228, 235}, {131, 235, 231}, {130, 231, 230}, {138, 230, 234}, {134, 234, 232}, {133, 232, 233},
  319. {137, 233, 255}, {135, 255, 250}, {136, 250, 251}, {181, 251, 236}, {1, 3, 2}, {3, 5, 4}, {5, 7, 6}, {7, 9, 8},
  320. {9, 11, 10}, {11, 13, 12}, {13, 15, 14}, {15, 17, 16}, {17, 19, 18}, {19, 21, 20}, {21, 23, 22}, {23, 25, 24},
  321. {25, 27, 26}, {27, 29, 28}, {29, 31, 30}, {31, 33, 32}, {33, 35, 34}, {35, 37, 36}, {37, 39, 38}, {39, 41, 40},
  322. {41, 43, 42}, {43, 45, 44}, {45, 47, 46}, {47, 49, 48}, {49, 51, 50}, {51, 53, 52}, {53, 55, 54}, {55, 57, 56},
  323. {57, 59, 58}, {59, 61, 60}, {61, 63, 62}, {63, 65, 64}, {64, 65, 67}, {66, 67, 69}, {68, 69, 71}, {70, 71, 73},
  324. {72, 73, 75}, {74, 75, 77}, {76, 77, 79}, {78, 79, 81}, {80, 81, 83}, {82, 83, 85}, {84, 85, 87}, {86, 87, 89},
  325. {88, 89, 91}, {90, 91, 93}, {92, 93, 95}, {94, 95, 97}, {96, 97, 99}, {98, 99, 101}, {100, 101, 103}, {102, 103, 105},
  326. {104, 105, 107}, {106, 107, 109}, {108, 109, 111}, {110, 111, 113}, {112, 113, 115}, {114, 115, 117}, {116, 117, 119}, {118, 119, 121},
  327. {120, 121, 123}, {122, 123, 125}, {138, 117, 115}, {115, 113, 130}, {113, 111, 131}, {130, 113, 131}, {111, 109, 128}, {109, 107, 129},
  328. {107, 105, 129}, {105, 103, 176}, {129, 105, 176}, {103, 101, 175}, {101, 99, 174}, {175, 101, 174}, {99, 97, 173}, {97, 95, 172},
  329. {173, 97, 172}, {95, 93, 139}, {93, 91, 141}, {91, 89, 143}, {89, 87, 143}, {87, 85, 142}, {85, 83, 149}, {142, 85, 149},
  330. {83, 81, 145}, {81, 79, 144}, {145, 81, 144}, {79, 77, 146}, {77, 75, 147}, {75, 73, 147}, {73, 71, 182}, {147, 73, 182},
  331. {71, 69, 177}, {69, 67, 178}, {177, 69, 178}, {67, 65, 184}, {65, 63, 183}, {184, 65, 183}, {63, 61, 150}, {61, 59, 154},
  332. {59, 57, 153}, {57, 55, 152}, {55, 53, 160}, {53, 51, 160}, {51, 49, 155}, {49, 47, 156}, {155, 49, 156}, {47, 45, 158},
  333. {45, 43, 159}, {43, 41, 188}, {41, 39, 187}, {39, 37, 190}, {37, 35, 191}, {35, 33, 191}, {33, 31, 189}, {191, 33, 189},
  334. {31, 29, 170}, {29, 27, 167}, {27, 25, 168}, {25, 23, 166}, {23, 21, 171}, {21, 19, 171}, {19, 17, 163}, {17, 15, 164},
  335. {163, 17, 164}, {15, 13, 161}, {13, 11, 162}, {11, 9, 186}, {9, 7, 185}, {7, 5, 185}, {5, 179, 185}, {13, 162, 161},
  336. {9, 185, 186}, {171, 19, 163}, {29, 167, 170}, {25, 166, 168}, {37, 191, 190}, {45, 159, 158}, {41, 187, 188}, {160, 51, 155},
  337. {61, 154, 150}, {57, 152, 153}, {77, 147, 146}, {93, 141, 139}, {109, 129, 128}, {138, 115, 130}, {91, 143, 141}, {143, 87, 142},
  338. {11, 186, 162}, {132, 131, 111}, {128, 132, 111}, {15, 161, 165}, {15, 165, 164}, {176, 103, 175}, {174, 99, 173}, {23, 171, 166},
  339. {27, 168, 167}, {140, 172, 95}, {139, 140, 95}, {31, 170, 169}, {31, 169, 189}, {149, 83, 145}, {39, 190, 187}, {43, 188, 159},
  340. {148, 144, 79}, {146, 148, 79}, {47, 158, 157}, {47, 157, 156}, {182, 71, 177}, {178, 67, 184}, {55, 160, 152}, {59, 153, 154},
  341. {151, 183, 63}, {180, 179, 5}, {5, 3, 180}, {3, 1, 181}, {1, 127, 136}, {127, 125, 135}, {125, 123, 135}, {123, 121, 137},
  342. {135, 123, 137}, {121, 119, 133}, {119, 117, 134}, {133, 119, 134}, {117, 138, 134}, {3, 181, 180}, {127, 135, 136}, {136, 181, 1},
  343. {124, 125, 127}, {126, 127, 1}, {216, 224, 78}, {78, 80, 216}, {80, 82, 218}, {82, 84, 217}, {84, 86, 217}, {86, 88, 214},
  344. {88, 90, 215}, {214, 88, 215}, {90, 92, 249}, {92, 94, 248}, {249, 92, 248}, {94, 96, 245}, {96, 98, 247}, {98, 100, 247},
  345. {100, 102, 226}, {247, 100, 226}, {102, 104, 225}, {104, 106, 227}, {225, 104, 227}, {106, 108, 229}, {108, 110, 228}, {229, 108, 228},
  346. {110, 112, 231}, {112, 114, 230}, {114, 116, 234}, {116, 118, 234}, {118, 120, 232}, {120, 122, 233}, {232, 120, 233}, {122, 124, 255},
  347. {124, 126, 250}, {255, 124, 250}, {126, 0, 236}, {0, 2, 237}, {2, 4, 237}, {4, 6, 193}, {237, 4, 193}, {6, 8, 192},
  348. {8, 10, 196}, {192, 8, 196}, {10, 12, 195}, {12, 14, 194}, {195, 12, 194}, {14, 16, 197}, {16, 18, 198}, {18, 20, 199},
  349. {20, 22, 200}, {22, 24, 201}, {24, 26, 241}, {26, 28, 241}, {28, 30, 240}, {241, 28, 240}, {30, 32, 242}, {32, 34, 243},
  350. {34, 36, 212}, {36, 38, 211}, {38, 40, 210}, {40, 42, 210}, {42, 44, 209}, {44, 46, 208}, {209, 44, 208}, {46, 48, 205},
  351. {48, 50, 206}, {50, 52, 207}, {52, 54, 203}, {54, 56, 203}, {56, 58, 204}, {203, 56, 204}, {58, 60, 239}, {60, 62, 238},
  352. {239, 60, 238}, {62, 252, 238}, {48, 206, 205}, {52, 203, 207}, {210, 42, 209}, {32, 243, 242}, {36, 211, 212}, {24, 241, 201},
  353. {16, 198, 197}, {20, 200, 199}, {0, 237, 236}, {112, 230, 231}, {96, 247, 245}, {80, 218, 216}, {217, 218, 82}, {217, 86, 214},
  354. {114, 234, 230}, {234, 118, 232}, {239, 204, 58}, {215, 90, 249}, {50, 207, 206}, {246, 248, 94}, {46, 205, 213}, {46, 213, 208},
  355. {245, 246, 94}, {226, 102, 225}, {38, 210, 211}, {227, 106, 229}, {34, 212, 243}, {30, 242, 244}, {235, 228, 110}, {231, 235, 110},
  356. {30, 244, 240}, {22, 201, 200}, {233, 122, 255}, {18, 199, 198}, {251, 250, 126}, {14, 197, 202}, {14, 202, 194}, {236, 251, 126},
  357. {195, 196, 10}, {253, 252, 62}, {62, 64, 253}, {64, 66, 254}, {66, 68, 222}, {68, 70, 221}, {70, 72, 221}, {72, 74, 223},
  358. {221, 72, 223}, {74, 76, 219}, {76, 78, 220}, {219, 76, 220}, {78, 224, 220}, {64, 254, 253}, {68, 221, 222}, {222, 254, 66},
  359. {237, 180, 181}, {193, 179, 180}, {192, 185, 179}, {196, 186, 185}, {162, 186, 196}, {161, 162, 195}, {202, 165, 161}, {197, 164, 165},
  360. {164, 197, 198}, {163, 198, 199}, {171, 199, 200}, {166, 200, 201}, {168, 201, 241}, {167, 241, 240}, {170, 240, 244}, {169, 244, 242},
  361. {189, 242, 243}, {191, 243, 212}, {190, 212, 211}, {187, 211, 210}, {188, 210, 209}, {159, 209, 208}, {158, 208, 213}, {157, 213, 205},
  362. {156, 205, 206}, {155, 206, 207}, {160, 207, 203}, {152, 203, 204}, {153, 204, 239}, {154, 239, 238}, {150, 238, 252}, {151, 252, 253},
  363. {184, 183, 253}, {178, 184, 254}, {177, 178, 222}, {182, 177, 221}, {182, 223, 219}, {147, 219, 220}, {148, 146, 220}, {144, 148, 224},
  364. {145, 144, 216}, {149, 145, 218}, {142, 149, 217}, {143, 142, 214}, {141, 143, 215}, {139, 141, 249}, {140, 139, 248}, {172, 140, 246},
  365. {173, 172, 245}, {174, 173, 247}, {175, 174, 226}, {176, 175, 225}, {129, 176, 227}, {128, 129, 229}, {132, 128, 228}, {131, 132, 235},
  366. {130, 131, 231}, {138, 130, 230}, {134, 138, 234}, {133, 134, 232}, {137, 133, 233}, {135, 137, 255}, {136, 135, 250}, {181, 136, 251}};
  367. static constexpr F32 kCubePositions[] = {
  368. // Front face
  369. -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f,
  370. // Back face
  371. 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f,
  372. // Left face
  373. -0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f,
  374. // Right face
  375. 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f,
  376. // Top face
  377. -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f,
  378. // Bottom face
  379. -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f};
  380. Dbg::Dbg()
  381. {
  382. registerDebugRenderTarget("ObjectPicking");
  383. }
  384. Dbg::~Dbg()
  385. {
  386. }
  387. Error Dbg::init()
  388. {
  389. // RT descr
  390. m_rtDescr = getRenderer().create2DRenderTargetDescription(getRenderer().getInternalResolution().x, getRenderer().getInternalResolution().y,
  391. Format::kR8G8B8A8_Unorm, "Dbg");
  392. m_rtDescr.bake();
  393. m_objectPickingRtDescr = getRenderer().create2DRenderTargetDescription(
  394. getRenderer().getInternalResolution().x / 2, getRenderer().getInternalResolution().y / 2, Format::kR32_Uint, "ObjectPicking");
  395. m_objectPickingRtDescr.bake();
  396. m_objectPickingDepthRtDescr = getRenderer().create2DRenderTargetDescription(
  397. getRenderer().getInternalResolution().x / 2, getRenderer().getInternalResolution().y / 2, Format::kD32_Sfloat, "ObjectPickingDepth");
  398. m_objectPickingDepthRtDescr.bake();
  399. ResourceManager& rsrcManager = ResourceManager::getSingleton();
  400. ANKI_CHECK(rsrcManager.loadResource("EngineAssets/GiProbe.ankitex", m_giProbeImage));
  401. ANKI_CHECK(rsrcManager.loadResource("EngineAssets/LightBulb.ankitex", m_pointLightImage));
  402. ANKI_CHECK(rsrcManager.loadResource("EngineAssets/SpotLight.ankitex", m_spotLightImage));
  403. ANKI_CHECK(rsrcManager.loadResource("EngineAssets/GreenDecal.ankitex", m_decalImage));
  404. ANKI_CHECK(rsrcManager.loadResource("EngineAssets/Mirror.ankitex", m_reflectionImage));
  405. ANKI_CHECK(rsrcManager.loadResource("ShaderBinaries/Dbg.ankiprogbin", m_dbgProg));
  406. {
  407. BufferInitInfo buffInit("Dbg cube verts");
  408. buffInit.m_size = sizeof(Vec3) * 8;
  409. buffInit.m_usage = BufferUsageBit::kVertexOrIndex;
  410. buffInit.m_mapAccess = BufferMapAccessBit::kWrite;
  411. m_boxLines.m_positionsBuff = GrManager::getSingleton().newBuffer(buffInit);
  412. Vec3* verts = static_cast<Vec3*>(m_boxLines.m_positionsBuff->map(0, kMaxPtrSize, BufferMapAccessBit::kWrite));
  413. constexpr F32 kSize = 1.0f;
  414. verts[0] = Vec3(kSize, kSize, kSize); // front top right
  415. verts[1] = Vec3(-kSize, kSize, kSize); // front top left
  416. verts[2] = Vec3(-kSize, -kSize, kSize); // front bottom left
  417. verts[3] = Vec3(kSize, -kSize, kSize); // front bottom right
  418. verts[4] = Vec3(kSize, kSize, -kSize); // back top right
  419. verts[5] = Vec3(-kSize, kSize, -kSize); // back top left
  420. verts[6] = Vec3(-kSize, -kSize, -kSize); // back bottom left
  421. verts[7] = Vec3(kSize, -kSize, -kSize); // back bottom right
  422. m_boxLines.m_positionsBuff->unmap();
  423. constexpr U kIndexCount = 12 * 2;
  424. buffInit.setName("Dbg cube indices");
  425. buffInit.m_usage = BufferUsageBit::kVertexOrIndex;
  426. buffInit.m_size = kIndexCount * sizeof(U16);
  427. m_boxLines.m_indexBuff = GrManager::getSingleton().newBuffer(buffInit);
  428. U16* indices = static_cast<U16*>(m_boxLines.m_indexBuff->map(0, kMaxPtrSize, BufferMapAccessBit::kWrite));
  429. U c = 0;
  430. indices[c++] = 0;
  431. indices[c++] = 1;
  432. indices[c++] = 1;
  433. indices[c++] = 2;
  434. indices[c++] = 2;
  435. indices[c++] = 3;
  436. indices[c++] = 3;
  437. indices[c++] = 0;
  438. indices[c++] = 4;
  439. indices[c++] = 5;
  440. indices[c++] = 5;
  441. indices[c++] = 6;
  442. indices[c++] = 6;
  443. indices[c++] = 7;
  444. indices[c++] = 7;
  445. indices[c++] = 4;
  446. indices[c++] = 0;
  447. indices[c++] = 4;
  448. indices[c++] = 1;
  449. indices[c++] = 5;
  450. indices[c++] = 2;
  451. indices[c++] = 6;
  452. indices[c++] = 3;
  453. indices[c++] = 7;
  454. m_boxLines.m_indexBuff->unmap();
  455. ANKI_ASSERT(c == kIndexCount);
  456. }
  457. initGizmos();
  458. {
  459. BufferInitInfo buffInit("Debug cube");
  460. buffInit.m_mapAccess = BufferMapAccessBit::kWrite;
  461. buffInit.m_size = sizeof(kCubePositions);
  462. buffInit.m_usage = BufferUsageBit::kVertexOrIndex;
  463. m_debugPoint.m_positionsBuff = GrManager::getSingleton().newBuffer(buffInit);
  464. void* mapped = m_debugPoint.m_positionsBuff->map(0, kMaxPtrSize, BufferMapAccessBit::kWrite);
  465. memcpy(mapped, kCubePositions, sizeof(kCubePositions));
  466. m_debugPoint.m_positionsBuff->unmap();
  467. }
  468. return Error::kNone;
  469. }
  470. void Dbg::initGizmos()
  471. {
  472. auto createPair = [](CString name, ConstWeakArray<F32> positionsArray, ConstWeakArray<U16> indicesArray, BufferPtr& positionsBuff,
  473. BufferPtr& indicesBuff) {
  474. BufferInitInfo buffInit(name);
  475. buffInit.m_mapAccess = BufferMapAccessBit::kWrite;
  476. buffInit.m_size = positionsArray.getSizeInBytes();
  477. buffInit.m_usage = BufferUsageBit::kVertexOrIndex;
  478. positionsBuff = GrManager::getSingleton().newBuffer(buffInit);
  479. void* mapped = positionsBuff->map(0, kMaxPtrSize, BufferMapAccessBit::kWrite);
  480. memcpy(mapped, positionsArray.getBegin(), positionsArray.getSizeInBytes());
  481. positionsBuff->unmap();
  482. buffInit.m_size = indicesArray.getSizeInBytes();
  483. indicesBuff = GrManager::getSingleton().newBuffer(buffInit);
  484. mapped = indicesBuff->map(0, kMaxPtrSize, BufferMapAccessBit::kWrite);
  485. memcpy(mapped, indicesArray.getBegin(), indicesArray.getSizeInBytes());
  486. indicesBuff->unmap();
  487. };
  488. createPair("GizmosArrow", ConstWeakArray<F32>(&g_gizmoArrowPositions[0][0], sizeof(g_gizmoArrowPositions) / sizeof(F32)),
  489. ConstWeakArray<U16>(&g_gizmoArrowIndices[0][0], sizeof(g_gizmoArrowIndices) / sizeof(U16)), m_gizmos.m_arrowPositions,
  490. m_gizmos.m_arrowIndices);
  491. createPair("GizmosScale", ConstWeakArray<F32>(&g_gizmoScalePositions[0][0], sizeof(g_gizmoScalePositions) / sizeof(F32)),
  492. ConstWeakArray<U16>(&g_gizmoScaleIndices[0][0], sizeof(g_gizmoScaleIndices) / sizeof(U16)), m_gizmos.m_scalePositions,
  493. m_gizmos.m_scaleIndices);
  494. createPair("GizmosRing", ConstWeakArray<F32>(&g_gizmoRingPositions[0][0], sizeof(g_gizmoRingPositions) / sizeof(F32)),
  495. ConstWeakArray<U16>(&g_gizmoRingIndices[0][0], sizeof(g_gizmoRingIndices) / sizeof(U16)), m_gizmos.m_ringPositions,
  496. m_gizmos.m_ringIndices);
  497. }
  498. void Dbg::drawNonRenderable(GpuSceneNonRenderableObjectType type, U32 objCount, const RenderingContext& ctx, const ImageResource& image,
  499. CommandBuffer& cmdb)
  500. {
  501. ShaderProgramResourceVariantInitInfo variantInitInfo(m_dbgProg);
  502. variantInitInfo.addMutation("OBJECT_TYPE", U32(type));
  503. variantInitInfo.requestTechniqueAndTypes(ShaderTypeBit::kVertex | ShaderTypeBit::kPixel, "Bilboards");
  504. const ShaderProgramResourceVariant* variant;
  505. m_dbgProg->getOrCreateVariant(variantInitInfo, variant);
  506. cmdb.bindShaderProgram(&variant->getProgram());
  507. class Constants
  508. {
  509. public:
  510. Mat4 m_viewProjMat;
  511. Mat3x4 m_camTrf;
  512. UVec3 m_padding;
  513. U32 m_depthFailureVisualization;
  514. } consts;
  515. consts.m_viewProjMat = ctx.m_matrices.m_viewProjection;
  516. consts.m_camTrf = ctx.m_matrices.m_cameraTransform;
  517. consts.m_depthFailureVisualization = !(m_options & DbgOption::kDepthTest);
  518. cmdb.setFastConstants(&consts, sizeof(consts));
  519. cmdb.bindSrv(1, 0, getClusterBinning().getPackedObjectsBuffer(type));
  520. cmdb.bindSrv(2, 0, getRenderer().getPrimaryNonRenderableVisibility().getVisibleIndicesBuffer(type));
  521. cmdb.bindSampler(1, 0, getRenderer().getSamplers().m_trilinearRepeat.get());
  522. cmdb.bindSrv(3, 0, TextureView(&image.getTexture(), TextureSubresourceDesc::all()));
  523. cmdb.bindSrv(4, 0, TextureView(&m_spotLightImage->getTexture(), TextureSubresourceDesc::all()));
  524. cmdb.draw(PrimitiveTopology::kTriangles, 6, objCount);
  525. }
  526. void Dbg::populateRenderGraph(RenderingContext& ctx)
  527. {
  528. ANKI_TRACE_SCOPED_EVENT(Dbg);
  529. m_runCtx.m_objectPickingRt = {};
  530. if(!isEnabled())
  531. {
  532. return;
  533. }
  534. // Debug visualization
  535. if(!!(m_options & (DbgOption::kDbgScene)))
  536. {
  537. populateRenderGraphMain(ctx);
  538. }
  539. // Object picking
  540. if(!!(m_options & DbgOption::kObjectPicking))
  541. {
  542. populateRenderGraphObjectPicking(ctx);
  543. }
  544. }
  545. void Dbg::populateRenderGraphMain(RenderingContext& ctx)
  546. {
  547. RenderGraphBuilder& rgraph = ctx.m_renderGraphDescr;
  548. m_runCtx.m_rt = rgraph.newRenderTarget(m_rtDescr);
  549. GraphicsRenderPass& pass = rgraph.newGraphicsRenderPass("Debug");
  550. GraphicsRenderPassTargetDesc colorRti(m_runCtx.m_rt);
  551. colorRti.m_loadOperation = RenderTargetLoadOperation::kClear;
  552. GraphicsRenderPassTargetDesc depthRti(getGBuffer().getDepthRt());
  553. depthRti.m_loadOperation = RenderTargetLoadOperation::kLoad;
  554. depthRti.m_subresource.m_depthStencilAspect = DepthStencilAspectBit::kDepth;
  555. pass.setRenderpassInfo({colorRti}, &depthRti);
  556. pass.newTextureDependency(m_runCtx.m_rt, TextureUsageBit::kRtvDsvWrite);
  557. pass.newTextureDependency(getGBuffer().getDepthRt(), TextureUsageBit::kSrvPixel | TextureUsageBit::kRtvDsvRead);
  558. const GpuVisibilityOutput& visOut = getGBuffer().getVisibilityOutput();
  559. if(visOut.m_dependency.isValid())
  560. {
  561. pass.newBufferDependency(visOut.m_dependency, BufferUsageBit::kSrvGeometry);
  562. }
  563. const GpuVisibilityOutput& fvisOut = getForwardShading().getGpuVisibilityOutput();
  564. if(fvisOut.m_dependency.isValid())
  565. {
  566. pass.newBufferDependency(fvisOut.m_dependency, BufferUsageBit::kSrvGeometry);
  567. }
  568. pass.setWork([this, &ctx](RenderPassWorkContext& rgraphCtx) {
  569. ANKI_TRACE_SCOPED_EVENT(Dbg);
  570. ANKI_ASSERT(!!(m_options & DbgOption::kDbgScene));
  571. CommandBuffer& cmdb = *rgraphCtx.m_commandBuffer;
  572. // Set common state
  573. cmdb.setViewport(0, 0, getRenderer().getInternalResolution().x, getRenderer().getInternalResolution().y);
  574. cmdb.setDepthWrite(false);
  575. cmdb.setBlendFactors(0, BlendFactor::kSrcAlpha, BlendFactor::kOneMinusSrcAlpha);
  576. cmdb.setDepthCompareOperation(!!(m_options & DbgOption::kDepthTest) ? CompareOperation::kLess : CompareOperation::kAlways);
  577. cmdb.setLineWidth(2.0f);
  578. rgraphCtx.bindSrv(0, 0, getGBuffer().getDepthRt());
  579. // Common code for boxes stuff
  580. {
  581. ShaderProgramResourceVariantInitInfo variantInitInfo(m_dbgProg);
  582. variantInitInfo.addMutation("OBJECT_TYPE", 0);
  583. variantInitInfo.requestTechniqueAndTypes(ShaderTypeBit::kVertex | ShaderTypeBit::kPixel, "RenderableBoxes");
  584. const ShaderProgramResourceVariant* variant;
  585. m_dbgProg->getOrCreateVariant(variantInitInfo, variant);
  586. cmdb.bindShaderProgram(&variant->getProgram());
  587. class Constants
  588. {
  589. public:
  590. Vec4 m_color;
  591. Mat4 m_viewProjMat;
  592. UVec3 m_padding;
  593. U32 m_depthFailureVisualization;
  594. } consts;
  595. consts.m_color = Vec4(1.0f, 1.0f, 0.0f, 1.0f);
  596. consts.m_viewProjMat = ctx.m_matrices.m_viewProjection;
  597. consts.m_depthFailureVisualization = !(m_options & DbgOption::kDepthTest);
  598. cmdb.setFastConstants(&consts, sizeof(consts));
  599. cmdb.bindVertexBuffer(0, BufferView(m_boxLines.m_positionsBuff.get()), sizeof(Vec3));
  600. cmdb.setVertexAttribute(VertexAttributeSemantic::kPosition, 0, Format::kR32G32B32_Sfloat, 0);
  601. cmdb.bindIndexBuffer(BufferView(m_boxLines.m_indexBuff.get()), IndexType::kU16);
  602. }
  603. // GBuffer AABBs
  604. const U32 gbufferAllAabbCount = GpuSceneArrays::RenderableBoundingVolumeGBuffer::getSingleton().getElementCount();
  605. if(!!(m_options & DbgOption::kBoundingBoxes) && gbufferAllAabbCount)
  606. {
  607. cmdb.bindSrv(1, 0, GpuSceneArrays::RenderableBoundingVolumeGBuffer::getSingleton().getBufferView());
  608. const GpuVisibilityOutput& visOut = getGBuffer().getVisibilityOutput();
  609. cmdb.bindSrv(2, 0, visOut.m_visibleAaabbIndicesBuffer);
  610. cmdb.drawIndexed(PrimitiveTopology::kLines, 12 * 2, gbufferAllAabbCount);
  611. }
  612. // Forward shading renderables
  613. const U32 forwardAllAabbCount = GpuSceneArrays::RenderableBoundingVolumeForward::getSingleton().getElementCount();
  614. if(!!(m_options & DbgOption::kBoundingBoxes) && forwardAllAabbCount)
  615. {
  616. cmdb.bindSrv(1, 0, GpuSceneArrays::RenderableBoundingVolumeForward::getSingleton().getBufferView());
  617. const GpuVisibilityOutput& visOut = getForwardShading().getGpuVisibilityOutput();
  618. cmdb.bindSrv(2, 0, visOut.m_visibleAaabbIndicesBuffer);
  619. cmdb.drawIndexed(PrimitiveTopology::kLines, 12 * 2, forwardAllAabbCount);
  620. }
  621. // Draw non-renderables
  622. if(!!(m_options & DbgOption::kIcons))
  623. {
  624. drawNonRenderable(GpuSceneNonRenderableObjectType::kLight, GpuSceneArrays::Light::getSingleton().getElementCount(), ctx,
  625. *m_pointLightImage, cmdb);
  626. drawNonRenderable(GpuSceneNonRenderableObjectType::kDecal, GpuSceneArrays::Decal::getSingleton().getElementCount(), ctx, *m_decalImage,
  627. cmdb);
  628. drawNonRenderable(GpuSceneNonRenderableObjectType::kGlobalIlluminationProbe,
  629. GpuSceneArrays::GlobalIlluminationProbe::getSingleton().getElementCount(), ctx, *m_giProbeImage, cmdb);
  630. drawNonRenderable(GpuSceneNonRenderableObjectType::kReflectionProbe, GpuSceneArrays::ReflectionProbe::getSingleton().getElementCount(),
  631. ctx, *m_reflectionImage, cmdb);
  632. }
  633. // Physics
  634. if(!!(m_options & DbgOption::kPhysics))
  635. {
  636. class MyPhysicsDebugDrawerInterface final : public PhysicsDebugDrawerInterface
  637. {
  638. public:
  639. RendererDynamicArray<HVec4> m_positions;
  640. RendererDynamicArray<Array<U8, 4>> m_colors;
  641. void drawLines(ConstWeakArray<Vec3> lines, Array<U8, 4> color) override
  642. {
  643. static constexpr U32 kMaxVerts = 1024 * 100;
  644. for(const Vec3& pos : lines)
  645. {
  646. if(m_positions.getSize() >= kMaxVerts)
  647. {
  648. break;
  649. }
  650. m_positions.emplaceBack(HVec4(Vec4(pos.xyz0)));
  651. m_colors.emplaceBack(color);
  652. }
  653. }
  654. } drawerInterface;
  655. PhysicsWorld::getSingleton().debugDraw(drawerInterface);
  656. const U32 vertCount = drawerInterface.m_positions.getSize();
  657. if(vertCount)
  658. {
  659. HVec4* positions;
  660. const BufferView positionBuff =
  661. RebarTransientMemoryPool::getSingleton().allocate(drawerInterface.m_positions.getSizeInBytes(), sizeof(HVec4), positions);
  662. memcpy(positions, drawerInterface.m_positions.getBegin(), drawerInterface.m_positions.getSizeInBytes());
  663. U8* colors;
  664. const BufferView colorBuff =
  665. RebarTransientMemoryPool::getSingleton().allocate(drawerInterface.m_colors.getSizeInBytes(), sizeof(U8) * 4, colors);
  666. memcpy(colors, drawerInterface.m_colors.getBegin(), drawerInterface.m_colors.getSizeInBytes());
  667. ShaderProgramResourceVariantInitInfo variantInitInfo(m_dbgProg);
  668. variantInitInfo.addMutation("OBJECT_TYPE", 0);
  669. variantInitInfo.requestTechniqueAndTypes(ShaderTypeBit::kVertex | ShaderTypeBit::kPixel, "Lines");
  670. const ShaderProgramResourceVariant* variant;
  671. m_dbgProg->getOrCreateVariant(variantInitInfo, variant);
  672. cmdb.bindShaderProgram(&variant->getProgram());
  673. cmdb.setVertexAttribute(VertexAttributeSemantic::kPosition, 0, Format::kR16G16B16A16_Sfloat, 0);
  674. cmdb.setVertexAttribute(VertexAttributeSemantic::kColor, 1, Format::kR8G8B8A8_Unorm, 0);
  675. cmdb.bindVertexBuffer(0, positionBuff, sizeof(HVec4));
  676. cmdb.bindVertexBuffer(1, colorBuff, sizeof(U8) * 4);
  677. cmdb.setFastConstants(&ctx.m_matrices.m_viewProjection, sizeof(ctx.m_matrices.m_viewProjection));
  678. cmdb.draw(PrimitiveTopology::kLines, vertCount);
  679. }
  680. }
  681. // Debug point
  682. if(m_debugPoint.m_position != kMaxF32)
  683. {
  684. struct Consts
  685. {
  686. Mat4 m_mvp;
  687. Vec4 m_color;
  688. } consts;
  689. const Mat4 trf = Mat4(m_debugPoint.m_position, Mat3::getIdentity(), Vec3(m_debugPoint.m_size));
  690. consts.m_mvp = ctx.m_matrices.m_viewProjection * trf;
  691. consts.m_color = m_debugPoint.m_color;
  692. cmdb.setFastConstants(&consts, sizeof(consts));
  693. ShaderProgramResourceVariantInitInfo variantInitInfo(m_dbgProg);
  694. variantInitInfo.addMutation("OBJECT_TYPE", 0);
  695. variantInitInfo.requestTechniqueAndTypes(ShaderTypeBit::kVertex | ShaderTypeBit::kPixel, "Gizmos");
  696. const ShaderProgramResourceVariant* variant;
  697. m_dbgProg->getOrCreateVariant(variantInitInfo, variant);
  698. cmdb.bindShaderProgram(&variant->getProgram());
  699. cmdb.setVertexAttribute(VertexAttributeSemantic::kPosition, 0, Format::kR32G32B32_Sfloat, 0);
  700. cmdb.bindVertexBuffer(0, BufferView(m_debugPoint.m_positionsBuff.get()), sizeof(Vec3));
  701. if(!m_debugPoint.m_enableDepthTest)
  702. {
  703. cmdb.setDepthCompareOperation(CompareOperation::kAlways);
  704. }
  705. cmdb.draw(PrimitiveTopology::kTriangles, sizeof(kCubePositions) / sizeof(F32));
  706. if(!m_debugPoint.m_enableDepthTest)
  707. {
  708. cmdb.setDepthCompareOperation(CompareOperation::kLess);
  709. }
  710. }
  711. if(m_gizmos.m_enabled)
  712. {
  713. cmdb.setDepthCompareOperation(CompareOperation::kAlways);
  714. drawGizmos(m_gizmos.m_trf, ctx, false, cmdb);
  715. }
  716. // Restore state
  717. cmdb.setBlendFactors(0, BlendFactor::kOne, BlendFactor::kZero);
  718. cmdb.setDepthCompareOperation(CompareOperation::kLess);
  719. cmdb.setDepthWrite(true);
  720. });
  721. }
  722. void Dbg::populateRenderGraphObjectPicking(RenderingContext& ctx)
  723. {
  724. RenderGraphBuilder& rgraph = ctx.m_renderGraphDescr;
  725. const GpuVisibilityOutput& visOut = getGBuffer().getVisibilityOutput();
  726. const GpuVisibilityOutput& fvisOut = getForwardShading().getGpuVisibilityOutput();
  727. U32 maxVisibleCount = 0;
  728. if(visOut.containsDrawcalls())
  729. {
  730. maxVisibleCount += U32(visOut.m_visibleAaabbIndicesBuffer.getRange() / sizeof(LodAndGpuSceneRenderableBoundingVolumeIndex));
  731. }
  732. if(fvisOut.containsDrawcalls())
  733. {
  734. maxVisibleCount += U32(fvisOut.m_visibleAaabbIndicesBuffer.getRange() / sizeof(LodAndGpuSceneRenderableBoundingVolumeIndex));
  735. }
  736. const BufferView drawIndirectArgsBuff =
  737. GpuVisibleTransientMemoryPool::getSingleton().allocateStructuredBuffer<DrawIndexedIndirectArgs>(maxVisibleCount);
  738. const BufferView drawCountBuff = GpuVisibleTransientMemoryPool::getSingleton().allocateStructuredBuffer<U32>(1);
  739. const BufferHandle bufferHandle = rgraph.importBuffer(drawCountBuff, BufferUsageBit::kNone);
  740. const BufferView lodAndRenderableIndicesBuff = GpuVisibleTransientMemoryPool::getSingleton().allocateStructuredBuffer<U32>(maxVisibleCount);
  741. // Zero draw count
  742. {
  743. NonGraphicsRenderPass& pass = rgraph.newNonGraphicsRenderPass("Object Picking: Zero");
  744. pass.newBufferDependency(bufferHandle, BufferUsageBit::kCopyDestination);
  745. pass.setWork([drawCountBuff, lodAndRenderableIndicesBuff, drawIndirectArgsBuff](RenderPassWorkContext& rgraphCtx) {
  746. CommandBuffer& cmdb = *rgraphCtx.m_commandBuffer;
  747. cmdb.zeroBuffer(drawCountBuff);
  748. cmdb.zeroBuffer(lodAndRenderableIndicesBuff);
  749. cmdb.zeroBuffer(drawIndirectArgsBuff);
  750. });
  751. }
  752. // Prepare pass
  753. {
  754. NonGraphicsRenderPass& pass = rgraph.newNonGraphicsRenderPass("Object Picking: Prepare");
  755. if(visOut.m_dependency.isValid())
  756. {
  757. pass.newBufferDependency(visOut.m_dependency, BufferUsageBit::kSrvCompute);
  758. }
  759. if(fvisOut.m_dependency.isValid())
  760. {
  761. pass.newBufferDependency(fvisOut.m_dependency, BufferUsageBit::kSrvCompute);
  762. }
  763. pass.newBufferDependency(bufferHandle, BufferUsageBit::kUavCompute);
  764. pass.setWork([this, drawIndirectArgsBuff, drawCountBuff, lodAndRenderableIndicesBuff](RenderPassWorkContext& rgraphCtx) {
  765. CommandBuffer& cmdb = *rgraphCtx.m_commandBuffer;
  766. ShaderProgramResourceVariantInitInfo variantInitInfo(m_dbgProg);
  767. variantInitInfo.addMutation("OBJECT_TYPE", 0);
  768. variantInitInfo.requestTechniqueAndTypes(ShaderTypeBit::kCompute, "PrepareRenderableUuids");
  769. const ShaderProgramResourceVariant* variant;
  770. m_dbgProg->getOrCreateVariant(variantInitInfo, variant);
  771. cmdb.bindShaderProgram(&variant->getProgram());
  772. cmdb.bindSrv(1, 0, GpuSceneArrays::Renderable::getSingleton().getBufferView());
  773. cmdb.bindSrv(2, 0, GpuSceneArrays::MeshLod::getSingleton().getBufferView());
  774. cmdb.bindUav(0, 0, drawIndirectArgsBuff);
  775. cmdb.bindUav(1, 0, drawCountBuff);
  776. cmdb.bindUav(2, 0, lodAndRenderableIndicesBuff);
  777. // Do GBuffer
  778. const GpuVisibilityOutput& visOut = getGBuffer().getVisibilityOutput();
  779. if(visOut.containsDrawcalls())
  780. {
  781. cmdb.bindSrv(0, 0, GpuSceneArrays::RenderableBoundingVolumeGBuffer::getSingleton().getBufferView());
  782. cmdb.bindSrv(3, 0, visOut.m_visibleAaabbIndicesBuffer);
  783. const U32 allAabbCount = GpuSceneArrays::RenderableBoundingVolumeGBuffer::getSingleton().getElementCount();
  784. cmdb.dispatchCompute((allAabbCount + 63) / 64, 1, 1);
  785. }
  786. // Do ForwardShading
  787. const GpuVisibilityOutput& fvisOut = getForwardShading().getGpuVisibilityOutput();
  788. if(fvisOut.containsDrawcalls())
  789. {
  790. cmdb.bindSrv(0, 0, GpuSceneArrays::RenderableBoundingVolumeForward::getSingleton().getBufferView());
  791. cmdb.bindSrv(3, 0, fvisOut.m_visibleAaabbIndicesBuffer);
  792. const U32 allAabbCount = GpuSceneArrays::RenderableBoundingVolumeForward::getSingleton().getElementCount();
  793. cmdb.dispatchCompute((allAabbCount + 63) / 64, 1, 1);
  794. }
  795. });
  796. }
  797. // The render pass that draws the UUIDs to a buffer
  798. const RenderTargetHandle objectPickingRt = rgraph.newRenderTarget(m_objectPickingRtDescr);
  799. m_runCtx.m_objectPickingRt = objectPickingRt;
  800. const RenderTargetHandle objectPickingDepthRt = rgraph.newRenderTarget(m_objectPickingDepthRtDescr);
  801. {
  802. GraphicsRenderPass& pass = rgraph.newGraphicsRenderPass("Object Picking: Draw UUIDs");
  803. pass.newBufferDependency(bufferHandle, BufferUsageBit::kIndirectDraw);
  804. pass.newTextureDependency(objectPickingRt, TextureUsageBit::kRtvDsvWrite);
  805. pass.newTextureDependency(objectPickingDepthRt, TextureUsageBit::kRtvDsvWrite);
  806. GraphicsRenderPassTargetDesc colorRti(objectPickingRt);
  807. colorRti.m_loadOperation = RenderTargetLoadOperation::kClear;
  808. GraphicsRenderPassTargetDesc depthRti(objectPickingDepthRt);
  809. depthRti.m_loadOperation = RenderTargetLoadOperation::kClear;
  810. depthRti.m_clearValue.m_depthStencil.m_depth = 1.0;
  811. depthRti.m_subresource.m_depthStencilAspect = DepthStencilAspectBit::kDepth;
  812. pass.setRenderpassInfo({colorRti}, &depthRti);
  813. pass.setWork(
  814. [this, lodAndRenderableIndicesBuff, &ctx, drawIndirectArgsBuff, drawCountBuff, maxVisibleCount](RenderPassWorkContext& rgraphCtx) {
  815. CommandBuffer& cmdb = *rgraphCtx.m_commandBuffer;
  816. // Set common state
  817. cmdb.setViewport(0, 0, getRenderer().getInternalResolution().x / 2, getRenderer().getInternalResolution().y / 2);
  818. cmdb.setDepthCompareOperation(CompareOperation::kLess);
  819. ShaderProgramResourceVariantInitInfo variantInitInfo(m_dbgProg);
  820. variantInitInfo.addMutation("OBJECT_TYPE", 0);
  821. variantInitInfo.requestTechniqueAndTypes(ShaderTypeBit::kVertex | ShaderTypeBit::kPixel, "RenderableUuids");
  822. const ShaderProgramResourceVariant* variant;
  823. m_dbgProg->getOrCreateVariant(variantInitInfo, variant);
  824. cmdb.bindShaderProgram(&variant->getProgram());
  825. cmdb.bindIndexBuffer(UnifiedGeometryBuffer::getSingleton().getBufferView(), IndexType::kU16);
  826. cmdb.bindSrv(0, 0, lodAndRenderableIndicesBuff);
  827. cmdb.bindSrv(1, 0, GpuSceneArrays::Renderable::getSingleton().getBufferView());
  828. cmdb.bindSrv(2, 0, GpuSceneArrays::MeshLod::getSingleton().getBufferView());
  829. cmdb.bindSrv(3, 0, GpuSceneArrays::Transform::getSingleton().getBufferView());
  830. cmdb.bindSrv(4, 0, UnifiedGeometryBuffer::getSingleton().getBufferView(), Format::kR16G16B16A16_Unorm);
  831. cmdb.bindSrv(5, 0, UnifiedGeometryBuffer::getSingleton().getBufferView(), Format::kR8G8B8A8_Uint);
  832. cmdb.bindSrv(6, 0, UnifiedGeometryBuffer::getSingleton().getBufferView(), Format::kR8G8B8A8_Snorm);
  833. cmdb.bindSrv(7, 0, GpuSceneBuffer::getSingleton().getBufferView());
  834. cmdb.setFastConstants(&ctx.m_matrices.m_viewProjection, sizeof(ctx.m_matrices.m_viewProjection));
  835. cmdb.drawIndexedIndirectCount(PrimitiveTopology::kTriangles, drawIndirectArgsBuff, sizeof(DrawIndexedIndirectArgs), drawCountBuff,
  836. maxVisibleCount);
  837. // Draw gizmos
  838. if(m_gizmos.m_enabled)
  839. {
  840. cmdb.setDepthCompareOperation(CompareOperation::kAlways);
  841. drawGizmos(m_gizmos.m_trf, ctx, true, cmdb);
  842. cmdb.setDepthCompareOperation(CompareOperation::kLess);
  843. }
  844. });
  845. }
  846. // Read the UUID RT to get the UUID that is over the mouse
  847. {
  848. U32 uuid;
  849. PtrSize dataOut;
  850. getRenderer().getReadbackManager().readMostRecentData(m_readback, &uuid, sizeof(uuid), dataOut);
  851. m_runCtx.m_objPickingRes = {};
  852. if(dataOut)
  853. {
  854. if(uuid & (1u << 31u))
  855. {
  856. // It's a gizmo
  857. uuid &= ~(1u << 31u);
  858. if(uuid < 3)
  859. {
  860. m_runCtx.m_objPickingRes.m_translationAxis = uuid;
  861. }
  862. else if(uuid < 6)
  863. {
  864. m_runCtx.m_objPickingRes.m_scaleAxis = uuid - 3;
  865. }
  866. else
  867. {
  868. ANKI_ASSERT(uuid - 6 < 3);
  869. m_runCtx.m_objPickingRes.m_rotationAxis = uuid - 6;
  870. }
  871. }
  872. else
  873. {
  874. m_runCtx.m_objPickingRes.m_sceneNodeUuid = uuid;
  875. }
  876. }
  877. const BufferView readbackBuff = getRenderer().getReadbackManager().allocateStructuredBuffer<U32>(m_readback, 1);
  878. NonGraphicsRenderPass& pass = rgraph.newNonGraphicsRenderPass("Object Picking: Picking");
  879. pass.newTextureDependency(objectPickingRt, TextureUsageBit::kSrvCompute);
  880. pass.setWork([this, readbackBuff, objectPickingRt](RenderPassWorkContext& rgraphCtx) {
  881. CommandBuffer& cmdb = *rgraphCtx.m_commandBuffer;
  882. ShaderProgramResourceVariantInitInfo variantInitInfo(m_dbgProg);
  883. variantInitInfo.addMutation("OBJECT_TYPE", 0);
  884. variantInitInfo.requestTechniqueAndTypes(ShaderTypeBit::kCompute, "RenderableUuidsPick");
  885. const ShaderProgramResourceVariant* variant;
  886. m_dbgProg->getOrCreateVariant(variantInitInfo, variant);
  887. cmdb.bindShaderProgram(&variant->getProgram());
  888. rgraphCtx.bindSrv(0, 0, objectPickingRt);
  889. cmdb.bindUav(0, 0, readbackBuff);
  890. Vec2 mousePos = Input::getSingleton().getMousePositionNdc();
  891. mousePos.y = -mousePos.y;
  892. mousePos = mousePos / 2.0f + 0.5f;
  893. mousePos *= Vec2(getRenderer().getInternalResolution() / 2);
  894. const UVec4 consts(UVec2(mousePos), 0u, 0u);
  895. cmdb.setFastConstants(&consts, sizeof(consts));
  896. cmdb.dispatchCompute(1, 1, 1);
  897. });
  898. }
  899. }
  900. void Dbg::drawGizmos(const Mat3x4& worldTransform, const RenderingContext& ctx, Bool objectPicking, CommandBuffer& cmdb) const
  901. {
  902. // Draw a gizmo
  903. auto draw = [&](Vec4 color, U32 id, Euler rotation, Vec3 scale, Buffer& positionsBuff, Buffer& indexBuff) {
  904. struct Consts
  905. {
  906. Mat4 m_mvp;
  907. Vec4 m_color;
  908. } consts;
  909. consts.m_mvp = ctx.m_matrices.m_viewProjection * Mat4(worldTransform, Vec4(0.0f, 0.0f, 0.0f, 1.0f)) * Mat4(Vec3(0.0f), Mat3(rotation), scale);
  910. consts.m_color = color;
  911. struct PickingConsts
  912. {
  913. Mat4 m_mvp;
  914. UVec3 m_padding;
  915. U32 m_id;
  916. } constsPicking;
  917. constsPicking.m_mvp = consts.m_mvp;
  918. constsPicking.m_id = id;
  919. if(objectPicking)
  920. {
  921. cmdb.setFastConstants(&constsPicking, sizeof(constsPicking));
  922. }
  923. else
  924. {
  925. cmdb.setFastConstants(&consts, sizeof(consts));
  926. }
  927. cmdb.setVertexAttribute(VertexAttributeSemantic::kPosition, 0, Format::kR32G32B32_Sfloat, 0);
  928. cmdb.bindVertexBuffer(0, BufferView(&positionsBuff), sizeof(Vec3));
  929. cmdb.bindIndexBuffer(BufferView(&indexBuff), IndexType::kU16);
  930. cmdb.drawIndexed(PrimitiveTopology::kTriangles, U32(indexBuff.getSize() / sizeof(U16)));
  931. };
  932. // Draw all gizmos of an axis
  933. auto drawAxis = [&](Euler rot, Vec3 color, U32 id) {
  934. const F32 alpha = 1.0f;
  935. draw(Vec4(color, alpha), id + 0, rot, Vec3(1.0f), *m_gizmos.m_arrowPositions, *m_gizmos.m_arrowIndices);
  936. draw(Vec4(color, alpha), id + 3, rot, Vec3(1.0f), *m_gizmos.m_scalePositions, *m_gizmos.m_scaleIndices);
  937. draw(Vec4(color, alpha), id + 6, rot, Vec3(0.4f), *m_gizmos.m_ringPositions, *m_gizmos.m_ringIndices);
  938. };
  939. ShaderProgramResourceVariantInitInfo variantInitInfo(m_dbgProg);
  940. variantInitInfo.addMutation("OBJECT_TYPE", 0);
  941. variantInitInfo.requestTechniqueAndTypes(ShaderTypeBit::kVertex | ShaderTypeBit::kPixel, (objectPicking) ? "GizmosPick" : "Gizmos");
  942. const ShaderProgramResourceVariant* variant;
  943. m_dbgProg->getOrCreateVariant(variantInitInfo, variant);
  944. cmdb.bindShaderProgram(&variant->getProgram());
  945. const Array<Vec3, 3> axis = {worldTransform.getXAxis().normalize(), worldTransform.getYAxis().normalize(), worldTransform.getZAxis().normalize()};
  946. const Array<Euler, 3> rotations = {Euler(0.0f, kPi / 2.0f, 0.0f), Euler(-kPi / 2.0f, 0.0f, 0.0f), Euler(0.0f, 0.0f, 0.0f)};
  947. const Array<Vec3, 3> colors = {Vec3(1.0f, 0.0f, 0.0f), Vec3(0.0f, 1.0f, 0.0f), Vec3(0.0f, 0.0f, 1.0f)};
  948. const Vec3 viewDir = ctx.m_matrices.m_cameraTransform.getZAxis();
  949. // Since we don't use depth test draw the axis that points to the camera more
  950. struct DotProduct
  951. {
  952. F32 m_dot;
  953. U32 m_axis;
  954. };
  955. Array<DotProduct, 3> dotProducts;
  956. for(U32 i = 0; i < 3; ++i)
  957. {
  958. dotProducts[i].m_axis = i;
  959. dotProducts[i].m_dot = viewDir.dot(axis[i]);
  960. }
  961. std::sort(dotProducts.getBegin(), dotProducts.getEnd(), [](const DotProduct& a, const DotProduct& b) {
  962. return a.m_dot < b.m_dot;
  963. });
  964. for(U32 i = 0; i < 3; ++i)
  965. {
  966. const U32 id = (1u << 31u);
  967. const U32 axisi = dotProducts[i].m_axis;
  968. drawAxis(rotations[axisi], colors[axisi], id | axisi);
  969. }
  970. }
  971. } // end namespace anki