visual_server.cpp 132 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809
  1. /**************************************************************************/
  2. /* visual_server.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "visual_server.h"
  31. #include "core/engine.h"
  32. #include "core/math/vertex_cache_optimizer.h"
  33. #include "core/method_bind_ext.gen.inc"
  34. #include "core/project_settings.h"
  35. #ifdef TOOLS_ENABLED
  36. #include "editor/editor_settings.h"
  37. #endif
  38. VisualServer *VisualServer::singleton = nullptr;
  39. VisualServer *(*VisualServer::create_func)() = nullptr;
  40. VisualServer *VisualServer::get_singleton() {
  41. return singleton;
  42. }
  43. VisualServer *VisualServer::create() {
  44. ERR_FAIL_COND_V(singleton, nullptr);
  45. if (create_func) {
  46. return create_func();
  47. }
  48. return nullptr;
  49. }
  50. RID VisualServer::texture_create_from_image(const Ref<Image> &p_image, uint32_t p_flags) {
  51. ERR_FAIL_COND_V(!p_image.is_valid(), RID());
  52. RID texture = texture_create();
  53. texture_allocate(texture, p_image->get_width(), p_image->get_height(), 0, p_image->get_format(), VS::TEXTURE_TYPE_2D, p_flags); //if it has mipmaps, use, else generate
  54. ERR_FAIL_COND_V(!texture.is_valid(), texture);
  55. texture_set_data(texture, p_image);
  56. return texture;
  57. }
  58. Array VisualServer::_texture_debug_usage_bind() {
  59. List<TextureInfo> list;
  60. texture_debug_usage(&list);
  61. Array arr;
  62. for (const List<TextureInfo>::Element *E = list.front(); E; E = E->next()) {
  63. Dictionary dict;
  64. dict["texture"] = E->get().texture;
  65. dict["width"] = E->get().width;
  66. dict["height"] = E->get().height;
  67. dict["depth"] = E->get().depth;
  68. dict["format"] = E->get().format;
  69. dict["bytes"] = E->get().bytes;
  70. dict["path"] = E->get().path;
  71. arr.push_back(dict);
  72. }
  73. return arr;
  74. }
  75. Array VisualServer::_shader_get_param_list_bind(RID p_shader) const {
  76. List<PropertyInfo> l;
  77. shader_get_param_list(p_shader, &l);
  78. return convert_property_list(&l);
  79. }
  80. static Array to_array(const Vector<ObjectID> &ids) {
  81. Array a;
  82. a.resize(ids.size());
  83. for (int i = 0; i < ids.size(); ++i) {
  84. a[i] = ids[i];
  85. }
  86. return a;
  87. }
  88. Array VisualServer::_instances_cull_aabb_bind(const AABB &p_aabb, RID p_scenario) const {
  89. Vector<ObjectID> ids = instances_cull_aabb(p_aabb, p_scenario);
  90. return to_array(ids);
  91. }
  92. Array VisualServer::_instances_cull_ray_bind(const Vector3 &p_from, const Vector3 &p_to, RID p_scenario) const {
  93. Vector<ObjectID> ids = instances_cull_ray(p_from, p_to, p_scenario);
  94. return to_array(ids);
  95. }
  96. Array VisualServer::_instances_cull_convex_bind(const Array &p_convex, RID p_scenario) const {
  97. Vector<Plane> planes;
  98. for (int i = 0; i < p_convex.size(); ++i) {
  99. Variant v = p_convex[i];
  100. ERR_FAIL_COND_V(v.get_type() != Variant::PLANE, Array());
  101. planes.push_back(v);
  102. }
  103. Vector<ObjectID> ids = instances_cull_convex(planes, p_scenario);
  104. return to_array(ids);
  105. }
  106. RID VisualServer::get_test_texture() {
  107. if (test_texture.is_valid()) {
  108. return test_texture;
  109. };
  110. #define TEST_TEXTURE_SIZE 256
  111. PoolVector<uint8_t> test_data;
  112. test_data.resize(TEST_TEXTURE_SIZE * TEST_TEXTURE_SIZE * 3);
  113. {
  114. PoolVector<uint8_t>::Write w = test_data.write();
  115. for (int x = 0; x < TEST_TEXTURE_SIZE; x++) {
  116. for (int y = 0; y < TEST_TEXTURE_SIZE; y++) {
  117. Color c;
  118. int r = 255 - (x + y) / 2;
  119. if ((x % (TEST_TEXTURE_SIZE / 8)) < 2 || (y % (TEST_TEXTURE_SIZE / 8)) < 2) {
  120. c.r = y;
  121. c.g = r;
  122. c.b = x;
  123. } else {
  124. c.r = r;
  125. c.g = x;
  126. c.b = y;
  127. }
  128. w[(y * TEST_TEXTURE_SIZE + x) * 3 + 0] = uint8_t(CLAMP(c.r * 255, 0, 255));
  129. w[(y * TEST_TEXTURE_SIZE + x) * 3 + 1] = uint8_t(CLAMP(c.g * 255, 0, 255));
  130. w[(y * TEST_TEXTURE_SIZE + x) * 3 + 2] = uint8_t(CLAMP(c.b * 255, 0, 255));
  131. }
  132. }
  133. }
  134. Ref<Image> data = memnew(Image(TEST_TEXTURE_SIZE, TEST_TEXTURE_SIZE, false, Image::FORMAT_RGB8, test_data));
  135. test_texture = RID_PRIME(texture_create_from_image(data));
  136. return test_texture;
  137. }
  138. void VisualServer::_free_internal_rids() {
  139. if (test_texture.is_valid()) {
  140. free(test_texture);
  141. }
  142. if (white_texture.is_valid()) {
  143. free(white_texture);
  144. }
  145. if (test_material.is_valid()) {
  146. free(test_material);
  147. }
  148. }
  149. RID VisualServer::_make_test_cube() {
  150. PoolVector<Vector3> vertices;
  151. PoolVector<Vector3> normals;
  152. PoolVector<float> tangents;
  153. PoolVector<Vector3> uvs;
  154. #define ADD_VTX(m_idx) \
  155. vertices.push_back(face_points[m_idx]); \
  156. normals.push_back(normal_points[m_idx]); \
  157. tangents.push_back(normal_points[m_idx][1]); \
  158. tangents.push_back(normal_points[m_idx][2]); \
  159. tangents.push_back(normal_points[m_idx][0]); \
  160. tangents.push_back(1.0); \
  161. uvs.push_back(Vector3(uv_points[m_idx * 2 + 0], uv_points[m_idx * 2 + 1], 0));
  162. for (int i = 0; i < 6; i++) {
  163. Vector3 face_points[4];
  164. Vector3 normal_points[4];
  165. float uv_points[8] = { 0, 0, 0, 1, 1, 1, 1, 0 };
  166. for (int j = 0; j < 4; j++) {
  167. float v[3];
  168. v[0] = 1.0;
  169. v[1] = 1 - 2 * ((j >> 1) & 1);
  170. v[2] = v[1] * (1 - 2 * (j & 1));
  171. for (int k = 0; k < 3; k++) {
  172. if (i < 3) {
  173. face_points[j][(i + k) % 3] = v[k];
  174. } else {
  175. face_points[3 - j][(i + k) % 3] = -v[k];
  176. }
  177. }
  178. normal_points[j] = Vector3();
  179. normal_points[j][i % 3] = (i >= 3 ? -1 : 1);
  180. }
  181. //tri 1
  182. ADD_VTX(0);
  183. ADD_VTX(1);
  184. ADD_VTX(2);
  185. //tri 2
  186. ADD_VTX(2);
  187. ADD_VTX(3);
  188. ADD_VTX(0);
  189. }
  190. RID test_cube = mesh_create();
  191. Array d;
  192. d.resize(VS::ARRAY_MAX);
  193. d[VisualServer::ARRAY_NORMAL] = normals;
  194. d[VisualServer::ARRAY_TANGENT] = tangents;
  195. d[VisualServer::ARRAY_TEX_UV] = uvs;
  196. d[VisualServer::ARRAY_VERTEX] = vertices;
  197. PoolVector<int> indices;
  198. indices.resize(vertices.size());
  199. for (int i = 0; i < vertices.size(); i++) {
  200. indices.set(i, i);
  201. }
  202. d[VisualServer::ARRAY_INDEX] = indices;
  203. mesh_add_surface_from_arrays(test_cube, PRIMITIVE_TRIANGLES, d);
  204. /*
  205. test_material = fixed_material_create();
  206. //material_set_flag(material, MATERIAL_FLAG_BILLBOARD_TOGGLE,true);
  207. fixed_material_set_texture( test_material, FIXED_MATERIAL_PARAM_DIFFUSE, get_test_texture() );
  208. fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_SPECULAR_EXP, 70 );
  209. fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_EMISSION, Color(0.2,0.2,0.2) );
  210. fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_DIFFUSE, Color(1, 1, 1) );
  211. fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_SPECULAR, Color(1,1,1) );
  212. */
  213. mesh_surface_set_material(test_cube, 0, test_material);
  214. return test_cube;
  215. }
  216. RID VisualServer::make_sphere_mesh(int p_lats, int p_lons, float p_radius) {
  217. PoolVector<Vector3> vertices;
  218. PoolVector<Vector3> normals;
  219. for (int i = 1; i <= p_lats; i++) {
  220. double lat0 = Math_PI * (-0.5 + (double)(i - 1) / p_lats);
  221. double z0 = Math::sin(lat0);
  222. double zr0 = Math::cos(lat0);
  223. double lat1 = Math_PI * (-0.5 + (double)i / p_lats);
  224. double z1 = Math::sin(lat1);
  225. double zr1 = Math::cos(lat1);
  226. for (int j = p_lons; j >= 1; j--) {
  227. double lng0 = 2 * Math_PI * (double)(j - 1) / p_lons;
  228. double x0 = Math::cos(lng0);
  229. double y0 = Math::sin(lng0);
  230. double lng1 = 2 * Math_PI * (double)(j) / p_lons;
  231. double x1 = Math::cos(lng1);
  232. double y1 = Math::sin(lng1);
  233. Vector3 v[4] = {
  234. Vector3(x1 * zr0, z0, y1 * zr0),
  235. Vector3(x1 * zr1, z1, y1 * zr1),
  236. Vector3(x0 * zr1, z1, y0 * zr1),
  237. Vector3(x0 * zr0, z0, y0 * zr0)
  238. };
  239. #define ADD_POINT(m_idx) \
  240. normals.push_back(v[m_idx]); \
  241. vertices.push_back(v[m_idx] * p_radius);
  242. ADD_POINT(0);
  243. ADD_POINT(1);
  244. ADD_POINT(2);
  245. ADD_POINT(2);
  246. ADD_POINT(3);
  247. ADD_POINT(0);
  248. }
  249. }
  250. RID mesh = mesh_create();
  251. Array d;
  252. d.resize(VS::ARRAY_MAX);
  253. d[ARRAY_VERTEX] = vertices;
  254. d[ARRAY_NORMAL] = normals;
  255. mesh_add_surface_from_arrays(mesh, PRIMITIVE_TRIANGLES, d);
  256. return mesh;
  257. }
  258. RID VisualServer::get_white_texture() {
  259. if (white_texture.is_valid()) {
  260. return white_texture;
  261. }
  262. PoolVector<uint8_t> wt;
  263. wt.resize(16 * 3);
  264. {
  265. PoolVector<uint8_t>::Write w = wt.write();
  266. for (int i = 0; i < 16 * 3; i++) {
  267. w[i] = 255;
  268. }
  269. }
  270. Ref<Image> white = memnew(Image(4, 4, 0, Image::FORMAT_RGB8, wt));
  271. white_texture = RID_PRIME(texture_create());
  272. texture_allocate(white_texture, 4, 4, 0, Image::FORMAT_RGB8, TEXTURE_TYPE_2D);
  273. texture_set_data(white_texture, white);
  274. return white_texture;
  275. }
  276. #define SMALL_VEC2 Vector2(0.00001, 0.00001)
  277. #define SMALL_VEC3 Vector3(0.00001, 0.00001, 0.00001)
  278. // Maps normalized vector to an octahedron projected onto the cartesian plane
  279. // Resulting 2D vector in range [-1, 1]
  280. // See http://jcgt.org/published/0003/02/01/ for details
  281. Vector2 VisualServer::norm_to_oct(const Vector3 v) {
  282. const float L1Norm = Math::absf(v.x) + Math::absf(v.y) + Math::absf(v.z);
  283. // NOTE: this will mean it decompresses to 0,0,1
  284. // Discussed heavily here: https://github.com/godotengine/godot/pull/51268 as to why we did this
  285. if (Math::is_zero_approx(L1Norm)) {
  286. WARN_PRINT_ONCE("Octahedral compression cannot be used to compress a zero-length vector, please use normalized normal values or disable octahedral compression");
  287. return Vector2(0, 0);
  288. }
  289. const float invL1Norm = 1.0f / L1Norm;
  290. Vector2 res;
  291. if (v.z < 0.0f) {
  292. res.x = (1.0f - Math::absf(v.y * invL1Norm)) * SGN(v.x);
  293. res.y = (1.0f - Math::absf(v.x * invL1Norm)) * SGN(v.y);
  294. } else {
  295. res.x = v.x * invL1Norm;
  296. res.y = v.y * invL1Norm;
  297. }
  298. return res;
  299. }
  300. // Maps normalized tangent vector to an octahedron projected onto the cartesian plane
  301. // Encodes the tangent vector sign in the second component of the returned Vector2 for use in shaders
  302. // high_precision specifies whether the encoding will be 32 bit (true) or 16 bit (false)
  303. // Resulting 2D vector in range [-1, 1]
  304. // See http://jcgt.org/published/0003/02/01/ for details
  305. Vector2 VisualServer::tangent_to_oct(const Vector3 v, const float sign, const bool high_precision) {
  306. float bias = high_precision ? 1.0f / 32767 : 1.0f / 127;
  307. Vector2 res = norm_to_oct(v);
  308. res.y = res.y * 0.5f + 0.5f;
  309. res.y = MAX(res.y, bias) * SGN(sign);
  310. return res;
  311. }
  312. // Convert Octohedron-mapped normalized vector back to Cartesian
  313. // Assumes normalized format (elements of v within range [-1, 1])
  314. Vector3 VisualServer::oct_to_norm(const Vector2 v) {
  315. Vector3 res(v.x, v.y, 1 - (Math::absf(v.x) + Math::absf(v.y)));
  316. float t = MAX(-res.z, 0.0f);
  317. res.x += t * -SGN(res.x);
  318. res.y += t * -SGN(res.y);
  319. return res.normalized();
  320. }
  321. // Convert Octohedron-mapped normalized tangent vector back to Cartesian
  322. // out_sign provides the direction for the original cartesian tangent
  323. // Assumes normalized format (elements of v within range [-1, 1])
  324. Vector3 VisualServer::oct_to_tangent(const Vector2 v, float *out_sign) {
  325. Vector2 v_decompressed = v;
  326. v_decompressed.y = Math::absf(v_decompressed.y) * 2 - 1;
  327. Vector3 res = oct_to_norm(v_decompressed);
  328. *out_sign = SGN(v[1]);
  329. return res;
  330. }
  331. Error VisualServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint32_t *p_offsets, uint32_t *p_stride, PoolVector<uint8_t> &r_vertex_array, int p_vertex_array_len, PoolVector<uint8_t> &r_index_array, int p_index_array_len, AABB &r_aabb, Vector<AABB> &r_bone_aabb) {
  332. PoolVector<uint8_t>::Write vw = r_vertex_array.write();
  333. PoolVector<uint8_t>::Write iw;
  334. if (r_index_array.size()) {
  335. iw = r_index_array.write();
  336. }
  337. int max_bone = 0;
  338. for (int ai = 0; ai < VS::ARRAY_MAX; ai++) {
  339. if (!(p_format & (1 << ai))) { // no array
  340. continue;
  341. }
  342. switch (ai) {
  343. case VS::ARRAY_VERTEX: {
  344. if (p_format & VS::ARRAY_FLAG_USE_2D_VERTICES) {
  345. PoolVector<Vector2> array = p_arrays[ai];
  346. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  347. PoolVector<Vector2>::Read read = array.read();
  348. const Vector2 *src = read.ptr();
  349. // setting vertices means regenerating the AABB
  350. Rect2 aabb;
  351. if (p_format & ARRAY_COMPRESS_VERTEX) {
  352. for (int i = 0; i < p_vertex_array_len; i++) {
  353. uint16_t vector[2] = { Math::make_half_float(src[i].x), Math::make_half_float(src[i].y) };
  354. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, sizeof(uint16_t) * 2);
  355. if (i == 0) {
  356. aabb = Rect2(src[i], SMALL_VEC2); //must have a bit of size
  357. } else {
  358. aabb.expand_to(src[i]);
  359. }
  360. }
  361. } else {
  362. for (int i = 0; i < p_vertex_array_len; i++) {
  363. float vector[2] = { src[i].x, src[i].y };
  364. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, sizeof(float) * 2);
  365. if (i == 0) {
  366. aabb = Rect2(src[i], SMALL_VEC2); //must have a bit of size
  367. } else {
  368. aabb.expand_to(src[i]);
  369. }
  370. }
  371. }
  372. r_aabb = AABB(Vector3(aabb.position.x, aabb.position.y, 0), Vector3(aabb.size.x, aabb.size.y, 0));
  373. } else {
  374. PoolVector<Vector3> array = p_arrays[ai];
  375. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  376. PoolVector<Vector3>::Read read = array.read();
  377. const Vector3 *src = read.ptr();
  378. // setting vertices means regenerating the AABB
  379. AABB aabb;
  380. if (p_format & ARRAY_COMPRESS_VERTEX) {
  381. for (int i = 0; i < p_vertex_array_len; i++) {
  382. uint16_t vector[4] = { Math::make_half_float(src[i].x), Math::make_half_float(src[i].y), Math::make_half_float(src[i].z), Math::make_half_float(1.0) };
  383. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, sizeof(uint16_t) * 4);
  384. if (i == 0) {
  385. aabb = AABB(src[i], SMALL_VEC3);
  386. } else {
  387. aabb.expand_to(src[i]);
  388. }
  389. }
  390. } else {
  391. for (int i = 0; i < p_vertex_array_len; i++) {
  392. float vector[3] = { src[i].x, src[i].y, src[i].z };
  393. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, sizeof(float) * 3);
  394. if (i == 0) {
  395. aabb = AABB(src[i], SMALL_VEC3);
  396. } else {
  397. aabb.expand_to(src[i]);
  398. }
  399. }
  400. }
  401. r_aabb = aabb;
  402. }
  403. } break;
  404. case VS::ARRAY_NORMAL: {
  405. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_VECTOR3_ARRAY, ERR_INVALID_PARAMETER);
  406. PoolVector<Vector3> array = p_arrays[ai];
  407. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  408. PoolVector<Vector3>::Read read = array.read();
  409. const Vector3 *src = read.ptr();
  410. // setting vertices means regenerating the AABB
  411. if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  412. if ((p_format & ARRAY_COMPRESS_NORMAL) && (p_format & ARRAY_FORMAT_TANGENT) && (p_format & ARRAY_COMPRESS_TANGENT)) {
  413. for (int i = 0; i < p_vertex_array_len; i++) {
  414. Vector2 res = norm_to_oct(src[i]);
  415. int8_t vector[2] = {
  416. (int8_t)CLAMP(res.x * 127, -128, 127),
  417. (int8_t)CLAMP(res.y * 127, -128, 127),
  418. };
  419. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, 2);
  420. }
  421. } else {
  422. for (int i = 0; i < p_vertex_array_len; i++) {
  423. Vector2 res = norm_to_oct(src[i]);
  424. int16_t vector[2] = {
  425. (int16_t)CLAMP(res.x * 32767, -32768, 32767),
  426. (int16_t)CLAMP(res.y * 32767, -32768, 32767),
  427. };
  428. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, 4);
  429. }
  430. }
  431. } else {
  432. if (p_format & ARRAY_COMPRESS_NORMAL) {
  433. for (int i = 0; i < p_vertex_array_len; i++) {
  434. int8_t vector[4] = {
  435. (int8_t)CLAMP(src[i].x * 127, -128, 127),
  436. (int8_t)CLAMP(src[i].y * 127, -128, 127),
  437. (int8_t)CLAMP(src[i].z * 127, -128, 127),
  438. 0,
  439. };
  440. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, 4);
  441. }
  442. } else {
  443. for (int i = 0; i < p_vertex_array_len; i++) {
  444. float vector[3] = { src[i].x, src[i].y, src[i].z };
  445. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, 3 * 4);
  446. }
  447. }
  448. }
  449. } break;
  450. case VS::ARRAY_TANGENT: {
  451. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_REAL_ARRAY, ERR_INVALID_PARAMETER);
  452. PoolVector<real_t> array = p_arrays[ai];
  453. ERR_FAIL_COND_V(array.size() != p_vertex_array_len * 4, ERR_INVALID_PARAMETER);
  454. PoolVector<real_t>::Read read = array.read();
  455. const real_t *src = read.ptr();
  456. if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  457. if (p_format & ARRAY_COMPRESS_TANGENT) {
  458. for (int i = 0; i < p_vertex_array_len; i++) {
  459. Vector3 source(src[i * 4 + 0], src[i * 4 + 1], src[i * 4 + 2]);
  460. Vector2 res = tangent_to_oct(source, src[i * 4 + 3], false);
  461. int8_t vector[2] = {
  462. (int8_t)CLAMP(res.x * 127, -128, 127),
  463. (int8_t)CLAMP(res.y * 127, -128, 127)
  464. };
  465. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, 2);
  466. }
  467. } else {
  468. for (int i = 0; i < p_vertex_array_len; i++) {
  469. Vector3 source(src[i * 4 + 0], src[i * 4 + 1], src[i * 4 + 2]);
  470. Vector2 res = tangent_to_oct(source, src[i * 4 + 3], true);
  471. int16_t vector[2] = {
  472. (int16_t)CLAMP(res.x * 32767, -32768, 32767),
  473. (int16_t)CLAMP(res.y * 32767, -32768, 32767)
  474. };
  475. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, 4);
  476. }
  477. }
  478. } else {
  479. if (p_format & ARRAY_COMPRESS_TANGENT) {
  480. for (int i = 0; i < p_vertex_array_len; i++) {
  481. int8_t xyzw[4] = {
  482. (int8_t)CLAMP(src[i * 4 + 0] * 127, -128, 127),
  483. (int8_t)CLAMP(src[i * 4 + 1] * 127, -128, 127),
  484. (int8_t)CLAMP(src[i * 4 + 2] * 127, -128, 127),
  485. (int8_t)CLAMP(src[i * 4 + 3] * 127, -128, 127)
  486. };
  487. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], xyzw, 4);
  488. }
  489. } else {
  490. for (int i = 0; i < p_vertex_array_len; i++) {
  491. float xyzw[4] = {
  492. src[i * 4 + 0],
  493. src[i * 4 + 1],
  494. src[i * 4 + 2],
  495. src[i * 4 + 3]
  496. };
  497. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], xyzw, 4 * 4);
  498. }
  499. }
  500. }
  501. } break;
  502. case VS::ARRAY_COLOR: {
  503. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_COLOR_ARRAY, ERR_INVALID_PARAMETER);
  504. PoolVector<Color> array = p_arrays[ai];
  505. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  506. PoolVector<Color>::Read read = array.read();
  507. const Color *src = read.ptr();
  508. if (p_format & ARRAY_COMPRESS_COLOR) {
  509. for (int i = 0; i < p_vertex_array_len; i++) {
  510. uint8_t colors[4];
  511. for (int j = 0; j < 4; j++) {
  512. colors[j] = CLAMP(int((src[i][j]) * 255.0), 0, 255);
  513. }
  514. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], colors, 4);
  515. }
  516. } else {
  517. for (int i = 0; i < p_vertex_array_len; i++) {
  518. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], &src[i], 4 * 4);
  519. }
  520. }
  521. } break;
  522. case VS::ARRAY_TEX_UV: {
  523. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_VECTOR3_ARRAY && p_arrays[ai].get_type() != Variant::POOL_VECTOR2_ARRAY, ERR_INVALID_PARAMETER);
  524. PoolVector<Vector2> array = p_arrays[ai];
  525. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  526. PoolVector<Vector2>::Read read = array.read();
  527. const Vector2 *src = read.ptr();
  528. if (p_format & ARRAY_COMPRESS_TEX_UV) {
  529. for (int i = 0; i < p_vertex_array_len; i++) {
  530. uint16_t uv[2] = { Math::make_half_float(src[i].x), Math::make_half_float(src[i].y) };
  531. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], uv, 2 * 2);
  532. }
  533. } else {
  534. for (int i = 0; i < p_vertex_array_len; i++) {
  535. float uv[2] = { src[i].x, src[i].y };
  536. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], uv, 2 * 4);
  537. }
  538. }
  539. } break;
  540. case VS::ARRAY_TEX_UV2: {
  541. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_VECTOR3_ARRAY && p_arrays[ai].get_type() != Variant::POOL_VECTOR2_ARRAY, ERR_INVALID_PARAMETER);
  542. PoolVector<Vector2> array = p_arrays[ai];
  543. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  544. PoolVector<Vector2>::Read read = array.read();
  545. const Vector2 *src = read.ptr();
  546. if (p_format & ARRAY_COMPRESS_TEX_UV2) {
  547. for (int i = 0; i < p_vertex_array_len; i++) {
  548. uint16_t uv[2] = { Math::make_half_float(src[i].x), Math::make_half_float(src[i].y) };
  549. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], uv, 2 * 2);
  550. }
  551. } else {
  552. for (int i = 0; i < p_vertex_array_len; i++) {
  553. float uv[2] = { src[i].x, src[i].y };
  554. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], uv, 2 * 4);
  555. }
  556. }
  557. } break;
  558. case VS::ARRAY_WEIGHTS: {
  559. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_REAL_ARRAY, ERR_INVALID_PARAMETER);
  560. PoolVector<real_t> array = p_arrays[ai];
  561. ERR_FAIL_COND_V(array.size() != p_vertex_array_len * VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER);
  562. PoolVector<real_t>::Read read = array.read();
  563. const real_t *src = read.ptr();
  564. if (p_format & ARRAY_COMPRESS_WEIGHTS) {
  565. for (int i = 0; i < p_vertex_array_len; i++) {
  566. uint16_t data[VS::ARRAY_WEIGHTS_SIZE];
  567. for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
  568. data[j] = CLAMP(src[i * VS::ARRAY_WEIGHTS_SIZE + j] * 65535, 0, 65535);
  569. }
  570. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], data, 2 * 4);
  571. }
  572. } else {
  573. for (int i = 0; i < p_vertex_array_len; i++) {
  574. float data[VS::ARRAY_WEIGHTS_SIZE];
  575. for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
  576. data[j] = src[i * VS::ARRAY_WEIGHTS_SIZE + j];
  577. }
  578. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], data, 4 * 4);
  579. }
  580. }
  581. } break;
  582. case VS::ARRAY_BONES: {
  583. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_INT_ARRAY && p_arrays[ai].get_type() != Variant::POOL_REAL_ARRAY, ERR_INVALID_PARAMETER);
  584. PoolVector<int> array = p_arrays[ai];
  585. ERR_FAIL_COND_V(array.size() != p_vertex_array_len * VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER);
  586. PoolVector<int>::Read read = array.read();
  587. const int *src = read.ptr();
  588. if (!(p_format & ARRAY_FLAG_USE_16_BIT_BONES)) {
  589. for (int i = 0; i < p_vertex_array_len; i++) {
  590. uint8_t data[VS::ARRAY_WEIGHTS_SIZE];
  591. for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
  592. data[j] = CLAMP(src[i * VS::ARRAY_WEIGHTS_SIZE + j], 0, 255);
  593. max_bone = MAX(data[j], max_bone);
  594. }
  595. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], data, 4);
  596. }
  597. } else {
  598. for (int i = 0; i < p_vertex_array_len; i++) {
  599. uint16_t data[VS::ARRAY_WEIGHTS_SIZE];
  600. for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
  601. data[j] = src[i * VS::ARRAY_WEIGHTS_SIZE + j];
  602. max_bone = MAX(data[j], max_bone);
  603. }
  604. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], data, 2 * 4);
  605. }
  606. }
  607. } break;
  608. case VS::ARRAY_INDEX: {
  609. ERR_FAIL_COND_V(p_index_array_len <= 0, ERR_INVALID_DATA);
  610. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_INT_ARRAY, ERR_INVALID_PARAMETER);
  611. PoolVector<int> indices = p_arrays[ai];
  612. ERR_FAIL_COND_V(indices.size() == 0, ERR_INVALID_PARAMETER);
  613. ERR_FAIL_COND_V(indices.size() != p_index_array_len, ERR_INVALID_PARAMETER);
  614. // Vertex cache optimization?
  615. if (p_format & ARRAY_FLAG_USE_VERTEX_CACHE_OPTIMIZATION) {
  616. // Expecting triangles.
  617. ERR_FAIL_COND_V((indices.size() % 3) != 0, ERR_INVALID_PARAMETER);
  618. VertexCacheOptimizer opt;
  619. opt.reorder_indices_pool(indices, indices.size() / 3, p_vertex_array_len);
  620. }
  621. /* determine whether using 16 or 32 bits indices */
  622. PoolVector<int>::Read read = indices.read();
  623. const int *src = read.ptr();
  624. for (int i = 0; i < p_index_array_len; i++) {
  625. if (p_vertex_array_len < (1 << 16)) {
  626. uint16_t v = src[i];
  627. memcpy(&iw[i * 2], &v, 2);
  628. } else {
  629. uint32_t v = src[i];
  630. memcpy(&iw[i * 4], &v, 4);
  631. }
  632. }
  633. } break;
  634. default: {
  635. ERR_FAIL_V(ERR_INVALID_DATA);
  636. }
  637. }
  638. }
  639. if (p_format & VS::ARRAY_FORMAT_BONES) {
  640. //create AABBs for each detected bone
  641. int total_bones = max_bone + 1;
  642. bool first = r_bone_aabb.size() == 0;
  643. r_bone_aabb.resize(total_bones);
  644. if (first) {
  645. for (int i = 0; i < total_bones; i++) {
  646. r_bone_aabb.write[i].size = Vector3(-1, -1, -1); //negative means unused
  647. }
  648. }
  649. PoolVector<Vector3> vertices = p_arrays[VS::ARRAY_VERTEX];
  650. PoolVector<int> bones = p_arrays[VS::ARRAY_BONES];
  651. PoolVector<float> weights = p_arrays[VS::ARRAY_WEIGHTS];
  652. bool any_valid = false;
  653. if (vertices.size() && bones.size() == vertices.size() * 4 && weights.size() == bones.size()) {
  654. int vs = vertices.size();
  655. PoolVector<Vector3>::Read rv = vertices.read();
  656. PoolVector<int>::Read rb = bones.read();
  657. PoolVector<float>::Read rw = weights.read();
  658. AABB *bptr = r_bone_aabb.ptrw();
  659. for (int i = 0; i < vs; i++) {
  660. Vector3 v = rv[i];
  661. for (int j = 0; j < 4; j++) {
  662. int idx = rb[i * 4 + j];
  663. float w = rw[i * 4 + j];
  664. if (w == 0) {
  665. continue; //break;
  666. }
  667. ERR_FAIL_INDEX_V(idx, total_bones, ERR_INVALID_DATA);
  668. if (bptr[idx].size.x < 0) {
  669. //first
  670. bptr[idx] = AABB(v, SMALL_VEC3);
  671. any_valid = true;
  672. } else {
  673. bptr[idx].expand_to(v);
  674. }
  675. }
  676. }
  677. }
  678. if (!any_valid && first) {
  679. r_bone_aabb.clear();
  680. }
  681. }
  682. return OK;
  683. }
  684. uint32_t VisualServer::mesh_surface_get_format_offset(uint32_t p_format, int p_vertex_len, int p_index_len, int p_array_index) const {
  685. ERR_FAIL_INDEX_V(p_array_index, ARRAY_MAX, 0);
  686. uint32_t offsets[ARRAY_MAX];
  687. uint32_t strides[ARRAY_MAX];
  688. mesh_surface_make_offsets_from_format(p_format, p_vertex_len, p_index_len, offsets, strides);
  689. return offsets[p_array_index];
  690. }
  691. uint32_t VisualServer::mesh_surface_get_format_stride(uint32_t p_format, int p_vertex_len, int p_index_len, int p_array_index) const {
  692. ERR_FAIL_INDEX_V(p_array_index, ARRAY_MAX, 0);
  693. uint32_t offsets[ARRAY_MAX];
  694. uint32_t strides[ARRAY_MAX];
  695. mesh_surface_make_offsets_from_format(p_format, p_vertex_len, p_index_len, offsets, strides);
  696. return strides[p_array_index];
  697. }
  698. void VisualServer::mesh_surface_make_offsets_from_format(uint32_t p_format, int p_vertex_len, int p_index_len, uint32_t *r_offsets, uint32_t *r_strides) const {
  699. bool use_split_stream = GLOBAL_GET("rendering/misc/mesh_storage/split_stream") && !(p_format & VS::ARRAY_FLAG_USE_DYNAMIC_UPDATE);
  700. int attributes_base_offset = 0;
  701. int attributes_stride = 0;
  702. int positions_stride = 0;
  703. for (int i = 0; i < VS::ARRAY_MAX; i++) {
  704. r_offsets[i] = 0; //reset
  705. if (!(p_format & (1 << i))) { // no array
  706. continue;
  707. }
  708. int elem_size = 0;
  709. switch (i) {
  710. case VS::ARRAY_VERTEX: {
  711. if (p_format & ARRAY_FLAG_USE_2D_VERTICES) {
  712. elem_size = 2;
  713. } else {
  714. elem_size = 3;
  715. }
  716. if (p_format & ARRAY_COMPRESS_VERTEX) {
  717. elem_size *= sizeof(int16_t);
  718. } else {
  719. elem_size *= sizeof(float);
  720. }
  721. if (elem_size == 6) {
  722. elem_size = 8;
  723. }
  724. r_offsets[i] = 0;
  725. positions_stride = elem_size;
  726. if (use_split_stream) {
  727. attributes_base_offset = elem_size * p_vertex_len;
  728. } else {
  729. attributes_base_offset = elem_size;
  730. }
  731. } break;
  732. case VS::ARRAY_NORMAL: {
  733. if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  734. // normal will always be oct32 (4 byte) encoded
  735. // UNLESS tangent exists and is also compressed
  736. // then it will be oct16 encoded along with tangent
  737. if ((p_format & ARRAY_COMPRESS_NORMAL) && (p_format & ARRAY_FORMAT_TANGENT) && (p_format & ARRAY_COMPRESS_TANGENT)) {
  738. elem_size = sizeof(uint8_t) * 2;
  739. } else {
  740. elem_size = sizeof(uint16_t) * 2;
  741. }
  742. } else {
  743. if (p_format & ARRAY_COMPRESS_NORMAL) {
  744. elem_size = sizeof(uint32_t);
  745. } else {
  746. elem_size = sizeof(float) * 3;
  747. }
  748. }
  749. r_offsets[i] = attributes_base_offset + attributes_stride;
  750. attributes_stride += elem_size;
  751. } break;
  752. case VS::ARRAY_TANGENT: {
  753. if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  754. if (p_format & ARRAY_COMPRESS_TANGENT && (p_format & ARRAY_FORMAT_NORMAL) && (p_format & ARRAY_COMPRESS_NORMAL)) {
  755. elem_size = sizeof(uint8_t) * 2;
  756. } else {
  757. elem_size = sizeof(uint16_t) * 2;
  758. }
  759. } else {
  760. if (p_format & ARRAY_COMPRESS_TANGENT) {
  761. elem_size = sizeof(uint32_t);
  762. } else {
  763. elem_size = sizeof(float) * 4;
  764. }
  765. }
  766. r_offsets[i] = attributes_base_offset + attributes_stride;
  767. attributes_stride += elem_size;
  768. } break;
  769. case VS::ARRAY_COLOR: {
  770. if (p_format & ARRAY_COMPRESS_COLOR) {
  771. elem_size = sizeof(uint32_t);
  772. } else {
  773. elem_size = sizeof(float) * 4;
  774. }
  775. r_offsets[i] = attributes_base_offset + attributes_stride;
  776. attributes_stride += elem_size;
  777. } break;
  778. case VS::ARRAY_TEX_UV: {
  779. if (p_format & ARRAY_COMPRESS_TEX_UV) {
  780. elem_size = sizeof(uint32_t);
  781. } else {
  782. elem_size = sizeof(float) * 2;
  783. }
  784. r_offsets[i] = attributes_base_offset + attributes_stride;
  785. attributes_stride += elem_size;
  786. } break;
  787. case VS::ARRAY_TEX_UV2: {
  788. if (p_format & ARRAY_COMPRESS_TEX_UV2) {
  789. elem_size = sizeof(uint32_t);
  790. } else {
  791. elem_size = sizeof(float) * 2;
  792. }
  793. r_offsets[i] = attributes_base_offset + attributes_stride;
  794. attributes_stride += elem_size;
  795. } break;
  796. case VS::ARRAY_WEIGHTS: {
  797. if (p_format & ARRAY_COMPRESS_WEIGHTS) {
  798. elem_size = sizeof(uint16_t) * 4;
  799. } else {
  800. elem_size = sizeof(float) * 4;
  801. }
  802. r_offsets[i] = attributes_base_offset + attributes_stride;
  803. attributes_stride += elem_size;
  804. } break;
  805. case VS::ARRAY_BONES: {
  806. if (p_format & ARRAY_FLAG_USE_16_BIT_BONES) {
  807. elem_size = sizeof(uint16_t) * 4;
  808. } else {
  809. elem_size = sizeof(uint32_t);
  810. }
  811. r_offsets[i] = attributes_base_offset + attributes_stride;
  812. attributes_stride += elem_size;
  813. } break;
  814. case VS::ARRAY_INDEX: {
  815. if (p_index_len <= 0) {
  816. ERR_PRINT("index_array_len==NO_INDEX_ARRAY");
  817. break;
  818. }
  819. /* determine whether using 16 or 32 bits indices */
  820. if (p_vertex_len >= (1 << 16)) {
  821. elem_size = 4;
  822. } else {
  823. elem_size = 2;
  824. }
  825. r_offsets[i] = elem_size;
  826. continue;
  827. }
  828. default: {
  829. ERR_FAIL();
  830. }
  831. }
  832. }
  833. if (use_split_stream) {
  834. r_strides[VS::ARRAY_VERTEX] = positions_stride;
  835. for (int i = 1; i < VS::ARRAY_MAX - 1; i++) {
  836. r_strides[i] = attributes_stride;
  837. }
  838. } else {
  839. for (int i = 0; i < VS::ARRAY_MAX - 1; i++) {
  840. r_strides[i] = positions_stride + attributes_stride;
  841. }
  842. }
  843. }
  844. // This function is separated from the main mesh_add_surface_from_arrays() to allow finding the format WITHOUT creating data.
  845. // This is necessary for CPU meshes, where we may want to know the final format without creating final data.
  846. bool VisualServer::_mesh_find_format(VS::PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, uint32_t p_compress_format, bool p_use_split_stream, uint32_t r_offsets[], int &r_attributes_base_offset, int &r_attributes_stride, int &r_positions_stride, uint32_t &r_format, int &r_index_array_len, int &r_array_len) {
  847. ERR_FAIL_INDEX_V(p_primitive, VS::PRIMITIVE_MAX, false);
  848. ERR_FAIL_COND_V(p_arrays.size() != VS::ARRAY_MAX, false);
  849. for (int i = 0; i < p_arrays.size(); i++) {
  850. if (p_arrays[i].get_type() == Variant::NIL) {
  851. continue;
  852. }
  853. r_format |= (1 << i);
  854. if (i == VS::ARRAY_VERTEX) {
  855. r_array_len = PoolVector3Array(p_arrays[i]).size();
  856. ERR_FAIL_COND_V(r_array_len == 0, false);
  857. } else if (i == VS::ARRAY_INDEX) {
  858. r_index_array_len = PoolIntArray(p_arrays[i]).size();
  859. }
  860. }
  861. ERR_FAIL_COND_V((r_format & VS::ARRAY_FORMAT_VERTEX) == 0, false); // mandatory
  862. if (p_blend_shapes.size()) {
  863. //validate format for morphs
  864. for (int i = 0; i < p_blend_shapes.size(); i++) {
  865. uint32_t bsformat = 0;
  866. Array arr = p_blend_shapes[i];
  867. for (int j = 0; j < arr.size(); j++) {
  868. if (arr[j].get_type() != Variant::NIL) {
  869. bsformat |= (1 << j);
  870. }
  871. }
  872. ERR_FAIL_COND_V((bsformat) != (r_format & (VS::ARRAY_FORMAT_INDEX - 1)), false);
  873. }
  874. }
  875. for (int i = 0; i < VS::ARRAY_MAX; i++) {
  876. r_offsets[i] = 0; //reset
  877. if (!(r_format & (1 << i))) { // no array
  878. continue;
  879. }
  880. int elem_size = 0;
  881. switch (i) {
  882. case VS::ARRAY_VERTEX: {
  883. Variant arr = p_arrays[0];
  884. if (arr.get_type() == Variant::POOL_VECTOR2_ARRAY) {
  885. elem_size = 2;
  886. p_compress_format |= VS::ARRAY_FLAG_USE_2D_VERTICES;
  887. } else if (arr.get_type() == Variant::POOL_VECTOR3_ARRAY) {
  888. p_compress_format &= ~VS::ARRAY_FLAG_USE_2D_VERTICES;
  889. elem_size = 3;
  890. } else {
  891. elem_size = (p_compress_format & VS::ARRAY_FLAG_USE_2D_VERTICES) ? 2 : 3;
  892. }
  893. if (p_compress_format & VS::ARRAY_COMPRESS_VERTEX) {
  894. elem_size *= sizeof(int16_t);
  895. } else {
  896. elem_size *= sizeof(float);
  897. }
  898. if (elem_size == 6) {
  899. //had to pad
  900. elem_size = 8;
  901. }
  902. r_offsets[i] = 0;
  903. r_positions_stride = elem_size;
  904. if (p_use_split_stream) {
  905. r_attributes_base_offset = elem_size * r_array_len;
  906. } else {
  907. r_attributes_base_offset = elem_size;
  908. }
  909. } break;
  910. case VS::ARRAY_NORMAL: {
  911. if (p_compress_format & VS::ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  912. // normal will always be oct32 (4 byte) encoded
  913. // UNLESS tangent exists and is also compressed
  914. // then it will be oct16 encoded along with tangent
  915. if ((p_compress_format & VS::ARRAY_COMPRESS_NORMAL) && (r_format & VS::ARRAY_FORMAT_TANGENT) && (p_compress_format & VS::ARRAY_COMPRESS_TANGENT)) {
  916. elem_size = sizeof(uint8_t) * 2;
  917. } else {
  918. elem_size = sizeof(uint16_t) * 2;
  919. }
  920. } else {
  921. if (p_compress_format & VS::ARRAY_COMPRESS_NORMAL) {
  922. elem_size = sizeof(uint32_t);
  923. } else {
  924. elem_size = sizeof(float) * 3;
  925. }
  926. }
  927. r_offsets[i] = r_attributes_base_offset + r_attributes_stride;
  928. r_attributes_stride += elem_size;
  929. } break;
  930. case VS::ARRAY_TANGENT: {
  931. if (p_compress_format & VS::ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  932. if (p_compress_format & VS::ARRAY_COMPRESS_TANGENT && (r_format & VS::ARRAY_FORMAT_NORMAL) && (p_compress_format & VS::ARRAY_COMPRESS_NORMAL)) {
  933. elem_size = sizeof(uint8_t) * 2;
  934. } else {
  935. elem_size = sizeof(uint16_t) * 2;
  936. }
  937. } else {
  938. if (p_compress_format & VS::ARRAY_COMPRESS_TANGENT) {
  939. elem_size = sizeof(uint32_t);
  940. } else {
  941. elem_size = sizeof(float) * 4;
  942. }
  943. }
  944. r_offsets[i] = r_attributes_base_offset + r_attributes_stride;
  945. r_attributes_stride += elem_size;
  946. } break;
  947. case VS::ARRAY_COLOR: {
  948. if (p_compress_format & VS::ARRAY_COMPRESS_COLOR) {
  949. elem_size = sizeof(uint32_t);
  950. } else {
  951. elem_size = sizeof(float) * 4;
  952. }
  953. r_offsets[i] = r_attributes_base_offset + r_attributes_stride;
  954. r_attributes_stride += elem_size;
  955. } break;
  956. case VS::ARRAY_TEX_UV: {
  957. if (p_compress_format & VS::ARRAY_COMPRESS_TEX_UV) {
  958. elem_size = sizeof(uint32_t);
  959. } else {
  960. elem_size = sizeof(float) * 2;
  961. }
  962. r_offsets[i] = r_attributes_base_offset + r_attributes_stride;
  963. r_attributes_stride += elem_size;
  964. } break;
  965. case VS::ARRAY_TEX_UV2: {
  966. if (p_compress_format & VS::ARRAY_COMPRESS_TEX_UV2) {
  967. elem_size = sizeof(uint32_t);
  968. } else {
  969. elem_size = sizeof(float) * 2;
  970. }
  971. r_offsets[i] = r_attributes_base_offset + r_attributes_stride;
  972. r_attributes_stride += elem_size;
  973. } break;
  974. case VS::ARRAY_WEIGHTS: {
  975. if (p_compress_format & VS::ARRAY_COMPRESS_WEIGHTS) {
  976. elem_size = sizeof(uint16_t) * 4;
  977. } else {
  978. elem_size = sizeof(float) * 4;
  979. }
  980. r_offsets[i] = r_attributes_base_offset + r_attributes_stride;
  981. r_attributes_stride += elem_size;
  982. } break;
  983. case VS::ARRAY_BONES: {
  984. PoolVector<int> bones = p_arrays[VS::ARRAY_BONES];
  985. int max_bone = 0;
  986. {
  987. int bc = bones.size();
  988. PoolVector<int>::Read r = bones.read();
  989. for (int j = 0; j < bc; j++) {
  990. max_bone = MAX(r[j], max_bone);
  991. }
  992. }
  993. if (max_bone > 255) {
  994. p_compress_format |= VS::ARRAY_FLAG_USE_16_BIT_BONES;
  995. elem_size = sizeof(uint16_t) * 4;
  996. } else {
  997. p_compress_format &= ~VS::ARRAY_FLAG_USE_16_BIT_BONES;
  998. elem_size = sizeof(uint32_t);
  999. }
  1000. r_offsets[i] = r_attributes_base_offset + r_attributes_stride;
  1001. r_attributes_stride += elem_size;
  1002. } break;
  1003. case VS::ARRAY_INDEX: {
  1004. if (r_index_array_len <= 0) {
  1005. ERR_PRINT("index_array_len==NO_INDEX_ARRAY");
  1006. break;
  1007. }
  1008. /* determine whether using 16 or 32 bits indices */
  1009. if (r_array_len >= (1 << 16)) {
  1010. elem_size = 4;
  1011. } else {
  1012. elem_size = 2;
  1013. }
  1014. r_offsets[i] = elem_size;
  1015. continue;
  1016. }
  1017. default: {
  1018. ERR_FAIL_V(false);
  1019. }
  1020. }
  1021. }
  1022. uint32_t mask = (1 << VS::ARRAY_MAX) - 1;
  1023. r_format |= (~mask) & p_compress_format; //make the full format
  1024. return true;
  1025. }
  1026. uint32_t VisualServer::mesh_find_format_from_arrays(PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, uint32_t p_compress_format) {
  1027. bool use_split_stream = GLOBAL_GET("rendering/misc/mesh_storage/split_stream") && !(p_compress_format & VS::ARRAY_FLAG_USE_DYNAMIC_UPDATE);
  1028. uint32_t offsets[VS::ARRAY_MAX];
  1029. int attributes_base_offset = 0;
  1030. int attributes_stride = 0;
  1031. int positions_stride = 0;
  1032. uint32_t format = 0;
  1033. // validation
  1034. int index_array_len = 0;
  1035. int array_len = 0;
  1036. bool res = _mesh_find_format(p_primitive, p_arrays, p_blend_shapes, p_compress_format, use_split_stream, offsets, attributes_base_offset, attributes_stride, positions_stride, format, index_array_len, array_len);
  1037. ERR_FAIL_COND_V(!res, 0);
  1038. return format;
  1039. }
  1040. void VisualServer::mesh_add_surface_from_arrays(RID p_mesh, PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, uint32_t p_compress_format) {
  1041. bool use_split_stream = GLOBAL_GET("rendering/misc/mesh_storage/split_stream") && !(p_compress_format & VS::ARRAY_FLAG_USE_DYNAMIC_UPDATE);
  1042. uint32_t offsets[VS::ARRAY_MAX];
  1043. int attributes_base_offset = 0;
  1044. int attributes_stride = 0;
  1045. int positions_stride = 0;
  1046. uint32_t format = 0;
  1047. // validation
  1048. int index_array_len = 0;
  1049. int array_len = 0;
  1050. // Only implemented for triangles.
  1051. if (p_primitive != PrimitiveType::PRIMITIVE_TRIANGLES) {
  1052. p_compress_format &= ~ARRAY_FLAG_USE_VERTEX_CACHE_OPTIMIZATION;
  1053. }
  1054. bool res = _mesh_find_format(p_primitive, p_arrays, p_blend_shapes, p_compress_format, use_split_stream, offsets, attributes_base_offset, attributes_stride, positions_stride, format, index_array_len, array_len);
  1055. ERR_FAIL_COND(!res);
  1056. uint32_t strides[VS::ARRAY_MAX];
  1057. if (use_split_stream) {
  1058. strides[VS::ARRAY_VERTEX] = positions_stride;
  1059. for (int i = 1; i < VS::ARRAY_MAX - 1; i++) {
  1060. strides[i] = attributes_stride;
  1061. }
  1062. } else {
  1063. for (int i = 0; i < VS::ARRAY_MAX - 1; i++) {
  1064. strides[i] = positions_stride + attributes_stride;
  1065. }
  1066. }
  1067. int array_size = (positions_stride + attributes_stride) * array_len;
  1068. PoolVector<uint8_t> vertex_array;
  1069. vertex_array.resize(array_size);
  1070. int index_array_size = offsets[VS::ARRAY_INDEX] * index_array_len;
  1071. PoolVector<uint8_t> index_array;
  1072. index_array.resize(index_array_size);
  1073. AABB aabb;
  1074. Vector<AABB> bone_aabb;
  1075. Error err = _surface_set_data(p_arrays, format, offsets, strides, vertex_array, array_len, index_array, index_array_len, aabb, bone_aabb);
  1076. ERR_FAIL_COND_MSG(err, "Invalid array format for surface.");
  1077. Vector<PoolVector<uint8_t>> blend_shape_data;
  1078. for (int i = 0; i < p_blend_shapes.size(); i++) {
  1079. PoolVector<uint8_t> vertex_array_shape;
  1080. vertex_array_shape.resize(array_size);
  1081. PoolVector<uint8_t> noindex;
  1082. AABB laabb;
  1083. Error err2 = _surface_set_data(p_blend_shapes[i], format & ~ARRAY_FORMAT_INDEX, offsets, strides, vertex_array_shape, array_len, noindex, 0, laabb, bone_aabb);
  1084. aabb.merge_with(laabb);
  1085. ERR_FAIL_COND_MSG(err2 != OK, "Invalid blend shape array format for surface.");
  1086. blend_shape_data.push_back(vertex_array_shape);
  1087. }
  1088. mesh_add_surface(p_mesh, format, p_primitive, vertex_array, array_len, index_array, index_array_len, aabb, blend_shape_data, bone_aabb);
  1089. }
  1090. Array VisualServer::_get_array_from_surface(uint32_t p_format, PoolVector<uint8_t> p_vertex_data, int p_vertex_len, PoolVector<uint8_t> p_index_data, int p_index_len) const {
  1091. bool use_split_stream = GLOBAL_GET("rendering/misc/mesh_storage/split_stream") && !(p_format & VS::ARRAY_FLAG_USE_DYNAMIC_UPDATE);
  1092. uint32_t offsets[ARRAY_MAX];
  1093. uint32_t strides[VS::ARRAY_MAX];
  1094. int attributes_base_offset = 0;
  1095. int attributes_stride = 0;
  1096. int positions_stride = 0;
  1097. for (int i = 0; i < VS::ARRAY_MAX; i++) {
  1098. offsets[i] = 0; //reset
  1099. if (!(p_format & (1 << i))) { // no array
  1100. continue;
  1101. }
  1102. int elem_size = 0;
  1103. switch (i) {
  1104. case VS::ARRAY_VERTEX: {
  1105. if (p_format & ARRAY_FLAG_USE_2D_VERTICES) {
  1106. elem_size = 2;
  1107. } else {
  1108. elem_size = 3;
  1109. }
  1110. if (p_format & ARRAY_COMPRESS_VERTEX) {
  1111. elem_size *= sizeof(int16_t);
  1112. } else {
  1113. elem_size *= sizeof(float);
  1114. }
  1115. if (elem_size == 6) {
  1116. elem_size = 8;
  1117. }
  1118. offsets[i] = 0;
  1119. positions_stride = elem_size;
  1120. if (use_split_stream) {
  1121. attributes_base_offset = elem_size * p_vertex_len;
  1122. } else {
  1123. attributes_base_offset = elem_size;
  1124. }
  1125. } break;
  1126. case VS::ARRAY_NORMAL: {
  1127. if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  1128. // normal will always be oct32 (4 byte) encoded
  1129. // UNLESS tangent exists and is also compressed
  1130. // then it will be oct16 encoded along with tangent
  1131. if ((p_format & ARRAY_COMPRESS_NORMAL) && (p_format & ARRAY_FORMAT_TANGENT) && (p_format & ARRAY_COMPRESS_TANGENT)) {
  1132. elem_size = sizeof(uint8_t) * 2;
  1133. } else {
  1134. elem_size = sizeof(uint16_t) * 2;
  1135. }
  1136. } else {
  1137. if (p_format & ARRAY_COMPRESS_NORMAL) {
  1138. elem_size = sizeof(uint32_t);
  1139. } else {
  1140. elem_size = sizeof(float) * 3;
  1141. }
  1142. }
  1143. offsets[i] = attributes_base_offset + attributes_stride;
  1144. attributes_stride += elem_size;
  1145. } break;
  1146. case VS::ARRAY_TANGENT: {
  1147. if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  1148. if (p_format & ARRAY_COMPRESS_TANGENT && (p_format & ARRAY_FORMAT_NORMAL) && (p_format & ARRAY_COMPRESS_NORMAL)) {
  1149. elem_size = sizeof(uint8_t) * 2;
  1150. } else {
  1151. elem_size = sizeof(uint16_t) * 2;
  1152. }
  1153. } else {
  1154. if (p_format & ARRAY_COMPRESS_TANGENT) {
  1155. elem_size = sizeof(uint32_t);
  1156. } else {
  1157. elem_size = sizeof(float) * 4;
  1158. }
  1159. }
  1160. offsets[i] = attributes_base_offset + attributes_stride;
  1161. attributes_stride += elem_size;
  1162. } break;
  1163. case VS::ARRAY_COLOR: {
  1164. if (p_format & ARRAY_COMPRESS_COLOR) {
  1165. elem_size = sizeof(uint32_t);
  1166. } else {
  1167. elem_size = sizeof(float) * 4;
  1168. }
  1169. offsets[i] = attributes_base_offset + attributes_stride;
  1170. attributes_stride += elem_size;
  1171. } break;
  1172. case VS::ARRAY_TEX_UV: {
  1173. if (p_format & ARRAY_COMPRESS_TEX_UV) {
  1174. elem_size = sizeof(uint32_t);
  1175. } else {
  1176. elem_size = sizeof(float) * 2;
  1177. }
  1178. offsets[i] = attributes_base_offset + attributes_stride;
  1179. attributes_stride += elem_size;
  1180. } break;
  1181. case VS::ARRAY_TEX_UV2: {
  1182. if (p_format & ARRAY_COMPRESS_TEX_UV2) {
  1183. elem_size = sizeof(uint32_t);
  1184. } else {
  1185. elem_size = sizeof(float) * 2;
  1186. }
  1187. offsets[i] = attributes_base_offset + attributes_stride;
  1188. attributes_stride += elem_size;
  1189. } break;
  1190. case VS::ARRAY_WEIGHTS: {
  1191. if (p_format & ARRAY_COMPRESS_WEIGHTS) {
  1192. elem_size = sizeof(uint16_t) * 4;
  1193. } else {
  1194. elem_size = sizeof(float) * 4;
  1195. }
  1196. offsets[i] = attributes_base_offset + attributes_stride;
  1197. attributes_stride += elem_size;
  1198. } break;
  1199. case VS::ARRAY_BONES: {
  1200. if (p_format & ARRAY_FLAG_USE_16_BIT_BONES) {
  1201. elem_size = sizeof(uint16_t) * 4;
  1202. } else {
  1203. elem_size = sizeof(uint32_t);
  1204. }
  1205. offsets[i] = attributes_base_offset + attributes_stride;
  1206. attributes_stride += elem_size;
  1207. } break;
  1208. case VS::ARRAY_INDEX: {
  1209. if (p_index_len <= 0) {
  1210. ERR_PRINT("index_array_len==NO_INDEX_ARRAY");
  1211. break;
  1212. }
  1213. /* determine whether using 16 or 32 bits indices */
  1214. if (p_vertex_len >= (1 << 16)) {
  1215. elem_size = 4;
  1216. } else {
  1217. elem_size = 2;
  1218. }
  1219. offsets[i] = elem_size;
  1220. continue;
  1221. }
  1222. default: {
  1223. ERR_FAIL_V(Array());
  1224. }
  1225. }
  1226. }
  1227. if (use_split_stream) {
  1228. strides[VS::ARRAY_VERTEX] = positions_stride;
  1229. for (int i = 1; i < VS::ARRAY_MAX - 1; i++) {
  1230. strides[i] = attributes_stride;
  1231. }
  1232. } else {
  1233. for (int i = 0; i < VS::ARRAY_MAX - 1; i++) {
  1234. strides[i] = positions_stride + attributes_stride;
  1235. }
  1236. }
  1237. Array ret;
  1238. ret.resize(VS::ARRAY_MAX);
  1239. PoolVector<uint8_t>::Read r = p_vertex_data.read();
  1240. for (int i = 0; i < VS::ARRAY_MAX; i++) {
  1241. if (!(p_format & (1 << i))) {
  1242. continue;
  1243. }
  1244. switch (i) {
  1245. case VS::ARRAY_VERTEX: {
  1246. if (p_format & ARRAY_FLAG_USE_2D_VERTICES) {
  1247. PoolVector<Vector2> arr_2d;
  1248. arr_2d.resize(p_vertex_len);
  1249. if (p_format & ARRAY_COMPRESS_VERTEX) {
  1250. PoolVector<Vector2>::Write w = arr_2d.write();
  1251. for (int j = 0; j < p_vertex_len; j++) {
  1252. const uint16_t *v = (const uint16_t *)&r[j * strides[i] + offsets[i]];
  1253. w[j] = Vector2(Math::halfptr_to_float(&v[0]), Math::halfptr_to_float(&v[1]));
  1254. }
  1255. } else {
  1256. PoolVector<Vector2>::Write w = arr_2d.write();
  1257. for (int j = 0; j < p_vertex_len; j++) {
  1258. const float *v = (const float *)&r[j * strides[i] + offsets[i]];
  1259. w[j] = Vector2(v[0], v[1]);
  1260. }
  1261. }
  1262. ret[i] = arr_2d;
  1263. } else {
  1264. PoolVector<Vector3> arr_3d;
  1265. arr_3d.resize(p_vertex_len);
  1266. if (p_format & ARRAY_COMPRESS_VERTEX) {
  1267. PoolVector<Vector3>::Write w = arr_3d.write();
  1268. for (int j = 0; j < p_vertex_len; j++) {
  1269. const uint16_t *v = (const uint16_t *)&r[j * strides[i] + offsets[i]];
  1270. w[j] = Vector3(Math::halfptr_to_float(&v[0]), Math::halfptr_to_float(&v[1]), Math::halfptr_to_float(&v[2]));
  1271. }
  1272. } else {
  1273. PoolVector<Vector3>::Write w = arr_3d.write();
  1274. for (int j = 0; j < p_vertex_len; j++) {
  1275. const float *v = (const float *)&r[j * strides[i] + offsets[i]];
  1276. w[j] = Vector3(v[0], v[1], v[2]);
  1277. }
  1278. }
  1279. ret[i] = arr_3d;
  1280. }
  1281. } break;
  1282. case VS::ARRAY_NORMAL: {
  1283. PoolVector<Vector3> arr;
  1284. arr.resize(p_vertex_len);
  1285. if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  1286. if (p_format & ARRAY_COMPRESS_NORMAL && (p_format & ARRAY_FORMAT_TANGENT) && (p_format & ARRAY_COMPRESS_TANGENT)) {
  1287. PoolVector<Vector3>::Write w = arr.write();
  1288. for (int j = 0; j < p_vertex_len; j++) {
  1289. const int8_t *n = (const int8_t *)&r[j * strides[i] + offsets[i]];
  1290. Vector2 enc(n[0] / 127.0f, n[1] / 127.0f);
  1291. w[j] = oct_to_norm(enc);
  1292. }
  1293. } else {
  1294. PoolVector<Vector3>::Write w = arr.write();
  1295. for (int j = 0; j < p_vertex_len; j++) {
  1296. const int16_t *n = (const int16_t *)&r[j * strides[i] + offsets[i]];
  1297. Vector2 enc(n[0] / 32767.0f, n[1] / 32767.0f);
  1298. w[j] = oct_to_norm(enc);
  1299. }
  1300. }
  1301. } else {
  1302. if (p_format & ARRAY_COMPRESS_NORMAL) {
  1303. PoolVector<Vector3>::Write w = arr.write();
  1304. const float multiplier = 1.f / 127.f;
  1305. for (int j = 0; j < p_vertex_len; j++) {
  1306. const int8_t *v = (const int8_t *)&r[j * strides[i] + offsets[i]];
  1307. w[j] = Vector3(float(v[0]) * multiplier, float(v[1]) * multiplier, float(v[2]) * multiplier);
  1308. }
  1309. } else {
  1310. PoolVector<Vector3>::Write w = arr.write();
  1311. for (int j = 0; j < p_vertex_len; j++) {
  1312. const float *v = (const float *)&r[j * strides[i] + offsets[i]];
  1313. w[j] = Vector3(v[0], v[1], v[2]);
  1314. }
  1315. }
  1316. }
  1317. ret[i] = arr;
  1318. } break;
  1319. case VS::ARRAY_TANGENT: {
  1320. PoolVector<float> arr;
  1321. arr.resize(p_vertex_len * 4);
  1322. if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  1323. if (p_format & ARRAY_COMPRESS_TANGENT) {
  1324. PoolVector<float>::Write w = arr.write();
  1325. for (int j = 0; j < p_vertex_len; j++) {
  1326. const int8_t *t = (const int8_t *)&r[j * strides[i] + offsets[i]];
  1327. Vector2 enc(t[0] / 127.0f, t[1] / 127.0f);
  1328. Vector3 dec = oct_to_tangent(enc, &w[j * 4 + 3]);
  1329. w[j * 4 + 0] = dec.x;
  1330. w[j * 4 + 1] = dec.y;
  1331. w[j * 4 + 2] = dec.z;
  1332. }
  1333. } else {
  1334. PoolVector<float>::Write w = arr.write();
  1335. for (int j = 0; j < p_vertex_len; j++) {
  1336. const int16_t *t = (const int16_t *)&r[j * strides[i] + offsets[i]];
  1337. Vector2 enc(t[0] / 32767.0f, t[1] / 32767.0f);
  1338. Vector3 dec = oct_to_tangent(enc, &w[j * 4 + 3]);
  1339. w[j * 4 + 0] = dec.x;
  1340. w[j * 4 + 1] = dec.y;
  1341. w[j * 4 + 2] = dec.z;
  1342. }
  1343. }
  1344. } else {
  1345. if (p_format & ARRAY_COMPRESS_TANGENT) {
  1346. PoolVector<float>::Write w = arr.write();
  1347. for (int j = 0; j < p_vertex_len; j++) {
  1348. const int8_t *v = (const int8_t *)&r[j * strides[i] + offsets[i]];
  1349. for (int k = 0; k < 4; k++) {
  1350. w[j * 4 + k] = float(v[k] / 127.0);
  1351. }
  1352. }
  1353. } else {
  1354. PoolVector<float>::Write w = arr.write();
  1355. for (int j = 0; j < p_vertex_len; j++) {
  1356. const float *v = (const float *)&r[j * strides[i] + offsets[i]];
  1357. for (int k = 0; k < 4; k++) {
  1358. w[j * 4 + k] = v[k];
  1359. }
  1360. }
  1361. }
  1362. }
  1363. ret[i] = arr;
  1364. } break;
  1365. case VS::ARRAY_COLOR: {
  1366. PoolVector<Color> arr;
  1367. arr.resize(p_vertex_len);
  1368. if (p_format & ARRAY_COMPRESS_COLOR) {
  1369. PoolVector<Color>::Write w = arr.write();
  1370. for (int j = 0; j < p_vertex_len; j++) {
  1371. const uint8_t *v = (const uint8_t *)&r[j * strides[i] + offsets[i]];
  1372. w[j] = Color(float(v[0] / 255.0), float(v[1] / 255.0), float(v[2] / 255.0), float(v[3] / 255.0));
  1373. }
  1374. } else {
  1375. PoolVector<Color>::Write w = arr.write();
  1376. for (int j = 0; j < p_vertex_len; j++) {
  1377. const float *v = (const float *)&r[j * strides[i] + offsets[i]];
  1378. w[j] = Color(v[0], v[1], v[2], v[3]);
  1379. }
  1380. }
  1381. ret[i] = arr;
  1382. } break;
  1383. case VS::ARRAY_TEX_UV: {
  1384. PoolVector<Vector2> arr;
  1385. arr.resize(p_vertex_len);
  1386. if (p_format & ARRAY_COMPRESS_TEX_UV) {
  1387. PoolVector<Vector2>::Write w = arr.write();
  1388. for (int j = 0; j < p_vertex_len; j++) {
  1389. const uint16_t *v = (const uint16_t *)&r[j * strides[i] + offsets[i]];
  1390. w[j] = Vector2(Math::halfptr_to_float(&v[0]), Math::halfptr_to_float(&v[1]));
  1391. }
  1392. } else {
  1393. PoolVector<Vector2>::Write w = arr.write();
  1394. for (int j = 0; j < p_vertex_len; j++) {
  1395. const float *v = (const float *)&r[j * strides[i] + offsets[i]];
  1396. w[j] = Vector2(v[0], v[1]);
  1397. }
  1398. }
  1399. ret[i] = arr;
  1400. } break;
  1401. case VS::ARRAY_TEX_UV2: {
  1402. PoolVector<Vector2> arr;
  1403. arr.resize(p_vertex_len);
  1404. if (p_format & ARRAY_COMPRESS_TEX_UV2) {
  1405. PoolVector<Vector2>::Write w = arr.write();
  1406. for (int j = 0; j < p_vertex_len; j++) {
  1407. const uint16_t *v = (const uint16_t *)&r[j * strides[i] + offsets[i]];
  1408. w[j] = Vector2(Math::halfptr_to_float(&v[0]), Math::halfptr_to_float(&v[1]));
  1409. }
  1410. } else {
  1411. PoolVector<Vector2>::Write w = arr.write();
  1412. for (int j = 0; j < p_vertex_len; j++) {
  1413. const float *v = (const float *)&r[j * strides[i] + offsets[i]];
  1414. w[j] = Vector2(v[0], v[1]);
  1415. }
  1416. }
  1417. ret[i] = arr;
  1418. } break;
  1419. case VS::ARRAY_WEIGHTS: {
  1420. PoolVector<float> arr;
  1421. arr.resize(p_vertex_len * 4);
  1422. if (p_format & ARRAY_COMPRESS_WEIGHTS) {
  1423. PoolVector<float>::Write w = arr.write();
  1424. for (int j = 0; j < p_vertex_len; j++) {
  1425. const uint16_t *v = (const uint16_t *)&r[j * strides[i] + offsets[i]];
  1426. for (int k = 0; k < 4; k++) {
  1427. w[j * 4 + k] = float(v[k] / 65535.0);
  1428. }
  1429. }
  1430. } else {
  1431. PoolVector<float>::Write w = arr.write();
  1432. for (int j = 0; j < p_vertex_len; j++) {
  1433. const float *v = (const float *)&r[j * strides[i] + offsets[i]];
  1434. for (int k = 0; k < 4; k++) {
  1435. w[j * 4 + k] = v[k];
  1436. }
  1437. }
  1438. }
  1439. ret[i] = arr;
  1440. } break;
  1441. case VS::ARRAY_BONES: {
  1442. PoolVector<int> arr;
  1443. arr.resize(p_vertex_len * 4);
  1444. if (p_format & ARRAY_FLAG_USE_16_BIT_BONES) {
  1445. PoolVector<int>::Write w = arr.write();
  1446. for (int j = 0; j < p_vertex_len; j++) {
  1447. const uint16_t *v = (const uint16_t *)&r[j * strides[i] + offsets[i]];
  1448. for (int k = 0; k < 4; k++) {
  1449. w[j * 4 + k] = v[k];
  1450. }
  1451. }
  1452. } else {
  1453. PoolVector<int>::Write w = arr.write();
  1454. for (int j = 0; j < p_vertex_len; j++) {
  1455. const uint8_t *v = (const uint8_t *)&r[j * strides[i] + offsets[i]];
  1456. for (int k = 0; k < 4; k++) {
  1457. w[j * 4 + k] = v[k];
  1458. }
  1459. }
  1460. }
  1461. ret[i] = arr;
  1462. } break;
  1463. case VS::ARRAY_INDEX: {
  1464. /* determine whether using 16 or 32 bits indices */
  1465. PoolVector<uint8_t>::Read ir = p_index_data.read();
  1466. PoolVector<int> arr;
  1467. arr.resize(p_index_len);
  1468. if (p_vertex_len < (1 << 16)) {
  1469. PoolVector<int>::Write w = arr.write();
  1470. for (int j = 0; j < p_index_len; j++) {
  1471. const uint16_t *v = (const uint16_t *)&ir[j * 2];
  1472. w[j] = *v;
  1473. }
  1474. } else {
  1475. PoolVector<int>::Write w = arr.write();
  1476. for (int j = 0; j < p_index_len; j++) {
  1477. const int *v = (const int *)&ir[j * 4];
  1478. w[j] = *v;
  1479. }
  1480. }
  1481. ret[i] = arr;
  1482. } break;
  1483. default: {
  1484. ERR_FAIL_V(ret);
  1485. }
  1486. }
  1487. }
  1488. return ret;
  1489. }
  1490. Array VisualServer::mesh_surface_get_arrays(RID p_mesh, int p_surface) const {
  1491. PoolVector<uint8_t> vertex_data = mesh_surface_get_array(p_mesh, p_surface);
  1492. ERR_FAIL_COND_V(vertex_data.size() == 0, Array());
  1493. int vertex_len = mesh_surface_get_array_len(p_mesh, p_surface);
  1494. PoolVector<uint8_t> index_data = mesh_surface_get_index_array(p_mesh, p_surface);
  1495. int index_len = mesh_surface_get_array_index_len(p_mesh, p_surface);
  1496. uint32_t format = mesh_surface_get_format(p_mesh, p_surface);
  1497. return _get_array_from_surface(format, vertex_data, vertex_len, index_data, index_len);
  1498. }
  1499. Array VisualServer::mesh_surface_get_blend_shape_arrays(RID p_mesh, int p_surface) const {
  1500. Vector<PoolVector<uint8_t>> blend_shape_data = mesh_surface_get_blend_shapes(p_mesh, p_surface);
  1501. if (blend_shape_data.size() > 0) {
  1502. int vertex_len = mesh_surface_get_array_len(p_mesh, p_surface);
  1503. PoolVector<uint8_t> index_data = mesh_surface_get_index_array(p_mesh, p_surface);
  1504. int index_len = mesh_surface_get_array_index_len(p_mesh, p_surface);
  1505. uint32_t format = mesh_surface_get_format(p_mesh, p_surface);
  1506. Array blend_shape_array;
  1507. blend_shape_array.resize(blend_shape_data.size());
  1508. for (int i = 0; i < blend_shape_data.size(); i++) {
  1509. blend_shape_array.set(i, _get_array_from_surface(format, blend_shape_data[i], vertex_len, index_data, index_len));
  1510. }
  1511. return blend_shape_array;
  1512. } else {
  1513. return Array();
  1514. }
  1515. }
  1516. Array VisualServer::_mesh_surface_get_skeleton_aabb_bind(RID p_mesh, int p_surface) const {
  1517. Vector<AABB> vec = VS::get_singleton()->mesh_surface_get_skeleton_aabb(p_mesh, p_surface);
  1518. Array arr;
  1519. for (int i = 0; i < vec.size(); i++) {
  1520. arr[i] = vec[i];
  1521. }
  1522. return arr;
  1523. }
  1524. void VisualServer::_bind_methods() {
  1525. ClassDB::bind_method(D_METHOD("force_sync"), &VisualServer::sync);
  1526. ClassDB::bind_method(D_METHOD("force_draw", "swap_buffers", "frame_step"), &VisualServer::draw, DEFVAL(true), DEFVAL(0.0));
  1527. // "draw" and "sync" are deprecated duplicates of "force_draw" and "force_sync"
  1528. // FIXME: Add deprecation messages using GH-4397 once available, and retire
  1529. // once the warnings have been enabled for a full release cycle
  1530. ClassDB::bind_method(D_METHOD("sync"), &VisualServer::sync);
  1531. ClassDB::bind_method(D_METHOD("draw", "swap_buffers", "frame_step"), &VisualServer::draw, DEFVAL(true), DEFVAL(0.0));
  1532. ClassDB::bind_method(D_METHOD("texture_create"), &VisualServer::texture_create);
  1533. ClassDB::bind_method(D_METHOD("texture_create_from_image", "image", "flags"), &VisualServer::texture_create_from_image, DEFVAL(TEXTURE_FLAGS_DEFAULT));
  1534. ClassDB::bind_method(D_METHOD("texture_allocate", "texture", "width", "height", "depth_3d", "format", "type", "flags"), &VisualServer::texture_allocate, DEFVAL(TEXTURE_FLAGS_DEFAULT));
  1535. ClassDB::bind_method(D_METHOD("texture_set_data", "texture", "image", "layer"), &VisualServer::texture_set_data, DEFVAL(0));
  1536. ClassDB::bind_method(D_METHOD("texture_set_data_partial", "texture", "image", "src_x", "src_y", "src_w", "src_h", "dst_x", "dst_y", "dst_mip", "layer"), &VisualServer::texture_set_data_partial, DEFVAL(0));
  1537. ClassDB::bind_method(D_METHOD("texture_get_data", "texture", "cube_side"), &VisualServer::texture_get_data, DEFVAL(CUBEMAP_LEFT));
  1538. ClassDB::bind_method(D_METHOD("texture_set_flags", "texture", "flags"), &VisualServer::texture_set_flags);
  1539. ClassDB::bind_method(D_METHOD("texture_get_flags", "texture"), &VisualServer::texture_get_flags);
  1540. ClassDB::bind_method(D_METHOD("texture_get_format", "texture"), &VisualServer::texture_get_format);
  1541. ClassDB::bind_method(D_METHOD("texture_get_type", "texture"), &VisualServer::texture_get_type);
  1542. ClassDB::bind_method(D_METHOD("texture_get_texid", "texture"), &VisualServer::texture_get_texid);
  1543. ClassDB::bind_method(D_METHOD("texture_get_width", "texture"), &VisualServer::texture_get_width);
  1544. ClassDB::bind_method(D_METHOD("texture_get_height", "texture"), &VisualServer::texture_get_height);
  1545. ClassDB::bind_method(D_METHOD("texture_get_depth", "texture"), &VisualServer::texture_get_depth);
  1546. ClassDB::bind_method(D_METHOD("texture_set_size_override", "texture", "width", "height", "depth"), &VisualServer::texture_set_size_override);
  1547. ClassDB::bind_method(D_METHOD("texture_set_path", "texture", "path"), &VisualServer::texture_set_path);
  1548. ClassDB::bind_method(D_METHOD("texture_get_path", "texture"), &VisualServer::texture_get_path);
  1549. ClassDB::bind_method(D_METHOD("texture_set_shrink_all_x2_on_set_data", "shrink"), &VisualServer::texture_set_shrink_all_x2_on_set_data);
  1550. ClassDB::bind_method(D_METHOD("texture_set_proxy", "proxy", "base"), &VisualServer::texture_set_proxy);
  1551. ClassDB::bind_method(D_METHOD("texture_bind", "texture", "number"), &VisualServer::texture_bind);
  1552. ClassDB::bind_method(D_METHOD("texture_debug_usage"), &VisualServer::_texture_debug_usage_bind);
  1553. ClassDB::bind_method(D_METHOD("textures_keep_original", "enable"), &VisualServer::textures_keep_original);
  1554. #ifndef _3D_DISABLED
  1555. ClassDB::bind_method(D_METHOD("sky_create"), &VisualServer::sky_create);
  1556. ClassDB::bind_method(D_METHOD("sky_set_texture", "sky", "cube_map", "radiance_size"), &VisualServer::sky_set_texture);
  1557. #endif
  1558. ClassDB::bind_method(D_METHOD("shader_create"), &VisualServer::shader_create);
  1559. ClassDB::bind_method(D_METHOD("shader_set_code", "shader", "code"), &VisualServer::shader_set_code);
  1560. ClassDB::bind_method(D_METHOD("shader_get_code", "shader"), &VisualServer::shader_get_code);
  1561. ClassDB::bind_method(D_METHOD("shader_get_param_list", "shader"), &VisualServer::_shader_get_param_list_bind);
  1562. ClassDB::bind_method(D_METHOD("shader_set_default_texture_param", "shader", "name", "texture"), &VisualServer::shader_set_default_texture_param);
  1563. ClassDB::bind_method(D_METHOD("shader_get_default_texture_param", "shader", "name"), &VisualServer::shader_get_default_texture_param);
  1564. ClassDB::bind_method(D_METHOD("set_shader_async_hidden_forbidden", "forbidden"), &VisualServer::set_shader_async_hidden_forbidden);
  1565. ClassDB::bind_method(D_METHOD("material_create"), &VisualServer::material_create);
  1566. ClassDB::bind_method(D_METHOD("material_set_shader", "shader_material", "shader"), &VisualServer::material_set_shader);
  1567. ClassDB::bind_method(D_METHOD("material_get_shader", "shader_material"), &VisualServer::material_get_shader);
  1568. ClassDB::bind_method(D_METHOD("material_set_param", "material", "parameter", "value"), &VisualServer::material_set_param);
  1569. ClassDB::bind_method(D_METHOD("material_get_param", "material", "parameter"), &VisualServer::material_get_param);
  1570. ClassDB::bind_method(D_METHOD("material_get_param_default", "material", "parameter"), &VisualServer::material_get_param_default);
  1571. ClassDB::bind_method(D_METHOD("material_set_render_priority", "material", "priority"), &VisualServer::material_set_render_priority);
  1572. ClassDB::bind_method(D_METHOD("material_set_line_width", "material", "width"), &VisualServer::material_set_line_width);
  1573. ClassDB::bind_method(D_METHOD("material_set_next_pass", "material", "next_material"), &VisualServer::material_set_next_pass);
  1574. ClassDB::bind_method(D_METHOD("mesh_create"), &VisualServer::mesh_create);
  1575. ClassDB::bind_method(D_METHOD("mesh_surface_get_format_offset", "format", "vertex_len", "index_len", "array_index"), &VisualServer::mesh_surface_get_format_offset);
  1576. ClassDB::bind_method(D_METHOD("mesh_surface_get_format_stride", "format", "vertex_len", "index_len", "array_index"), &VisualServer::mesh_surface_get_format_stride);
  1577. ClassDB::bind_method(D_METHOD("mesh_add_surface_from_arrays", "mesh", "primitive", "arrays", "blend_shapes", "compress_format"), &VisualServer::mesh_add_surface_from_arrays, DEFVAL(Array()), DEFVAL(ARRAY_COMPRESS_DEFAULT));
  1578. ClassDB::bind_method(D_METHOD("mesh_set_blend_shape_count", "mesh", "amount"), &VisualServer::mesh_set_blend_shape_count);
  1579. ClassDB::bind_method(D_METHOD("mesh_get_blend_shape_count", "mesh"), &VisualServer::mesh_get_blend_shape_count);
  1580. ClassDB::bind_method(D_METHOD("mesh_set_blend_shape_mode", "mesh", "mode"), &VisualServer::mesh_set_blend_shape_mode);
  1581. ClassDB::bind_method(D_METHOD("mesh_get_blend_shape_mode", "mesh"), &VisualServer::mesh_get_blend_shape_mode);
  1582. ClassDB::bind_method(D_METHOD("mesh_surface_update_region", "mesh", "surface", "offset", "data"), &VisualServer::mesh_surface_update_region);
  1583. ClassDB::bind_method(D_METHOD("mesh_surface_set_material", "mesh", "surface", "material"), &VisualServer::mesh_surface_set_material);
  1584. ClassDB::bind_method(D_METHOD("mesh_surface_get_material", "mesh", "surface"), &VisualServer::mesh_surface_get_material);
  1585. ClassDB::bind_method(D_METHOD("mesh_surface_get_array_len", "mesh", "surface"), &VisualServer::mesh_surface_get_array_len);
  1586. ClassDB::bind_method(D_METHOD("mesh_surface_get_array_index_len", "mesh", "surface"), &VisualServer::mesh_surface_get_array_index_len);
  1587. ClassDB::bind_method(D_METHOD("mesh_surface_get_array", "mesh", "surface"), &VisualServer::mesh_surface_get_array);
  1588. ClassDB::bind_method(D_METHOD("mesh_surface_get_index_array", "mesh", "surface"), &VisualServer::mesh_surface_get_index_array);
  1589. ClassDB::bind_method(D_METHOD("mesh_surface_get_arrays", "mesh", "surface"), &VisualServer::mesh_surface_get_arrays);
  1590. ClassDB::bind_method(D_METHOD("mesh_surface_get_blend_shape_arrays", "mesh", "surface"), &VisualServer::mesh_surface_get_blend_shape_arrays);
  1591. ClassDB::bind_method(D_METHOD("mesh_surface_get_format", "mesh", "surface"), &VisualServer::mesh_surface_get_format);
  1592. ClassDB::bind_method(D_METHOD("mesh_surface_get_primitive_type", "mesh", "surface"), &VisualServer::mesh_surface_get_primitive_type);
  1593. ClassDB::bind_method(D_METHOD("mesh_surface_get_aabb", "mesh", "surface"), &VisualServer::mesh_surface_get_aabb);
  1594. ClassDB::bind_method(D_METHOD("mesh_surface_get_skeleton_aabb", "mesh", "surface"), &VisualServer::_mesh_surface_get_skeleton_aabb_bind);
  1595. ClassDB::bind_method(D_METHOD("mesh_remove_surface", "mesh", "index"), &VisualServer::mesh_remove_surface);
  1596. ClassDB::bind_method(D_METHOD("mesh_get_surface_count", "mesh"), &VisualServer::mesh_get_surface_count);
  1597. ClassDB::bind_method(D_METHOD("mesh_set_custom_aabb", "mesh", "aabb"), &VisualServer::mesh_set_custom_aabb);
  1598. ClassDB::bind_method(D_METHOD("mesh_get_custom_aabb", "mesh"), &VisualServer::mesh_get_custom_aabb);
  1599. ClassDB::bind_method(D_METHOD("mesh_clear", "mesh"), &VisualServer::mesh_clear);
  1600. ClassDB::bind_method(D_METHOD("multimesh_create"), &VisualServer::multimesh_create);
  1601. ClassDB::bind_method(D_METHOD("multimesh_allocate", "multimesh", "instances", "transform_format", "color_format", "custom_data_format"), &VisualServer::multimesh_allocate, DEFVAL(MULTIMESH_CUSTOM_DATA_NONE));
  1602. ClassDB::bind_method(D_METHOD("multimesh_get_instance_count", "multimesh"), &VisualServer::multimesh_get_instance_count);
  1603. ClassDB::bind_method(D_METHOD("multimesh_set_mesh", "multimesh", "mesh"), &VisualServer::multimesh_set_mesh);
  1604. ClassDB::bind_method(D_METHOD("multimesh_instance_set_transform", "multimesh", "index", "transform"), &VisualServer::multimesh_instance_set_transform);
  1605. ClassDB::bind_method(D_METHOD("multimesh_instance_set_transform_2d", "multimesh", "index", "transform"), &VisualServer::multimesh_instance_set_transform_2d);
  1606. ClassDB::bind_method(D_METHOD("multimesh_instance_set_color", "multimesh", "index", "color"), &VisualServer::multimesh_instance_set_color);
  1607. ClassDB::bind_method(D_METHOD("multimesh_instance_set_custom_data", "multimesh", "index", "custom_data"), &VisualServer::multimesh_instance_set_custom_data);
  1608. ClassDB::bind_method(D_METHOD("multimesh_get_mesh", "multimesh"), &VisualServer::multimesh_get_mesh);
  1609. ClassDB::bind_method(D_METHOD("multimesh_get_aabb", "multimesh"), &VisualServer::multimesh_get_aabb);
  1610. ClassDB::bind_method(D_METHOD("multimesh_instance_get_transform", "multimesh", "index"), &VisualServer::multimesh_instance_get_transform);
  1611. ClassDB::bind_method(D_METHOD("multimesh_instance_get_transform_2d", "multimesh", "index"), &VisualServer::multimesh_instance_get_transform_2d);
  1612. ClassDB::bind_method(D_METHOD("multimesh_instance_get_color", "multimesh", "index"), &VisualServer::multimesh_instance_get_color);
  1613. ClassDB::bind_method(D_METHOD("multimesh_instance_get_custom_data", "multimesh", "index"), &VisualServer::multimesh_instance_get_custom_data);
  1614. ClassDB::bind_method(D_METHOD("multimesh_set_visible_instances", "multimesh", "visible"), &VisualServer::multimesh_set_visible_instances);
  1615. ClassDB::bind_method(D_METHOD("multimesh_get_visible_instances", "multimesh"), &VisualServer::multimesh_get_visible_instances);
  1616. ClassDB::bind_method(D_METHOD("multimesh_set_as_bulk_array", "multimesh", "array"), &VisualServer::multimesh_set_as_bulk_array);
  1617. ClassDB::bind_method(D_METHOD("multimesh_set_as_bulk_array_interpolated", "multimesh", "array", "array_previous"), &VisualServer::multimesh_set_as_bulk_array_interpolated);
  1618. ClassDB::bind_method(D_METHOD("multimesh_set_physics_interpolated", "multimesh", "interpolated"), &VisualServer::multimesh_set_physics_interpolated);
  1619. ClassDB::bind_method(D_METHOD("multimesh_set_physics_interpolation_quality", "multimesh", "quality"), &VisualServer::multimesh_set_physics_interpolation_quality);
  1620. ClassDB::bind_method(D_METHOD("multimesh_instance_reset_physics_interpolation", "multimesh", "index"), &VisualServer::multimesh_instance_reset_physics_interpolation);
  1621. #ifndef _3D_DISABLED
  1622. ClassDB::bind_method(D_METHOD("immediate_create"), &VisualServer::immediate_create);
  1623. ClassDB::bind_method(D_METHOD("immediate_begin", "immediate", "primitive", "texture"), &VisualServer::immediate_begin, DEFVAL(RID()));
  1624. ClassDB::bind_method(D_METHOD("immediate_vertex", "immediate", "vertex"), &VisualServer::immediate_vertex);
  1625. ClassDB::bind_method(D_METHOD("immediate_vertex_2d", "immediate", "vertex"), &VisualServer::immediate_vertex_2d);
  1626. ClassDB::bind_method(D_METHOD("immediate_normal", "immediate", "normal"), &VisualServer::immediate_normal);
  1627. ClassDB::bind_method(D_METHOD("immediate_tangent", "immediate", "tangent"), &VisualServer::immediate_tangent);
  1628. ClassDB::bind_method(D_METHOD("immediate_color", "immediate", "color"), &VisualServer::immediate_color);
  1629. ClassDB::bind_method(D_METHOD("immediate_uv", "immediate", "tex_uv"), &VisualServer::immediate_uv);
  1630. ClassDB::bind_method(D_METHOD("immediate_uv2", "immediate", "tex_uv"), &VisualServer::immediate_uv2);
  1631. ClassDB::bind_method(D_METHOD("immediate_end", "immediate"), &VisualServer::immediate_end);
  1632. ClassDB::bind_method(D_METHOD("immediate_clear", "immediate"), &VisualServer::immediate_clear);
  1633. ClassDB::bind_method(D_METHOD("immediate_set_material", "immediate", "material"), &VisualServer::immediate_set_material);
  1634. ClassDB::bind_method(D_METHOD("immediate_get_material", "immediate"), &VisualServer::immediate_get_material);
  1635. #endif
  1636. ClassDB::bind_method(D_METHOD("skeleton_create"), &VisualServer::skeleton_create);
  1637. ClassDB::bind_method(D_METHOD("skeleton_allocate", "skeleton", "bones", "is_2d_skeleton"), &VisualServer::skeleton_allocate, DEFVAL(false));
  1638. ClassDB::bind_method(D_METHOD("skeleton_get_bone_count", "skeleton"), &VisualServer::skeleton_get_bone_count);
  1639. ClassDB::bind_method(D_METHOD("skeleton_bone_set_transform", "skeleton", "bone", "transform"), &VisualServer::skeleton_bone_set_transform);
  1640. ClassDB::bind_method(D_METHOD("skeleton_bone_get_transform", "skeleton", "bone"), &VisualServer::skeleton_bone_get_transform);
  1641. ClassDB::bind_method(D_METHOD("skeleton_bone_set_transform_2d", "skeleton", "bone", "transform"), &VisualServer::skeleton_bone_set_transform_2d);
  1642. ClassDB::bind_method(D_METHOD("skeleton_bone_get_transform_2d", "skeleton", "bone"), &VisualServer::skeleton_bone_get_transform_2d);
  1643. #ifndef _3D_DISABLED
  1644. ClassDB::bind_method(D_METHOD("directional_light_create"), &VisualServer::directional_light_create);
  1645. ClassDB::bind_method(D_METHOD("omni_light_create"), &VisualServer::omni_light_create);
  1646. ClassDB::bind_method(D_METHOD("spot_light_create"), &VisualServer::spot_light_create);
  1647. ClassDB::bind_method(D_METHOD("light_set_color", "light", "color"), &VisualServer::light_set_color);
  1648. ClassDB::bind_method(D_METHOD("light_set_param", "light", "param", "value"), &VisualServer::light_set_param);
  1649. ClassDB::bind_method(D_METHOD("light_set_shadow", "light", "enabled"), &VisualServer::light_set_shadow);
  1650. ClassDB::bind_method(D_METHOD("light_set_shadow_color", "light", "color"), &VisualServer::light_set_shadow_color);
  1651. ClassDB::bind_method(D_METHOD("light_set_projector", "light", "texture"), &VisualServer::light_set_projector);
  1652. ClassDB::bind_method(D_METHOD("light_set_negative", "light", "enable"), &VisualServer::light_set_negative);
  1653. ClassDB::bind_method(D_METHOD("light_set_cull_mask", "light", "mask"), &VisualServer::light_set_cull_mask);
  1654. ClassDB::bind_method(D_METHOD("light_set_reverse_cull_face_mode", "light", "enabled"), &VisualServer::light_set_reverse_cull_face_mode);
  1655. ClassDB::bind_method(D_METHOD("light_set_use_gi", "light", "enabled"), &VisualServer::light_set_use_gi);
  1656. ClassDB::bind_method(D_METHOD("light_set_bake_mode", "light", "bake_mode"), &VisualServer::light_set_bake_mode);
  1657. ClassDB::bind_method(D_METHOD("light_omni_set_shadow_mode", "light", "mode"), &VisualServer::light_omni_set_shadow_mode);
  1658. ClassDB::bind_method(D_METHOD("light_omni_set_shadow_detail", "light", "detail"), &VisualServer::light_omni_set_shadow_detail);
  1659. ClassDB::bind_method(D_METHOD("light_directional_set_shadow_mode", "light", "mode"), &VisualServer::light_directional_set_shadow_mode);
  1660. ClassDB::bind_method(D_METHOD("light_directional_set_blend_splits", "light", "enable"), &VisualServer::light_directional_set_blend_splits);
  1661. ClassDB::bind_method(D_METHOD("light_directional_set_shadow_depth_range_mode", "light", "range_mode"), &VisualServer::light_directional_set_shadow_depth_range_mode);
  1662. ClassDB::bind_method(D_METHOD("reflection_probe_create"), &VisualServer::reflection_probe_create);
  1663. ClassDB::bind_method(D_METHOD("reflection_probe_set_update_mode", "probe", "mode"), &VisualServer::reflection_probe_set_update_mode);
  1664. ClassDB::bind_method(D_METHOD("reflection_probe_set_intensity", "probe", "intensity"), &VisualServer::reflection_probe_set_intensity);
  1665. ClassDB::bind_method(D_METHOD("reflection_probe_set_interior_ambient", "probe", "color"), &VisualServer::reflection_probe_set_interior_ambient);
  1666. ClassDB::bind_method(D_METHOD("reflection_probe_set_interior_ambient_energy", "probe", "energy"), &VisualServer::reflection_probe_set_interior_ambient_energy);
  1667. ClassDB::bind_method(D_METHOD("reflection_probe_set_interior_ambient_probe_contribution", "probe", "contrib"), &VisualServer::reflection_probe_set_interior_ambient_probe_contribution);
  1668. ClassDB::bind_method(D_METHOD("reflection_probe_set_max_distance", "probe", "distance"), &VisualServer::reflection_probe_set_max_distance);
  1669. ClassDB::bind_method(D_METHOD("reflection_probe_set_extents", "probe", "extents"), &VisualServer::reflection_probe_set_extents);
  1670. ClassDB::bind_method(D_METHOD("reflection_probe_set_origin_offset", "probe", "offset"), &VisualServer::reflection_probe_set_origin_offset);
  1671. ClassDB::bind_method(D_METHOD("reflection_probe_set_as_interior", "probe", "enable"), &VisualServer::reflection_probe_set_as_interior);
  1672. ClassDB::bind_method(D_METHOD("reflection_probe_set_enable_box_projection", "probe", "enable"), &VisualServer::reflection_probe_set_enable_box_projection);
  1673. ClassDB::bind_method(D_METHOD("reflection_probe_set_enable_shadows", "probe", "enable"), &VisualServer::reflection_probe_set_enable_shadows);
  1674. ClassDB::bind_method(D_METHOD("reflection_probe_set_cull_mask", "probe", "layers"), &VisualServer::reflection_probe_set_cull_mask);
  1675. ClassDB::bind_method(D_METHOD("gi_probe_create"), &VisualServer::gi_probe_create);
  1676. ClassDB::bind_method(D_METHOD("gi_probe_set_bounds", "probe", "bounds"), &VisualServer::gi_probe_set_bounds);
  1677. ClassDB::bind_method(D_METHOD("gi_probe_get_bounds", "probe"), &VisualServer::gi_probe_get_bounds);
  1678. ClassDB::bind_method(D_METHOD("gi_probe_set_cell_size", "probe", "range"), &VisualServer::gi_probe_set_cell_size);
  1679. ClassDB::bind_method(D_METHOD("gi_probe_get_cell_size", "probe"), &VisualServer::gi_probe_get_cell_size);
  1680. ClassDB::bind_method(D_METHOD("gi_probe_set_to_cell_xform", "probe", "xform"), &VisualServer::gi_probe_set_to_cell_xform);
  1681. ClassDB::bind_method(D_METHOD("gi_probe_get_to_cell_xform", "probe"), &VisualServer::gi_probe_get_to_cell_xform);
  1682. ClassDB::bind_method(D_METHOD("gi_probe_set_dynamic_data", "probe", "data"), &VisualServer::gi_probe_set_dynamic_data);
  1683. ClassDB::bind_method(D_METHOD("gi_probe_get_dynamic_data", "probe"), &VisualServer::gi_probe_get_dynamic_data);
  1684. ClassDB::bind_method(D_METHOD("gi_probe_set_dynamic_range", "probe", "range"), &VisualServer::gi_probe_set_dynamic_range);
  1685. ClassDB::bind_method(D_METHOD("gi_probe_get_dynamic_range", "probe"), &VisualServer::gi_probe_get_dynamic_range);
  1686. ClassDB::bind_method(D_METHOD("gi_probe_set_energy", "probe", "energy"), &VisualServer::gi_probe_set_energy);
  1687. ClassDB::bind_method(D_METHOD("gi_probe_get_energy", "probe"), &VisualServer::gi_probe_get_energy);
  1688. ClassDB::bind_method(D_METHOD("gi_probe_set_bias", "probe", "bias"), &VisualServer::gi_probe_set_bias);
  1689. ClassDB::bind_method(D_METHOD("gi_probe_get_bias", "probe"), &VisualServer::gi_probe_get_bias);
  1690. ClassDB::bind_method(D_METHOD("gi_probe_set_normal_bias", "probe", "bias"), &VisualServer::gi_probe_set_normal_bias);
  1691. ClassDB::bind_method(D_METHOD("gi_probe_get_normal_bias", "probe"), &VisualServer::gi_probe_get_normal_bias);
  1692. ClassDB::bind_method(D_METHOD("gi_probe_set_propagation", "probe", "propagation"), &VisualServer::gi_probe_set_propagation);
  1693. ClassDB::bind_method(D_METHOD("gi_probe_get_propagation", "probe"), &VisualServer::gi_probe_get_propagation);
  1694. ClassDB::bind_method(D_METHOD("gi_probe_set_interior", "probe", "enable"), &VisualServer::gi_probe_set_interior);
  1695. ClassDB::bind_method(D_METHOD("gi_probe_is_interior", "probe"), &VisualServer::gi_probe_is_interior);
  1696. ClassDB::bind_method(D_METHOD("gi_probe_set_compress", "probe", "enable"), &VisualServer::gi_probe_set_compress);
  1697. ClassDB::bind_method(D_METHOD("gi_probe_is_compressed", "probe"), &VisualServer::gi_probe_is_compressed);
  1698. ClassDB::bind_method(D_METHOD("lightmap_capture_create"), &VisualServer::lightmap_capture_create);
  1699. ClassDB::bind_method(D_METHOD("lightmap_capture_set_bounds", "capture", "bounds"), &VisualServer::lightmap_capture_set_bounds);
  1700. ClassDB::bind_method(D_METHOD("lightmap_capture_get_bounds", "capture"), &VisualServer::lightmap_capture_get_bounds);
  1701. ClassDB::bind_method(D_METHOD("lightmap_capture_set_octree", "capture", "octree"), &VisualServer::lightmap_capture_set_octree);
  1702. ClassDB::bind_method(D_METHOD("lightmap_capture_set_octree_cell_transform", "capture", "xform"), &VisualServer::lightmap_capture_set_octree_cell_transform);
  1703. ClassDB::bind_method(D_METHOD("lightmap_capture_get_octree_cell_transform", "capture"), &VisualServer::lightmap_capture_get_octree_cell_transform);
  1704. ClassDB::bind_method(D_METHOD("lightmap_capture_set_octree_cell_subdiv", "capture", "subdiv"), &VisualServer::lightmap_capture_set_octree_cell_subdiv);
  1705. ClassDB::bind_method(D_METHOD("lightmap_capture_get_octree_cell_subdiv", "capture"), &VisualServer::lightmap_capture_get_octree_cell_subdiv);
  1706. ClassDB::bind_method(D_METHOD("lightmap_capture_get_octree", "capture"), &VisualServer::lightmap_capture_get_octree);
  1707. ClassDB::bind_method(D_METHOD("lightmap_capture_set_energy", "capture", "energy"), &VisualServer::lightmap_capture_set_energy);
  1708. ClassDB::bind_method(D_METHOD("lightmap_capture_get_energy", "capture"), &VisualServer::lightmap_capture_get_energy);
  1709. ClassDB::bind_method(D_METHOD("lightmap_capture_set_interior", "capture", "interior"), &VisualServer::lightmap_capture_set_interior);
  1710. ClassDB::bind_method(D_METHOD("lightmap_capture_is_interior", "capture"), &VisualServer::lightmap_capture_is_interior);
  1711. #endif
  1712. ClassDB::bind_method(D_METHOD("particles_create"), &VisualServer::particles_create);
  1713. ClassDB::bind_method(D_METHOD("particles_set_emitting", "particles", "emitting"), &VisualServer::particles_set_emitting);
  1714. ClassDB::bind_method(D_METHOD("particles_get_emitting", "particles"), &VisualServer::particles_get_emitting);
  1715. ClassDB::bind_method(D_METHOD("particles_set_amount", "particles", "amount"), &VisualServer::particles_set_amount);
  1716. ClassDB::bind_method(D_METHOD("particles_set_lifetime", "particles", "lifetime"), &VisualServer::particles_set_lifetime);
  1717. ClassDB::bind_method(D_METHOD("particles_set_one_shot", "particles", "one_shot"), &VisualServer::particles_set_one_shot);
  1718. ClassDB::bind_method(D_METHOD("particles_set_pre_process_time", "particles", "time"), &VisualServer::particles_set_pre_process_time);
  1719. ClassDB::bind_method(D_METHOD("particles_set_explosiveness_ratio", "particles", "ratio"), &VisualServer::particles_set_explosiveness_ratio);
  1720. ClassDB::bind_method(D_METHOD("particles_set_randomness_ratio", "particles", "ratio"), &VisualServer::particles_set_randomness_ratio);
  1721. ClassDB::bind_method(D_METHOD("particles_set_custom_aabb", "particles", "aabb"), &VisualServer::particles_set_custom_aabb);
  1722. ClassDB::bind_method(D_METHOD("particles_set_speed_scale", "particles", "scale"), &VisualServer::particles_set_speed_scale);
  1723. ClassDB::bind_method(D_METHOD("particles_set_use_local_coordinates", "particles", "enable"), &VisualServer::particles_set_use_local_coordinates);
  1724. ClassDB::bind_method(D_METHOD("particles_set_process_material", "particles", "material"), &VisualServer::particles_set_process_material);
  1725. ClassDB::bind_method(D_METHOD("particles_set_fixed_fps", "particles", "fps"), &VisualServer::particles_set_fixed_fps);
  1726. ClassDB::bind_method(D_METHOD("particles_set_fractional_delta", "particles", "enable"), &VisualServer::particles_set_fractional_delta);
  1727. ClassDB::bind_method(D_METHOD("particles_is_inactive", "particles"), &VisualServer::particles_is_inactive);
  1728. ClassDB::bind_method(D_METHOD("particles_request_process", "particles"), &VisualServer::particles_request_process);
  1729. ClassDB::bind_method(D_METHOD("particles_restart", "particles"), &VisualServer::particles_restart);
  1730. ClassDB::bind_method(D_METHOD("particles_set_draw_order", "particles", "order"), &VisualServer::particles_set_draw_order);
  1731. ClassDB::bind_method(D_METHOD("particles_set_draw_passes", "particles", "count"), &VisualServer::particles_set_draw_passes);
  1732. ClassDB::bind_method(D_METHOD("particles_set_draw_pass_mesh", "particles", "pass", "mesh"), &VisualServer::particles_set_draw_pass_mesh);
  1733. ClassDB::bind_method(D_METHOD("particles_get_current_aabb", "particles"), &VisualServer::particles_get_current_aabb);
  1734. ClassDB::bind_method(D_METHOD("particles_set_emission_transform", "particles", "transform"), &VisualServer::particles_set_emission_transform);
  1735. ClassDB::bind_method(D_METHOD("camera_create"), &VisualServer::camera_create);
  1736. ClassDB::bind_method(D_METHOD("camera_set_perspective", "camera", "fovy_degrees", "z_near", "z_far"), &VisualServer::camera_set_perspective);
  1737. ClassDB::bind_method(D_METHOD("camera_set_orthogonal", "camera", "size", "z_near", "z_far"), &VisualServer::camera_set_orthogonal);
  1738. ClassDB::bind_method(D_METHOD("camera_set_frustum", "camera", "size", "offset", "z_near", "z_far"), &VisualServer::camera_set_frustum);
  1739. ClassDB::bind_method(D_METHOD("camera_set_transform", "camera", "transform"), &VisualServer::camera_set_transform);
  1740. ClassDB::bind_method(D_METHOD("camera_set_cull_mask", "camera", "layers"), &VisualServer::camera_set_cull_mask);
  1741. ClassDB::bind_method(D_METHOD("camera_set_environment", "camera", "env"), &VisualServer::camera_set_environment);
  1742. ClassDB::bind_method(D_METHOD("camera_set_use_vertical_aspect", "camera", "enable"), &VisualServer::camera_set_use_vertical_aspect);
  1743. ClassDB::bind_method(D_METHOD("viewport_create"), &VisualServer::viewport_create);
  1744. ClassDB::bind_method(D_METHOD("viewport_set_use_arvr", "viewport", "use_arvr"), &VisualServer::viewport_set_use_arvr);
  1745. ClassDB::bind_method(D_METHOD("viewport_set_size", "viewport", "width", "height"), &VisualServer::viewport_set_size);
  1746. ClassDB::bind_method(D_METHOD("viewport_set_active", "viewport", "active"), &VisualServer::viewport_set_active);
  1747. ClassDB::bind_method(D_METHOD("viewport_set_parent_viewport", "viewport", "parent_viewport"), &VisualServer::viewport_set_parent_viewport);
  1748. ClassDB::bind_method(D_METHOD("viewport_attach_to_screen", "viewport", "rect", "screen"), &VisualServer::viewport_attach_to_screen, DEFVAL(Rect2()), DEFVAL(0));
  1749. ClassDB::bind_method(D_METHOD("viewport_set_render_direct_to_screen", "viewport", "enabled"), &VisualServer::viewport_set_render_direct_to_screen);
  1750. ClassDB::bind_method(D_METHOD("viewport_detach", "viewport"), &VisualServer::viewport_detach);
  1751. ClassDB::bind_method(D_METHOD("viewport_set_update_mode", "viewport", "update_mode"), &VisualServer::viewport_set_update_mode);
  1752. ClassDB::bind_method(D_METHOD("viewport_set_vflip", "viewport", "enabled"), &VisualServer::viewport_set_vflip);
  1753. ClassDB::bind_method(D_METHOD("viewport_set_clear_mode", "viewport", "clear_mode"), &VisualServer::viewport_set_clear_mode);
  1754. ClassDB::bind_method(D_METHOD("viewport_get_texture", "viewport"), &VisualServer::viewport_get_texture);
  1755. ClassDB::bind_method(D_METHOD("viewport_set_hide_scenario", "viewport", "hidden"), &VisualServer::viewport_set_hide_scenario);
  1756. ClassDB::bind_method(D_METHOD("viewport_set_hide_canvas", "viewport", "hidden"), &VisualServer::viewport_set_hide_canvas);
  1757. ClassDB::bind_method(D_METHOD("viewport_set_disable_environment", "viewport", "disabled"), &VisualServer::viewport_set_disable_environment);
  1758. ClassDB::bind_method(D_METHOD("viewport_set_disable_3d", "viewport", "disabled"), &VisualServer::viewport_set_disable_3d);
  1759. ClassDB::bind_method(D_METHOD("viewport_attach_camera", "viewport", "camera"), &VisualServer::viewport_attach_camera);
  1760. ClassDB::bind_method(D_METHOD("viewport_set_scenario", "viewport", "scenario"), &VisualServer::viewport_set_scenario);
  1761. ClassDB::bind_method(D_METHOD("viewport_attach_canvas", "viewport", "canvas"), &VisualServer::viewport_attach_canvas);
  1762. ClassDB::bind_method(D_METHOD("viewport_remove_canvas", "viewport", "canvas"), &VisualServer::viewport_remove_canvas);
  1763. ClassDB::bind_method(D_METHOD("viewport_set_canvas_transform", "viewport", "canvas", "offset"), &VisualServer::viewport_set_canvas_transform);
  1764. ClassDB::bind_method(D_METHOD("viewport_set_transparent_background", "viewport", "enabled"), &VisualServer::viewport_set_transparent_background);
  1765. ClassDB::bind_method(D_METHOD("viewport_set_global_canvas_transform", "viewport", "transform"), &VisualServer::viewport_set_global_canvas_transform);
  1766. ClassDB::bind_method(D_METHOD("viewport_set_canvas_stacking", "viewport", "canvas", "layer", "sublayer"), &VisualServer::viewport_set_canvas_stacking);
  1767. ClassDB::bind_method(D_METHOD("viewport_set_shadow_atlas_size", "viewport", "size"), &VisualServer::viewport_set_shadow_atlas_size);
  1768. ClassDB::bind_method(D_METHOD("viewport_set_shadow_atlas_quadrant_subdivision", "viewport", "quadrant", "subdivision"), &VisualServer::viewport_set_shadow_atlas_quadrant_subdivision);
  1769. ClassDB::bind_method(D_METHOD("viewport_set_msaa", "viewport", "msaa"), &VisualServer::viewport_set_msaa);
  1770. ClassDB::bind_method(D_METHOD("viewport_set_use_fxaa", "viewport", "fxaa"), &VisualServer::viewport_set_use_fxaa);
  1771. ClassDB::bind_method(D_METHOD("viewport_set_use_debanding", "viewport", "debanding"), &VisualServer::viewport_set_use_debanding);
  1772. ClassDB::bind_method(D_METHOD("viewport_set_sharpen_intensity", "viewport", "intensity"), &VisualServer::viewport_set_sharpen_intensity);
  1773. ClassDB::bind_method(D_METHOD("viewport_set_hdr", "viewport", "enabled"), &VisualServer::viewport_set_hdr);
  1774. ClassDB::bind_method(D_METHOD("viewport_set_use_32_bpc_depth", "viewport", "enabled"), &VisualServer::viewport_set_use_32_bpc_depth);
  1775. ClassDB::bind_method(D_METHOD("viewport_set_usage", "viewport", "usage"), &VisualServer::viewport_set_usage);
  1776. ClassDB::bind_method(D_METHOD("viewport_get_render_info", "viewport", "info"), &VisualServer::viewport_get_render_info);
  1777. ClassDB::bind_method(D_METHOD("viewport_set_debug_draw", "viewport", "draw"), &VisualServer::viewport_set_debug_draw);
  1778. ClassDB::bind_method(D_METHOD("environment_create"), &VisualServer::environment_create);
  1779. ClassDB::bind_method(D_METHOD("environment_set_background", "env", "bg"), &VisualServer::environment_set_background);
  1780. ClassDB::bind_method(D_METHOD("environment_set_sky", "env", "sky"), &VisualServer::environment_set_sky);
  1781. ClassDB::bind_method(D_METHOD("environment_set_sky_custom_fov", "env", "scale"), &VisualServer::environment_set_sky_custom_fov);
  1782. ClassDB::bind_method(D_METHOD("environment_set_sky_orientation", "env", "orientation"), &VisualServer::environment_set_sky_orientation);
  1783. ClassDB::bind_method(D_METHOD("environment_set_bg_color", "env", "color"), &VisualServer::environment_set_bg_color);
  1784. ClassDB::bind_method(D_METHOD("environment_set_bg_energy", "env", "energy"), &VisualServer::environment_set_bg_energy);
  1785. ClassDB::bind_method(D_METHOD("environment_set_canvas_max_layer", "env", "max_layer"), &VisualServer::environment_set_canvas_max_layer);
  1786. ClassDB::bind_method(D_METHOD("environment_set_ambient_light", "env", "color", "energy", "sky_contibution"), &VisualServer::environment_set_ambient_light, DEFVAL(1.0), DEFVAL(0.0));
  1787. ClassDB::bind_method(D_METHOD("environment_set_dof_blur_near", "env", "enable", "distance", "transition", "far_amount", "quality"), &VisualServer::environment_set_dof_blur_near);
  1788. ClassDB::bind_method(D_METHOD("environment_set_dof_blur_far", "env", "enable", "distance", "transition", "far_amount", "quality"), &VisualServer::environment_set_dof_blur_far);
  1789. ClassDB::bind_method(D_METHOD("environment_set_glow", "env", "enable", "level_flags", "intensity", "strength", "bloom_threshold", "blend_mode", "hdr_bleed_threshold", "hdr_bleed_scale", "hdr_luminance_cap", "bicubic_upscale", "high_quality"), &VisualServer::environment_set_glow);
  1790. ClassDB::bind_method(D_METHOD("environment_set_glow_map", "env", "glow_map_strength", "glow_map"), &VisualServer::environment_set_glow_map);
  1791. ClassDB::bind_method(D_METHOD("environment_set_tonemap", "env", "tone_mapper", "exposure", "white", "auto_exposure", "min_luminance", "max_luminance", "auto_exp_speed", "auto_exp_grey"), &VisualServer::environment_set_tonemap);
  1792. ClassDB::bind_method(D_METHOD("environment_set_adjustment", "env", "enable", "brightness", "contrast", "saturation", "ramp"), &VisualServer::environment_set_adjustment);
  1793. ClassDB::bind_method(D_METHOD("environment_set_ssr", "env", "enable", "max_steps", "fade_in", "fade_out", "depth_tolerance", "roughness"), &VisualServer::environment_set_ssr);
  1794. ClassDB::bind_method(D_METHOD("environment_set_ssao", "env", "enable", "radius", "intensity", "radius2", "intensity2", "bias", "light_affect", "ao_channel_affect", "color", "quality", "blur", "bilateral_sharpness"), &VisualServer::environment_set_ssao);
  1795. ClassDB::bind_method(D_METHOD("environment_set_fog", "env", "enable", "color", "sun_color", "sun_amount"), &VisualServer::environment_set_fog);
  1796. ClassDB::bind_method(D_METHOD("environment_set_fog_depth", "env", "enable", "depth_begin", "depth_end", "depth_curve", "transmit", "transmit_curve"), &VisualServer::environment_set_fog_depth);
  1797. ClassDB::bind_method(D_METHOD("environment_set_fog_height", "env", "enable", "min_height", "max_height", "height_curve"), &VisualServer::environment_set_fog_height);
  1798. ClassDB::bind_method(D_METHOD("scenario_create"), &VisualServer::scenario_create);
  1799. ClassDB::bind_method(D_METHOD("scenario_set_debug", "scenario", "debug_mode"), &VisualServer::scenario_set_debug);
  1800. ClassDB::bind_method(D_METHOD("scenario_set_environment", "scenario", "environment"), &VisualServer::scenario_set_environment);
  1801. ClassDB::bind_method(D_METHOD("scenario_set_reflection_atlas_size", "scenario", "size", "subdiv"), &VisualServer::scenario_set_reflection_atlas_size);
  1802. ClassDB::bind_method(D_METHOD("scenario_set_fallback_environment", "scenario", "environment"), &VisualServer::scenario_set_fallback_environment);
  1803. #ifndef _3D_DISABLED
  1804. ClassDB::bind_method(D_METHOD("instance_create2", "base", "scenario"), &VisualServer::instance_create2);
  1805. ClassDB::bind_method(D_METHOD("instance_create"), &VisualServer::instance_create);
  1806. ClassDB::bind_method(D_METHOD("instance_set_base", "instance", "base"), &VisualServer::instance_set_base);
  1807. ClassDB::bind_method(D_METHOD("instance_set_scenario", "instance", "scenario"), &VisualServer::instance_set_scenario);
  1808. ClassDB::bind_method(D_METHOD("instance_set_layer_mask", "instance", "mask"), &VisualServer::instance_set_layer_mask);
  1809. ClassDB::bind_method(D_METHOD("instance_set_transform", "instance", "transform"), &VisualServer::instance_set_transform);
  1810. ClassDB::bind_method(D_METHOD("instance_set_interpolated", "instance", "interpolated"), &VisualServer::instance_set_interpolated);
  1811. ClassDB::bind_method(D_METHOD("instance_reset_physics_interpolation", "instance"), &VisualServer::instance_reset_physics_interpolation);
  1812. ClassDB::bind_method(D_METHOD("instance_attach_object_instance_id", "instance", "id"), &VisualServer::instance_attach_object_instance_id);
  1813. ClassDB::bind_method(D_METHOD("instance_set_blend_shape_weight", "instance", "shape", "weight"), &VisualServer::instance_set_blend_shape_weight);
  1814. ClassDB::bind_method(D_METHOD("instance_set_surface_material", "instance", "surface", "material"), &VisualServer::instance_set_surface_material);
  1815. ClassDB::bind_method(D_METHOD("instance_set_visible", "instance", "visible"), &VisualServer::instance_set_visible);
  1816. ClassDB::bind_method(D_METHOD("instance_set_use_lightmap", "instance", "lightmap_instance", "lightmap", "lightmap_slice", "lightmap_uv_rect"), &VisualServer::instance_set_use_lightmap, DEFVAL(-1), DEFVAL(Rect2(0, 0, 1, 1)));
  1817. ClassDB::bind_method(D_METHOD("instance_set_custom_aabb", "instance", "aabb"), &VisualServer::instance_set_custom_aabb);
  1818. ClassDB::bind_method(D_METHOD("instance_attach_skeleton", "instance", "skeleton"), &VisualServer::instance_attach_skeleton);
  1819. ClassDB::bind_method(D_METHOD("instance_set_exterior", "instance", "enabled"), &VisualServer::instance_set_exterior);
  1820. ClassDB::bind_method(D_METHOD("instance_set_extra_visibility_margin", "instance", "margin"), &VisualServer::instance_set_extra_visibility_margin);
  1821. ClassDB::bind_method(D_METHOD("instance_geometry_set_flag", "instance", "flag", "enabled"), &VisualServer::instance_geometry_set_flag);
  1822. ClassDB::bind_method(D_METHOD("instance_geometry_set_cast_shadows_setting", "instance", "shadow_casting_setting"), &VisualServer::instance_geometry_set_cast_shadows_setting);
  1823. ClassDB::bind_method(D_METHOD("instance_geometry_set_material_override", "instance", "material"), &VisualServer::instance_geometry_set_material_override);
  1824. ClassDB::bind_method(D_METHOD("instance_geometry_set_material_overlay", "instance", "material"), &VisualServer::instance_geometry_set_material_overlay);
  1825. ClassDB::bind_method(D_METHOD("instances_cull_aabb", "aabb", "scenario"), &VisualServer::_instances_cull_aabb_bind, DEFVAL(RID()));
  1826. ClassDB::bind_method(D_METHOD("instances_cull_ray", "from", "to", "scenario"), &VisualServer::_instances_cull_ray_bind, DEFVAL(RID()));
  1827. ClassDB::bind_method(D_METHOD("instances_cull_convex", "convex", "scenario"), &VisualServer::_instances_cull_convex_bind, DEFVAL(RID()));
  1828. #endif
  1829. ClassDB::bind_method(D_METHOD("canvas_create"), &VisualServer::canvas_create);
  1830. ClassDB::bind_method(D_METHOD("canvas_set_item_mirroring", "canvas", "item", "mirroring"), &VisualServer::canvas_set_item_mirroring);
  1831. ClassDB::bind_method(D_METHOD("canvas_set_modulate", "canvas", "color"), &VisualServer::canvas_set_modulate);
  1832. ClassDB::bind_method(D_METHOD("canvas_item_create"), &VisualServer::canvas_item_create);
  1833. ClassDB::bind_method(D_METHOD("canvas_item_set_parent", "item", "parent"), &VisualServer::canvas_item_set_parent);
  1834. ClassDB::bind_method(D_METHOD("canvas_item_set_visible", "item", "visible"), &VisualServer::canvas_item_set_visible);
  1835. ClassDB::bind_method(D_METHOD("canvas_item_set_light_mask", "item", "mask"), &VisualServer::canvas_item_set_light_mask);
  1836. ClassDB::bind_method(D_METHOD("canvas_item_set_transform", "item", "transform"), &VisualServer::canvas_item_set_transform);
  1837. ClassDB::bind_method(D_METHOD("canvas_item_set_clip", "item", "clip"), &VisualServer::canvas_item_set_clip);
  1838. ClassDB::bind_method(D_METHOD("canvas_item_set_distance_field_mode", "item", "enabled"), &VisualServer::canvas_item_set_distance_field_mode);
  1839. ClassDB::bind_method(D_METHOD("canvas_item_set_custom_rect", "item", "use_custom_rect", "rect"), &VisualServer::canvas_item_set_custom_rect, DEFVAL(Rect2()));
  1840. ClassDB::bind_method(D_METHOD("canvas_item_set_modulate", "item", "color"), &VisualServer::canvas_item_set_modulate);
  1841. ClassDB::bind_method(D_METHOD("canvas_item_set_self_modulate", "item", "color"), &VisualServer::canvas_item_set_self_modulate);
  1842. ClassDB::bind_method(D_METHOD("canvas_item_set_draw_behind_parent", "item", "enabled"), &VisualServer::canvas_item_set_draw_behind_parent);
  1843. ClassDB::bind_method(D_METHOD("canvas_item_add_line", "item", "from", "to", "color", "width", "antialiased"), &VisualServer::canvas_item_add_line, DEFVAL(1.0), DEFVAL(false));
  1844. ClassDB::bind_method(D_METHOD("canvas_item_add_polyline", "item", "points", "colors", "width", "antialiased"), &VisualServer::canvas_item_add_polyline, DEFVAL(1.0), DEFVAL(false));
  1845. ClassDB::bind_method(D_METHOD("canvas_item_add_rect", "item", "rect", "color"), &VisualServer::canvas_item_add_rect);
  1846. ClassDB::bind_method(D_METHOD("canvas_item_add_circle", "item", "pos", "radius", "color"), &VisualServer::canvas_item_add_circle);
  1847. ClassDB::bind_method(D_METHOD("canvas_item_add_texture_rect", "item", "rect", "texture", "tile", "modulate", "transpose", "normal_map"), &VisualServer::canvas_item_add_texture_rect, DEFVAL(false), DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(RID()));
  1848. ClassDB::bind_method(D_METHOD("canvas_item_add_texture_rect_region", "item", "rect", "texture", "src_rect", "modulate", "transpose", "normal_map", "clip_uv"), &VisualServer::canvas_item_add_texture_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(RID()), DEFVAL(true));
  1849. ClassDB::bind_method(D_METHOD("canvas_item_add_nine_patch", "item", "rect", "source", "texture", "topleft", "bottomright", "x_axis_mode", "y_axis_mode", "draw_center", "modulate", "normal_map"), &VisualServer::canvas_item_add_nine_patch, DEFVAL(NINE_PATCH_STRETCH), DEFVAL(NINE_PATCH_STRETCH), DEFVAL(true), DEFVAL(Color(1, 1, 1)), DEFVAL(RID()));
  1850. ClassDB::bind_method(D_METHOD("canvas_item_add_primitive", "item", "points", "colors", "uvs", "texture", "width", "normal_map"), &VisualServer::canvas_item_add_primitive, DEFVAL(1.0), DEFVAL(RID()));
  1851. ClassDB::bind_method(D_METHOD("canvas_item_add_polygon", "item", "points", "colors", "uvs", "texture", "normal_map", "antialiased"), &VisualServer::canvas_item_add_polygon, DEFVAL(Vector<Point2>()), DEFVAL(RID()), DEFVAL(RID()), DEFVAL(false));
  1852. ClassDB::bind_method(D_METHOD("canvas_item_add_triangle_array", "item", "indices", "points", "colors", "uvs", "bones", "weights", "texture", "count", "normal_map", "antialiased", "antialiasing_use_indices"), &VisualServer::canvas_item_add_triangle_array, DEFVAL(Vector<Point2>()), DEFVAL(Vector<int>()), DEFVAL(Vector<float>()), DEFVAL(RID()), DEFVAL(-1), DEFVAL(RID()), DEFVAL(false), DEFVAL(false));
  1853. ClassDB::bind_method(D_METHOD("canvas_item_add_mesh", "item", "mesh", "transform", "modulate", "texture", "normal_map"), &VisualServer::canvas_item_add_mesh, DEFVAL(Transform2D()), DEFVAL(Color(1, 1, 1)), DEFVAL(RID()), DEFVAL(RID()));
  1854. ClassDB::bind_method(D_METHOD("canvas_item_add_multimesh", "item", "mesh", "texture", "normal_map"), &VisualServer::canvas_item_add_multimesh, DEFVAL(RID()));
  1855. ClassDB::bind_method(D_METHOD("canvas_item_add_particles", "item", "particles", "texture", "normal_map"), &VisualServer::canvas_item_add_particles);
  1856. ClassDB::bind_method(D_METHOD("canvas_item_add_set_transform", "item", "transform"), &VisualServer::canvas_item_add_set_transform);
  1857. ClassDB::bind_method(D_METHOD("canvas_item_add_clip_ignore", "item", "ignore"), &VisualServer::canvas_item_add_clip_ignore);
  1858. ClassDB::bind_method(D_METHOD("canvas_item_set_sort_children_by_y", "item", "enabled"), &VisualServer::canvas_item_set_sort_children_by_y);
  1859. ClassDB::bind_method(D_METHOD("canvas_item_set_z_index", "item", "z_index"), &VisualServer::canvas_item_set_z_index);
  1860. ClassDB::bind_method(D_METHOD("canvas_item_set_z_as_relative_to_parent", "item", "enabled"), &VisualServer::canvas_item_set_z_as_relative_to_parent);
  1861. ClassDB::bind_method(D_METHOD("canvas_item_set_copy_to_backbuffer", "item", "enabled", "rect"), &VisualServer::canvas_item_set_copy_to_backbuffer);
  1862. ClassDB::bind_method(D_METHOD("canvas_item_set_interpolated", "item", "interpolated"), &VisualServer::canvas_item_set_interpolated);
  1863. ClassDB::bind_method(D_METHOD("canvas_item_reset_physics_interpolation", "item"), &VisualServer::canvas_item_reset_physics_interpolation);
  1864. ClassDB::bind_method(D_METHOD("canvas_item_transform_physics_interpolation", "item", "xform"), &VisualServer::canvas_item_transform_physics_interpolation);
  1865. ClassDB::bind_method(D_METHOD("canvas_item_clear", "item"), &VisualServer::canvas_item_clear);
  1866. ClassDB::bind_method(D_METHOD("canvas_item_set_draw_index", "item", "index"), &VisualServer::canvas_item_set_draw_index);
  1867. ClassDB::bind_method(D_METHOD("canvas_item_set_material", "item", "material"), &VisualServer::canvas_item_set_material);
  1868. ClassDB::bind_method(D_METHOD("canvas_item_set_use_parent_material", "item", "enabled"), &VisualServer::canvas_item_set_use_parent_material);
  1869. ClassDB::bind_method(D_METHOD("debug_canvas_item_get_rect", "item"), &VisualServer::debug_canvas_item_get_rect);
  1870. ClassDB::bind_method(D_METHOD("debug_canvas_item_get_local_bound", "item"), &VisualServer::debug_canvas_item_get_local_bound);
  1871. ClassDB::bind_method(D_METHOD("canvas_light_create"), &VisualServer::canvas_light_create);
  1872. ClassDB::bind_method(D_METHOD("canvas_light_attach_to_canvas", "light", "canvas"), &VisualServer::canvas_light_attach_to_canvas);
  1873. ClassDB::bind_method(D_METHOD("canvas_light_set_enabled", "light", "enabled"), &VisualServer::canvas_light_set_enabled);
  1874. ClassDB::bind_method(D_METHOD("canvas_light_set_scale", "light", "scale"), &VisualServer::canvas_light_set_scale);
  1875. ClassDB::bind_method(D_METHOD("canvas_light_set_transform", "light", "transform"), &VisualServer::canvas_light_set_transform);
  1876. ClassDB::bind_method(D_METHOD("canvas_light_set_texture", "light", "texture"), &VisualServer::canvas_light_set_texture);
  1877. ClassDB::bind_method(D_METHOD("canvas_light_set_texture_offset", "light", "offset"), &VisualServer::canvas_light_set_texture_offset);
  1878. ClassDB::bind_method(D_METHOD("canvas_light_set_color", "light", "color"), &VisualServer::canvas_light_set_color);
  1879. ClassDB::bind_method(D_METHOD("canvas_light_set_height", "light", "height"), &VisualServer::canvas_light_set_height);
  1880. ClassDB::bind_method(D_METHOD("canvas_light_set_energy", "light", "energy"), &VisualServer::canvas_light_set_energy);
  1881. ClassDB::bind_method(D_METHOD("canvas_light_set_z_range", "light", "min_z", "max_z"), &VisualServer::canvas_light_set_z_range);
  1882. ClassDB::bind_method(D_METHOD("canvas_light_set_layer_range", "light", "min_layer", "max_layer"), &VisualServer::canvas_light_set_layer_range);
  1883. ClassDB::bind_method(D_METHOD("canvas_light_set_item_cull_mask", "light", "mask"), &VisualServer::canvas_light_set_item_cull_mask);
  1884. ClassDB::bind_method(D_METHOD("canvas_light_set_item_shadow_cull_mask", "light", "mask"), &VisualServer::canvas_light_set_item_shadow_cull_mask);
  1885. ClassDB::bind_method(D_METHOD("canvas_light_set_mode", "light", "mode"), &VisualServer::canvas_light_set_mode);
  1886. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_enabled", "light", "enabled"), &VisualServer::canvas_light_set_shadow_enabled);
  1887. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_buffer_size", "light", "size"), &VisualServer::canvas_light_set_shadow_buffer_size);
  1888. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_gradient_length", "light", "length"), &VisualServer::canvas_light_set_shadow_gradient_length);
  1889. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_filter", "light", "filter"), &VisualServer::canvas_light_set_shadow_filter);
  1890. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_color", "light", "color"), &VisualServer::canvas_light_set_shadow_color);
  1891. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_smooth", "light", "smooth"), &VisualServer::canvas_light_set_shadow_smooth);
  1892. ClassDB::bind_method(D_METHOD("canvas_light_set_interpolated", "light", "interpolated"), &VisualServer::canvas_light_set_interpolated);
  1893. ClassDB::bind_method(D_METHOD("canvas_light_reset_physics_interpolation", "light"), &VisualServer::canvas_light_reset_physics_interpolation);
  1894. ClassDB::bind_method(D_METHOD("canvas_light_transform_physics_interpolation", "light", "xform"), &VisualServer::canvas_light_transform_physics_interpolation);
  1895. ClassDB::bind_method(D_METHOD("canvas_light_occluder_create"), &VisualServer::canvas_light_occluder_create);
  1896. ClassDB::bind_method(D_METHOD("canvas_light_occluder_attach_to_canvas", "occluder", "canvas"), &VisualServer::canvas_light_occluder_attach_to_canvas);
  1897. ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_enabled", "occluder", "enabled"), &VisualServer::canvas_light_occluder_set_enabled);
  1898. ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_polygon", "occluder", "polygon"), &VisualServer::canvas_light_occluder_set_polygon);
  1899. ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_transform", "occluder", "transform"), &VisualServer::canvas_light_occluder_set_transform);
  1900. ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_light_mask", "occluder", "mask"), &VisualServer::canvas_light_occluder_set_light_mask);
  1901. ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_interpolated", "occluder", "interpolated"), &VisualServer::canvas_light_occluder_set_interpolated);
  1902. ClassDB::bind_method(D_METHOD("canvas_light_occluder_reset_physics_interpolation", "occluder"), &VisualServer::canvas_light_occluder_reset_physics_interpolation);
  1903. ClassDB::bind_method(D_METHOD("canvas_light_occluder_transform_physics_interpolation", "occluder", "xform"), &VisualServer::canvas_light_occluder_transform_physics_interpolation);
  1904. ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_create"), &VisualServer::canvas_occluder_polygon_create);
  1905. ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_set_shape", "occluder_polygon", "shape", "closed"), &VisualServer::canvas_occluder_polygon_set_shape);
  1906. ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_set_shape_as_lines", "occluder_polygon", "shape"), &VisualServer::canvas_occluder_polygon_set_shape_as_lines);
  1907. ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_set_cull_mode", "occluder_polygon", "mode"), &VisualServer::canvas_occluder_polygon_set_cull_mode);
  1908. ClassDB::bind_method(D_METHOD("black_bars_set_margins", "left", "top", "right", "bottom"), &VisualServer::black_bars_set_margins);
  1909. ClassDB::bind_method(D_METHOD("black_bars_set_images", "left", "top", "right", "bottom"), &VisualServer::black_bars_set_images);
  1910. ClassDB::bind_method(D_METHOD("free_rid", "rid"), &VisualServer::free); // shouldn't conflict with Object::free()
  1911. ClassDB::bind_method(D_METHOD("request_frame_drawn_callback", "where", "method", "userdata"), &VisualServer::request_frame_drawn_callback);
  1912. ClassDB::bind_method(D_METHOD("has_changed", "queried_priority"), &VisualServer::has_changed, DEFVAL(CHANGED_PRIORITY_ANY));
  1913. ClassDB::bind_method(D_METHOD("init"), &VisualServer::init);
  1914. ClassDB::bind_method(D_METHOD("finish"), &VisualServer::finish);
  1915. ClassDB::bind_method(D_METHOD("get_render_info", "info"), &VisualServer::get_render_info);
  1916. ClassDB::bind_method(D_METHOD("get_video_adapter_name"), &VisualServer::get_video_adapter_name);
  1917. ClassDB::bind_method(D_METHOD("get_video_adapter_vendor"), &VisualServer::get_video_adapter_vendor);
  1918. #ifndef _3D_DISABLED
  1919. ClassDB::bind_method(D_METHOD("make_sphere_mesh", "latitudes", "longitudes", "radius"), &VisualServer::make_sphere_mesh);
  1920. ClassDB::bind_method(D_METHOD("get_test_cube"), &VisualServer::get_test_cube);
  1921. #endif
  1922. ClassDB::bind_method(D_METHOD("get_test_texture"), &VisualServer::get_test_texture);
  1923. ClassDB::bind_method(D_METHOD("get_white_texture"), &VisualServer::get_white_texture);
  1924. ClassDB::bind_method(D_METHOD("set_boot_image", "image", "color", "scale", "use_filter"), &VisualServer::set_boot_image, DEFVAL(true));
  1925. ClassDB::bind_method(D_METHOD("set_default_clear_color", "color"), &VisualServer::set_default_clear_color);
  1926. ClassDB::bind_method(D_METHOD("set_shader_time_scale", "scale"), &VisualServer::set_shader_time_scale);
  1927. ClassDB::bind_method(D_METHOD("has_feature", "feature"), &VisualServer::has_feature);
  1928. ClassDB::bind_method(D_METHOD("has_os_feature", "feature"), &VisualServer::has_os_feature);
  1929. ClassDB::bind_method(D_METHOD("set_debug_generate_wireframes", "generate"), &VisualServer::set_debug_generate_wireframes);
  1930. ClassDB::bind_method(D_METHOD("set_use_occlusion_culling", "enable"), &VisualServer::set_use_occlusion_culling);
  1931. ClassDB::bind_method(D_METHOD("is_render_loop_enabled"), &VisualServer::is_render_loop_enabled);
  1932. ClassDB::bind_method(D_METHOD("set_render_loop_enabled", "enabled"), &VisualServer::set_render_loop_enabled);
  1933. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_loop_enabled"), "set_render_loop_enabled", "is_render_loop_enabled");
  1934. BIND_CONSTANT(NO_INDEX_ARRAY);
  1935. BIND_CONSTANT(ARRAY_WEIGHTS_SIZE);
  1936. BIND_CONSTANT(CANVAS_ITEM_Z_MIN);
  1937. BIND_CONSTANT(CANVAS_ITEM_Z_MAX);
  1938. BIND_CONSTANT(MAX_GLOW_LEVELS);
  1939. BIND_CONSTANT(MAX_CURSORS);
  1940. BIND_CONSTANT(MATERIAL_RENDER_PRIORITY_MIN);
  1941. BIND_CONSTANT(MATERIAL_RENDER_PRIORITY_MAX);
  1942. BIND_ENUM_CONSTANT(CUBEMAP_LEFT);
  1943. BIND_ENUM_CONSTANT(CUBEMAP_RIGHT);
  1944. BIND_ENUM_CONSTANT(CUBEMAP_BOTTOM);
  1945. BIND_ENUM_CONSTANT(CUBEMAP_TOP);
  1946. BIND_ENUM_CONSTANT(CUBEMAP_FRONT);
  1947. BIND_ENUM_CONSTANT(CUBEMAP_BACK);
  1948. BIND_ENUM_CONSTANT(TEXTURE_TYPE_2D);
  1949. BIND_ENUM_CONSTANT(TEXTURE_TYPE_CUBEMAP);
  1950. BIND_ENUM_CONSTANT(TEXTURE_TYPE_2D_ARRAY);
  1951. BIND_ENUM_CONSTANT(TEXTURE_TYPE_3D);
  1952. BIND_ENUM_CONSTANT(TEXTURE_FLAG_MIPMAPS);
  1953. BIND_ENUM_CONSTANT(TEXTURE_FLAG_REPEAT);
  1954. BIND_ENUM_CONSTANT(TEXTURE_FLAG_FILTER);
  1955. BIND_ENUM_CONSTANT(TEXTURE_FLAG_ANISOTROPIC_FILTER);
  1956. BIND_ENUM_CONSTANT(TEXTURE_FLAG_CONVERT_TO_LINEAR);
  1957. BIND_ENUM_CONSTANT(TEXTURE_FLAG_MIRRORED_REPEAT);
  1958. BIND_ENUM_CONSTANT(TEXTURE_FLAG_USED_FOR_STREAMING);
  1959. BIND_ENUM_CONSTANT(TEXTURE_FLAGS_DEFAULT);
  1960. BIND_ENUM_CONSTANT(SHADER_SPATIAL);
  1961. BIND_ENUM_CONSTANT(SHADER_CANVAS_ITEM);
  1962. BIND_ENUM_CONSTANT(SHADER_PARTICLES);
  1963. BIND_ENUM_CONSTANT(SHADER_MAX);
  1964. BIND_ENUM_CONSTANT(ARRAY_VERTEX);
  1965. BIND_ENUM_CONSTANT(ARRAY_NORMAL);
  1966. BIND_ENUM_CONSTANT(ARRAY_TANGENT);
  1967. BIND_ENUM_CONSTANT(ARRAY_COLOR);
  1968. BIND_ENUM_CONSTANT(ARRAY_TEX_UV);
  1969. BIND_ENUM_CONSTANT(ARRAY_TEX_UV2);
  1970. BIND_ENUM_CONSTANT(ARRAY_BONES);
  1971. BIND_ENUM_CONSTANT(ARRAY_WEIGHTS);
  1972. BIND_ENUM_CONSTANT(ARRAY_INDEX);
  1973. BIND_ENUM_CONSTANT(ARRAY_MAX);
  1974. BIND_ENUM_CONSTANT(ARRAY_FORMAT_VERTEX);
  1975. BIND_ENUM_CONSTANT(ARRAY_FORMAT_NORMAL);
  1976. BIND_ENUM_CONSTANT(ARRAY_FORMAT_TANGENT);
  1977. BIND_ENUM_CONSTANT(ARRAY_FORMAT_COLOR);
  1978. BIND_ENUM_CONSTANT(ARRAY_FORMAT_TEX_UV);
  1979. BIND_ENUM_CONSTANT(ARRAY_FORMAT_TEX_UV2);
  1980. BIND_ENUM_CONSTANT(ARRAY_FORMAT_BONES);
  1981. BIND_ENUM_CONSTANT(ARRAY_FORMAT_WEIGHTS);
  1982. BIND_ENUM_CONSTANT(ARRAY_FORMAT_INDEX);
  1983. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_VERTEX);
  1984. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_NORMAL);
  1985. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_TANGENT);
  1986. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_COLOR);
  1987. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_TEX_UV);
  1988. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_TEX_UV2);
  1989. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_BONES);
  1990. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_WEIGHTS);
  1991. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_INDEX);
  1992. BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_2D_VERTICES);
  1993. BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_16_BIT_BONES);
  1994. BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION);
  1995. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_DEFAULT);
  1996. BIND_ENUM_CONSTANT(PRIMITIVE_POINTS);
  1997. BIND_ENUM_CONSTANT(PRIMITIVE_LINES);
  1998. BIND_ENUM_CONSTANT(PRIMITIVE_LINE_STRIP);
  1999. BIND_ENUM_CONSTANT(PRIMITIVE_LINE_LOOP);
  2000. BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLES);
  2001. BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLE_STRIP);
  2002. BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLE_FAN);
  2003. BIND_ENUM_CONSTANT(PRIMITIVE_MAX);
  2004. BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_NORMALIZED);
  2005. BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_RELATIVE);
  2006. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL);
  2007. BIND_ENUM_CONSTANT(LIGHT_OMNI);
  2008. BIND_ENUM_CONSTANT(LIGHT_SPOT);
  2009. BIND_ENUM_CONSTANT(LIGHT_PARAM_ENERGY);
  2010. BIND_ENUM_CONSTANT(LIGHT_PARAM_INDIRECT_ENERGY);
  2011. BIND_ENUM_CONSTANT(LIGHT_PARAM_SIZE);
  2012. BIND_ENUM_CONSTANT(LIGHT_PARAM_SPECULAR);
  2013. BIND_ENUM_CONSTANT(LIGHT_PARAM_RANGE);
  2014. BIND_ENUM_CONSTANT(LIGHT_PARAM_ATTENUATION);
  2015. BIND_ENUM_CONSTANT(LIGHT_PARAM_SPOT_ANGLE);
  2016. BIND_ENUM_CONSTANT(LIGHT_PARAM_SPOT_ATTENUATION);
  2017. BIND_ENUM_CONSTANT(LIGHT_PARAM_CONTACT_SHADOW_SIZE);
  2018. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_MAX_DISTANCE);
  2019. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET);
  2020. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET);
  2021. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET);
  2022. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_NORMAL_BIAS);
  2023. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_BIAS);
  2024. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_BIAS_SPLIT_SCALE);
  2025. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_FADE_START);
  2026. BIND_ENUM_CONSTANT(LIGHT_PARAM_MAX);
  2027. BIND_ENUM_CONSTANT(LIGHT_BAKE_DISABLED);
  2028. BIND_ENUM_CONSTANT(LIGHT_BAKE_INDIRECT);
  2029. BIND_ENUM_CONSTANT(LIGHT_BAKE_ALL);
  2030. BIND_ENUM_CONSTANT(LIGHT_OMNI_SHADOW_DUAL_PARABOLOID);
  2031. BIND_ENUM_CONSTANT(LIGHT_OMNI_SHADOW_CUBE);
  2032. BIND_ENUM_CONSTANT(LIGHT_OMNI_SHADOW_DETAIL_VERTICAL);
  2033. BIND_ENUM_CONSTANT(LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL);
  2034. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL);
  2035. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS);
  2036. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_PARALLEL_3_SPLITS);
  2037. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS);
  2038. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE);
  2039. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_OPTIMIZED);
  2040. BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_DISABLED);
  2041. BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_ONCE);
  2042. BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_WHEN_VISIBLE);
  2043. BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_ALWAYS);
  2044. BIND_ENUM_CONSTANT(VIEWPORT_CLEAR_ALWAYS);
  2045. BIND_ENUM_CONSTANT(VIEWPORT_CLEAR_NEVER);
  2046. BIND_ENUM_CONSTANT(VIEWPORT_CLEAR_ONLY_NEXT_FRAME);
  2047. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_DISABLED);
  2048. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_2X);
  2049. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_4X);
  2050. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_8X);
  2051. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_16X);
  2052. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_EXT_2X);
  2053. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_EXT_4X);
  2054. BIND_ENUM_CONSTANT(VIEWPORT_USAGE_2D);
  2055. BIND_ENUM_CONSTANT(VIEWPORT_USAGE_2D_NO_SAMPLING);
  2056. BIND_ENUM_CONSTANT(VIEWPORT_USAGE_3D);
  2057. BIND_ENUM_CONSTANT(VIEWPORT_USAGE_3D_NO_EFFECTS);
  2058. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME);
  2059. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_VERTICES_IN_FRAME);
  2060. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_MATERIAL_CHANGES_IN_FRAME);
  2061. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_SHADER_CHANGES_IN_FRAME);
  2062. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_SURFACE_CHANGES_IN_FRAME);
  2063. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME);
  2064. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_2D_ITEMS_IN_FRAME);
  2065. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_2D_DRAW_CALLS_IN_FRAME);
  2066. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_MAX);
  2067. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_DISABLED);
  2068. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_UNSHADED);
  2069. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_OVERDRAW);
  2070. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_WIREFRAME);
  2071. BIND_ENUM_CONSTANT(SCENARIO_DEBUG_DISABLED);
  2072. BIND_ENUM_CONSTANT(SCENARIO_DEBUG_WIREFRAME);
  2073. BIND_ENUM_CONSTANT(SCENARIO_DEBUG_OVERDRAW);
  2074. BIND_ENUM_CONSTANT(SCENARIO_DEBUG_SHADELESS);
  2075. BIND_ENUM_CONSTANT(INSTANCE_NONE);
  2076. BIND_ENUM_CONSTANT(INSTANCE_MESH);
  2077. BIND_ENUM_CONSTANT(INSTANCE_MULTIMESH);
  2078. BIND_ENUM_CONSTANT(INSTANCE_IMMEDIATE);
  2079. BIND_ENUM_CONSTANT(INSTANCE_PARTICLES);
  2080. BIND_ENUM_CONSTANT(INSTANCE_LIGHT);
  2081. BIND_ENUM_CONSTANT(INSTANCE_REFLECTION_PROBE);
  2082. BIND_ENUM_CONSTANT(INSTANCE_GI_PROBE);
  2083. BIND_ENUM_CONSTANT(INSTANCE_LIGHTMAP_CAPTURE);
  2084. BIND_ENUM_CONSTANT(INSTANCE_MAX);
  2085. BIND_ENUM_CONSTANT(INSTANCE_GEOMETRY_MASK);
  2086. BIND_ENUM_CONSTANT(INSTANCE_FLAG_USE_BAKED_LIGHT);
  2087. BIND_ENUM_CONSTANT(INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE);
  2088. BIND_ENUM_CONSTANT(INSTANCE_FLAG_MAX);
  2089. BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_OFF);
  2090. BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_ON);
  2091. BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_DOUBLE_SIDED);
  2092. BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_SHADOWS_ONLY);
  2093. BIND_ENUM_CONSTANT(NINE_PATCH_STRETCH);
  2094. BIND_ENUM_CONSTANT(NINE_PATCH_TILE);
  2095. BIND_ENUM_CONSTANT(NINE_PATCH_TILE_FIT);
  2096. BIND_ENUM_CONSTANT(CANVAS_LIGHT_MODE_ADD);
  2097. BIND_ENUM_CONSTANT(CANVAS_LIGHT_MODE_SUB);
  2098. BIND_ENUM_CONSTANT(CANVAS_LIGHT_MODE_MIX);
  2099. BIND_ENUM_CONSTANT(CANVAS_LIGHT_MODE_MASK);
  2100. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_NONE);
  2101. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF3);
  2102. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF5);
  2103. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF7);
  2104. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF9);
  2105. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF13);
  2106. BIND_ENUM_CONSTANT(CANVAS_OCCLUDER_POLYGON_CULL_DISABLED);
  2107. BIND_ENUM_CONSTANT(CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE);
  2108. BIND_ENUM_CONSTANT(CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE);
  2109. BIND_ENUM_CONSTANT(INFO_OBJECTS_IN_FRAME);
  2110. BIND_ENUM_CONSTANT(INFO_VERTICES_IN_FRAME);
  2111. BIND_ENUM_CONSTANT(INFO_MATERIAL_CHANGES_IN_FRAME);
  2112. BIND_ENUM_CONSTANT(INFO_SHADER_CHANGES_IN_FRAME);
  2113. BIND_ENUM_CONSTANT(INFO_SHADER_COMPILES_IN_FRAME);
  2114. BIND_ENUM_CONSTANT(INFO_SURFACE_CHANGES_IN_FRAME);
  2115. BIND_ENUM_CONSTANT(INFO_DRAW_CALLS_IN_FRAME);
  2116. BIND_ENUM_CONSTANT(INFO_2D_ITEMS_IN_FRAME);
  2117. BIND_ENUM_CONSTANT(INFO_2D_DRAW_CALLS_IN_FRAME);
  2118. BIND_ENUM_CONSTANT(INFO_USAGE_VIDEO_MEM_TOTAL);
  2119. BIND_ENUM_CONSTANT(INFO_VIDEO_MEM_USED);
  2120. BIND_ENUM_CONSTANT(INFO_TEXTURE_MEM_USED);
  2121. BIND_ENUM_CONSTANT(INFO_VERTEX_MEM_USED);
  2122. BIND_ENUM_CONSTANT(FEATURE_SHADERS);
  2123. BIND_ENUM_CONSTANT(FEATURE_MULTITHREADED);
  2124. BIND_ENUM_CONSTANT(MULTIMESH_TRANSFORM_2D);
  2125. BIND_ENUM_CONSTANT(MULTIMESH_TRANSFORM_3D);
  2126. BIND_ENUM_CONSTANT(MULTIMESH_COLOR_NONE);
  2127. BIND_ENUM_CONSTANT(MULTIMESH_COLOR_8BIT);
  2128. BIND_ENUM_CONSTANT(MULTIMESH_COLOR_FLOAT);
  2129. BIND_ENUM_CONSTANT(MULTIMESH_CUSTOM_DATA_NONE);
  2130. BIND_ENUM_CONSTANT(MULTIMESH_CUSTOM_DATA_8BIT);
  2131. BIND_ENUM_CONSTANT(MULTIMESH_CUSTOM_DATA_FLOAT);
  2132. BIND_ENUM_CONSTANT(MULTIMESH_INTERP_QUALITY_FAST);
  2133. BIND_ENUM_CONSTANT(MULTIMESH_INTERP_QUALITY_HIGH);
  2134. BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ONCE);
  2135. BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ALWAYS);
  2136. BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_INDEX);
  2137. BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_LIFETIME);
  2138. BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_VIEW_DEPTH);
  2139. BIND_ENUM_CONSTANT(ENV_BG_CLEAR_COLOR);
  2140. BIND_ENUM_CONSTANT(ENV_BG_COLOR);
  2141. BIND_ENUM_CONSTANT(ENV_BG_SKY);
  2142. BIND_ENUM_CONSTANT(ENV_BG_COLOR_SKY);
  2143. BIND_ENUM_CONSTANT(ENV_BG_CANVAS);
  2144. BIND_ENUM_CONSTANT(ENV_BG_KEEP);
  2145. BIND_ENUM_CONSTANT(ENV_BG_MAX);
  2146. BIND_ENUM_CONSTANT(ENV_DOF_BLUR_QUALITY_LOW);
  2147. BIND_ENUM_CONSTANT(ENV_DOF_BLUR_QUALITY_MEDIUM);
  2148. BIND_ENUM_CONSTANT(ENV_DOF_BLUR_QUALITY_HIGH);
  2149. BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_ADDITIVE);
  2150. BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_SCREEN);
  2151. BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_SOFTLIGHT);
  2152. BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_REPLACE);
  2153. BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_LINEAR);
  2154. BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_REINHARD);
  2155. BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_FILMIC);
  2156. BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_ACES);
  2157. BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_ACES_FITTED);
  2158. BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_LOW);
  2159. BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_MEDIUM);
  2160. BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_HIGH);
  2161. BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_DISABLED);
  2162. BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_1x1);
  2163. BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_2x2);
  2164. BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_3x3);
  2165. BIND_ENUM_CONSTANT(CHANGED_PRIORITY_ANY);
  2166. BIND_ENUM_CONSTANT(CHANGED_PRIORITY_LOW);
  2167. BIND_ENUM_CONSTANT(CHANGED_PRIORITY_HIGH);
  2168. ADD_SIGNAL(MethodInfo("frame_pre_draw"));
  2169. ADD_SIGNAL(MethodInfo("frame_post_draw"));
  2170. }
  2171. void VisualServer::_canvas_item_add_style_box(RID p_item, const Rect2 &p_rect, const Rect2 &p_source, RID p_texture, const Vector<float> &p_margins, const Color &p_modulate) {
  2172. ERR_FAIL_COND(p_margins.size() != 4);
  2173. //canvas_item_add_style_box(p_item,p_rect,p_source,p_texture,Vector2(p_margins[0],p_margins[1]),Vector2(p_margins[2],p_margins[3]),true,p_modulate);
  2174. }
  2175. void VisualServer::_camera_set_orthogonal(RID p_camera, float p_size, float p_z_near, float p_z_far) {
  2176. camera_set_orthogonal(p_camera, p_size, p_z_near, p_z_far);
  2177. }
  2178. void VisualServer::mesh_add_surface_from_mesh_data(RID p_mesh, const Geometry::MeshData &p_mesh_data) {
  2179. PoolVector<Vector3> vertices;
  2180. PoolVector<Vector3> normals;
  2181. for (int i = 0; i < p_mesh_data.faces.size(); i++) {
  2182. const Geometry::MeshData::Face &f = p_mesh_data.faces[i];
  2183. for (int j = 2; j < f.indices.size(); j++) {
  2184. #define _ADD_VERTEX(m_idx) \
  2185. vertices.push_back(p_mesh_data.vertices[f.indices[m_idx]]); \
  2186. normals.push_back(f.plane.normal);
  2187. _ADD_VERTEX(0);
  2188. _ADD_VERTEX(j - 1);
  2189. _ADD_VERTEX(j);
  2190. }
  2191. }
  2192. Array d;
  2193. d.resize(VS::ARRAY_MAX);
  2194. d[ARRAY_VERTEX] = vertices;
  2195. d[ARRAY_NORMAL] = normals;
  2196. mesh_add_surface_from_arrays(p_mesh, PRIMITIVE_TRIANGLES, d);
  2197. }
  2198. void VisualServer::mesh_add_surface_from_planes(RID p_mesh, const PoolVector<Plane> &p_planes) {
  2199. Geometry::MeshData mdata = Geometry::build_convex_mesh(p_planes);
  2200. mesh_add_surface_from_mesh_data(p_mesh, mdata);
  2201. }
  2202. void VisualServer::immediate_vertex_2d(RID p_immediate, const Vector2 &p_vertex) {
  2203. immediate_vertex(p_immediate, Vector3(p_vertex.x, p_vertex.y, 0));
  2204. }
  2205. RID VisualServer::instance_create2(RID p_base, RID p_scenario) {
  2206. RID instance = instance_create();
  2207. instance_set_base(instance, p_base);
  2208. instance_set_scenario(instance, p_scenario);
  2209. // instance_create2 is used mainly by editor instances.
  2210. // These should not be culled by the portal system when it is active, so we set their mode to global,
  2211. // for frustum culling only.
  2212. instance_set_portal_mode(instance, VisualServer::INSTANCE_PORTAL_MODE_GLOBAL);
  2213. return instance;
  2214. }
  2215. bool VisualServer::is_render_loop_enabled() const {
  2216. return render_loop_enabled;
  2217. }
  2218. void VisualServer::set_render_loop_enabled(bool p_enabled) {
  2219. render_loop_enabled = p_enabled;
  2220. }
  2221. #ifdef DEBUG_ENABLED
  2222. bool VisualServer::is_force_shader_fallbacks_enabled() const {
  2223. return force_shader_fallbacks;
  2224. }
  2225. void VisualServer::set_force_shader_fallbacks_enabled(bool p_enabled) {
  2226. force_shader_fallbacks = p_enabled;
  2227. }
  2228. #endif
  2229. VisualServer::VisualServer() {
  2230. //ERR_FAIL_COND(singleton);
  2231. singleton = this;
  2232. GLOBAL_DEF_RST("rendering/vram_compression/import_bptc", false);
  2233. GLOBAL_DEF_RST("rendering/vram_compression/import_s3tc", true);
  2234. GLOBAL_DEF_RST("rendering/vram_compression/import_etc", false);
  2235. GLOBAL_DEF_RST("rendering/vram_compression/import_etc2", true);
  2236. GLOBAL_DEF_RST("rendering/vram_compression/import_pvrtc", false);
  2237. GLOBAL_DEF("rendering/misc/lossless_compression/force_png", false);
  2238. GLOBAL_DEF("rendering/misc/lossless_compression/webp_compression_level", 2);
  2239. ProjectSettings::get_singleton()->set_custom_property_info("rendering/misc/lossless_compression/webp_compression_level", PropertyInfo(Variant::INT, "rendering/misc/lossless_compression/webp_compression_level", PROPERTY_HINT_RANGE, "0,9,1"));
  2240. GLOBAL_DEF("rendering/limits/time/time_rollover_secs", 3600);
  2241. ProjectSettings::get_singleton()->set_custom_property_info("rendering/limits/time/time_rollover_secs", PropertyInfo(Variant::REAL, "rendering/limits/time/time_rollover_secs", PROPERTY_HINT_RANGE, "0,10000,1,or_greater"));
  2242. GLOBAL_DEF("rendering/quality/directional_shadow/size", 4096);
  2243. GLOBAL_DEF("rendering/quality/directional_shadow/size.mobile", 2048);
  2244. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/directional_shadow/size", PropertyInfo(Variant::INT, "rendering/quality/directional_shadow/size", PROPERTY_HINT_RANGE, "256,16384,256"));
  2245. GLOBAL_DEF_RST("rendering/quality/shadow_atlas/size", 4096);
  2246. GLOBAL_DEF("rendering/quality/shadow_atlas/size.mobile", 2048);
  2247. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadow_atlas/size", PropertyInfo(Variant::INT, "rendering/quality/shadow_atlas/size", PROPERTY_HINT_RANGE, "256,16384,256"));
  2248. GLOBAL_DEF_RST("rendering/quality/shadow_atlas/cubemap_size", 512);
  2249. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadow_atlas/cubemap_size", PropertyInfo(Variant::INT, "rendering/quality/shadow_atlas/cubemap_size", PROPERTY_HINT_RANGE, "64,16384,64"));
  2250. GLOBAL_DEF("rendering/quality/shadow_atlas/quadrant_0_subdiv", 1);
  2251. GLOBAL_DEF("rendering/quality/shadow_atlas/quadrant_1_subdiv", 2);
  2252. GLOBAL_DEF("rendering/quality/shadow_atlas/quadrant_2_subdiv", 3);
  2253. GLOBAL_DEF("rendering/quality/shadow_atlas/quadrant_3_subdiv", 4);
  2254. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadow_atlas/quadrant_0_subdiv", PropertyInfo(Variant::INT, "rendering/quality/shadow_atlas/quadrant_0_subdiv", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"));
  2255. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadow_atlas/quadrant_1_subdiv", PropertyInfo(Variant::INT, "rendering/quality/shadow_atlas/quadrant_1_subdiv", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"));
  2256. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadow_atlas/quadrant_2_subdiv", PropertyInfo(Variant::INT, "rendering/quality/shadow_atlas/quadrant_2_subdiv", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"));
  2257. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadow_atlas/quadrant_3_subdiv", PropertyInfo(Variant::INT, "rendering/quality/shadow_atlas/quadrant_3_subdiv", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"));
  2258. GLOBAL_DEF("rendering/quality/shadows/filter_mode", 1);
  2259. GLOBAL_DEF("rendering/quality/shadows/filter_mode.mobile", 0);
  2260. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadows/filter_mode", PropertyInfo(Variant::INT, "rendering/quality/shadows/filter_mode", PROPERTY_HINT_ENUM, "Disabled,PCF5,PCF13"));
  2261. GLOBAL_DEF("rendering/quality/reflections/texture_array_reflections", true);
  2262. GLOBAL_DEF("rendering/quality/reflections/texture_array_reflections.mobile", false);
  2263. GLOBAL_DEF("rendering/quality/reflections/high_quality_ggx", true);
  2264. GLOBAL_DEF("rendering/quality/reflections/high_quality_ggx.mobile", false);
  2265. GLOBAL_DEF("rendering/quality/reflections/irradiance_max_size", 128);
  2266. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/reflections/irradiance_max_size", PropertyInfo(Variant::INT, "rendering/quality/reflections/irradiance_max_size", PROPERTY_HINT_RANGE, "32,2048"));
  2267. GLOBAL_DEF("rendering/quality/shading/force_vertex_shading", false);
  2268. GLOBAL_DEF("rendering/quality/shading/force_vertex_shading.mobile", true);
  2269. GLOBAL_DEF("rendering/quality/shading/force_lambert_over_burley", false);
  2270. GLOBAL_DEF("rendering/quality/shading/force_lambert_over_burley.mobile", true);
  2271. GLOBAL_DEF("rendering/quality/shading/force_blinn_over_ggx", false);
  2272. GLOBAL_DEF("rendering/quality/shading/force_blinn_over_ggx.mobile", true);
  2273. GLOBAL_DEF_RST("rendering/misc/mesh_storage/split_stream", false);
  2274. GLOBAL_DEF_RST("rendering/quality/shading/use_physical_light_attenuation", false);
  2275. GLOBAL_DEF("rendering/quality/depth_prepass/enable", true);
  2276. GLOBAL_DEF("rendering/quality/depth_prepass/disable_for_vendors", "PowerVR,Mali,Adreno,Apple");
  2277. GLOBAL_DEF("rendering/quality/filters/anisotropic_filter_level", 4);
  2278. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/filters/anisotropic_filter_level", PropertyInfo(Variant::INT, "rendering/quality/filters/anisotropic_filter_level", PROPERTY_HINT_RANGE, "1,16,1"));
  2279. GLOBAL_DEF("rendering/quality/filters/use_nearest_mipmap_filter", false);
  2280. GLOBAL_DEF("rendering/quality/skinning/software_skinning_fallback", true);
  2281. GLOBAL_DEF("rendering/quality/skinning/force_software_skinning", false);
  2282. const char *sz_balance_render_tree = "rendering/quality/spatial_partitioning/render_tree_balance";
  2283. GLOBAL_DEF(sz_balance_render_tree, 0.0f);
  2284. ProjectSettings::get_singleton()->set_custom_property_info(sz_balance_render_tree, PropertyInfo(Variant::REAL, sz_balance_render_tree, PROPERTY_HINT_RANGE, "0.0,1.0,0.01"));
  2285. GLOBAL_DEF_RST("rendering/2d/options/use_software_skinning", true);
  2286. GLOBAL_DEF_RST("rendering/2d/options/ninepatch_mode", 1);
  2287. ProjectSettings::get_singleton()->set_custom_property_info("rendering/2d/options/ninepatch_mode", PropertyInfo(Variant::INT, "rendering/2d/options/ninepatch_mode", PROPERTY_HINT_ENUM, "Fixed,Scaling"));
  2288. GLOBAL_DEF_RST("rendering/2d/opengl/batching_send_null", 0);
  2289. ProjectSettings::get_singleton()->set_custom_property_info("rendering/2d/opengl/batching_send_null", PropertyInfo(Variant::INT, "rendering/2d/opengl/batching_send_null", PROPERTY_HINT_ENUM, "Default (On),Off,On"));
  2290. GLOBAL_DEF_RST("rendering/2d/opengl/batching_stream", 0);
  2291. ProjectSettings::get_singleton()->set_custom_property_info("rendering/2d/opengl/batching_stream", PropertyInfo(Variant::INT, "rendering/2d/opengl/batching_stream", PROPERTY_HINT_ENUM, "Default (Off),Off,On"));
  2292. GLOBAL_DEF_RST("rendering/2d/opengl/legacy_orphan_buffers", 0);
  2293. ProjectSettings::get_singleton()->set_custom_property_info("rendering/2d/opengl/legacy_orphan_buffers", PropertyInfo(Variant::INT, "rendering/2d/opengl/legacy_orphan_buffers", PROPERTY_HINT_ENUM, "Default (On),Off,On"));
  2294. GLOBAL_DEF_RST("rendering/2d/opengl/legacy_stream", 0);
  2295. ProjectSettings::get_singleton()->set_custom_property_info("rendering/2d/opengl/legacy_stream", PropertyInfo(Variant::INT, "rendering/2d/opengl/legacy_stream", PROPERTY_HINT_ENUM, "Default (On),Off,On"));
  2296. GLOBAL_DEF("rendering/batching/options/use_batching", true);
  2297. GLOBAL_DEF_RST("rendering/batching/options/use_batching_in_editor", true);
  2298. GLOBAL_DEF("rendering/batching/options/single_rect_fallback", false);
  2299. GLOBAL_DEF("rendering/batching/options/use_multirect", true);
  2300. GLOBAL_DEF("rendering/batching/parameters/max_join_item_commands", 16);
  2301. GLOBAL_DEF("rendering/batching/parameters/colored_vertex_format_threshold", 0.25f);
  2302. GLOBAL_DEF("rendering/batching/lights/scissor_area_threshold", 1.0f);
  2303. GLOBAL_DEF("rendering/batching/lights/max_join_items", 32);
  2304. GLOBAL_DEF("rendering/batching/parameters/batch_buffer_size", 16384);
  2305. GLOBAL_DEF("rendering/batching/parameters/item_reordering_lookahead", 4);
  2306. GLOBAL_DEF("rendering/batching/debug/flash_batching", false);
  2307. GLOBAL_DEF("rendering/batching/debug/diagnose_frame", false);
  2308. GLOBAL_DEF("rendering/gles2/compatibility/disable_half_float", false);
  2309. GLOBAL_DEF("rendering/gles2/compatibility/disable_half_float.iOS", true);
  2310. GLOBAL_DEF("rendering/gles2/compatibility/enable_high_float.Android", false);
  2311. GLOBAL_DEF("rendering/batching/precision/uv_contract", false);
  2312. GLOBAL_DEF("rendering/batching/precision/uv_contract_amount", 100);
  2313. ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/parameters/max_join_item_commands", PropertyInfo(Variant::INT, "rendering/batching/parameters/max_join_item_commands", PROPERTY_HINT_RANGE, "0,65535"));
  2314. ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/parameters/colored_vertex_format_threshold", PropertyInfo(Variant::REAL, "rendering/batching/parameters/colored_vertex_format_threshold", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"));
  2315. ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/parameters/batch_buffer_size", PropertyInfo(Variant::INT, "rendering/batching/parameters/batch_buffer_size", PROPERTY_HINT_RANGE, "8192,65536,1024"));
  2316. ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/lights/scissor_area_threshold", PropertyInfo(Variant::REAL, "rendering/batching/lights/scissor_area_threshold", PROPERTY_HINT_RANGE, "0.0,1.0"));
  2317. ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/lights/max_join_items", PropertyInfo(Variant::INT, "rendering/batching/lights/max_join_items", PROPERTY_HINT_RANGE, "0,512"));
  2318. ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/parameters/item_reordering_lookahead", PropertyInfo(Variant::INT, "rendering/batching/parameters/item_reordering_lookahead", PROPERTY_HINT_RANGE, "0,256"));
  2319. ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/precision/uv_contract_amount", PropertyInfo(Variant::INT, "rendering/batching/precision/uv_contract_amount", PROPERTY_HINT_RANGE, "0,10000"));
  2320. // Portal rendering settings
  2321. GLOBAL_DEF("rendering/portals/pvs/use_simple_pvs", false);
  2322. GLOBAL_DEF("rendering/portals/pvs/pvs_logging", false);
  2323. GLOBAL_DEF("rendering/portals/gameplay/use_signals", true);
  2324. GLOBAL_DEF("rendering/portals/optimize/remove_danglers", true);
  2325. GLOBAL_DEF("rendering/portals/debug/logging", true);
  2326. GLOBAL_DEF("rendering/portals/advanced/flip_imported_portals", false);
  2327. // Occlusion culling
  2328. GLOBAL_DEF("rendering/misc/occlusion_culling/max_active_spheres", 8);
  2329. ProjectSettings::get_singleton()->set_custom_property_info("rendering/misc/occlusion_culling/max_active_spheres", PropertyInfo(Variant::INT, "rendering/misc/occlusion_culling/max_active_spheres", PROPERTY_HINT_RANGE, "0,64"));
  2330. GLOBAL_DEF("rendering/misc/occlusion_culling/max_active_polygons", 8);
  2331. ProjectSettings::get_singleton()->set_custom_property_info("rendering/misc/occlusion_culling/max_active_polygons", PropertyInfo(Variant::INT, "rendering/misc/occlusion_culling/max_active_polygons", PROPERTY_HINT_RANGE, "0,64"));
  2332. // Async. compilation and caching
  2333. #ifdef DEBUG_ENABLED
  2334. if (!Engine::get_singleton()->is_editor_hint()) {
  2335. force_shader_fallbacks = GLOBAL_GET("rendering/gles3/shaders/debug_shader_fallbacks");
  2336. }
  2337. #endif
  2338. GLOBAL_DEF("rendering/gles3/shaders/shader_compilation_mode", 0);
  2339. ProjectSettings::get_singleton()->set_custom_property_info("rendering/gles3/shaders/shader_compilation_mode", PropertyInfo(Variant::INT, "rendering/gles3/shaders/shader_compilation_mode", PROPERTY_HINT_ENUM, "Synchronous,Asynchronous,Asynchronous + Cache"));
  2340. GLOBAL_DEF("rendering/gles3/shaders/shader_compilation_mode.mobile", 0);
  2341. GLOBAL_DEF("rendering/gles3/shaders/shader_compilation_mode.web", 0);
  2342. GLOBAL_DEF("rendering/gles3/shaders/max_simultaneous_compiles", 2);
  2343. ProjectSettings::get_singleton()->set_custom_property_info("rendering/gles3/shaders/max_simultaneous_compiles", PropertyInfo(Variant::INT, "rendering/gles3/shaders/max_simultaneous_compiles", PROPERTY_HINT_RANGE, "1,8,1"));
  2344. GLOBAL_DEF("rendering/gles3/shaders/max_simultaneous_compiles.mobile", 1);
  2345. GLOBAL_DEF("rendering/gles3/shaders/max_simultaneous_compiles.web", 1);
  2346. GLOBAL_DEF("rendering/gles3/shaders/log_active_async_compiles_count", false);
  2347. GLOBAL_DEF("rendering/gles3/shaders/shader_cache_size_mb", 512);
  2348. ProjectSettings::get_singleton()->set_custom_property_info("rendering/gles3/shaders/shader_cache_size_mb", PropertyInfo(Variant::INT, "rendering/gles3/shaders/shader_cache_size_mb", PROPERTY_HINT_RANGE, "128,4096,128"));
  2349. GLOBAL_DEF("rendering/gles3/shaders/shader_cache_size_mb.mobile", 128);
  2350. GLOBAL_DEF("rendering/gles3/shaders/shader_cache_size_mb.web", 128);
  2351. }
  2352. VisualServer::~VisualServer() {
  2353. singleton = nullptr;
  2354. }