visual_server.cpp 124 KB

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