visual_server.cpp 127 KB

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