rendering_server.cpp 176 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637
  1. /**************************************************************************/
  2. /* rendering_server.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "rendering_server.h"
  31. #include "rendering_server.compat.inc"
  32. #include "core/config/project_settings.h"
  33. #include "core/object/worker_thread_pool.h"
  34. #include "core/variant/typed_array.h"
  35. #include "servers/rendering/rendering_server_globals.h"
  36. #include "servers/rendering/shader_language.h"
  37. #include "servers/rendering/shader_warnings.h"
  38. RenderingServer *RenderingServer::singleton = nullptr;
  39. RenderingServer *(*RenderingServer::create_func)() = nullptr;
  40. RenderingServer *RenderingServer::get_singleton() {
  41. return singleton;
  42. }
  43. RenderingServer *RenderingServer::create() {
  44. ERR_FAIL_COND_V(singleton, nullptr);
  45. if (create_func) {
  46. return create_func();
  47. }
  48. return nullptr;
  49. }
  50. Array RenderingServer::_texture_debug_usage_bind() {
  51. List<TextureInfo> list;
  52. texture_debug_usage(&list);
  53. Array arr;
  54. for (const TextureInfo &E : list) {
  55. Dictionary dict;
  56. dict["texture"] = E.texture;
  57. dict["width"] = E.width;
  58. dict["height"] = E.height;
  59. dict["depth"] = E.depth;
  60. dict["format"] = E.format;
  61. dict["bytes"] = E.bytes;
  62. dict["path"] = E.path;
  63. arr.push_back(dict);
  64. }
  65. return arr;
  66. }
  67. static PackedInt64Array to_int_array(const Vector<ObjectID> &ids) {
  68. PackedInt64Array a;
  69. a.resize(ids.size());
  70. for (int i = 0; i < ids.size(); ++i) {
  71. a.write[i] = ids[i];
  72. }
  73. return a;
  74. }
  75. PackedInt64Array RenderingServer::_instances_cull_aabb_bind(const AABB &p_aabb, RID p_scenario) const {
  76. if (RSG::threaded) {
  77. WARN_PRINT_ONCE("Using this function with a threaded renderer hurts performance, as it causes a server stall.");
  78. }
  79. Vector<ObjectID> ids = instances_cull_aabb(p_aabb, p_scenario);
  80. return to_int_array(ids);
  81. }
  82. PackedInt64Array RenderingServer::_instances_cull_ray_bind(const Vector3 &p_from, const Vector3 &p_to, RID p_scenario) const {
  83. if (RSG::threaded) {
  84. WARN_PRINT_ONCE("Using this function with a threaded renderer hurts performance, as it causes a server stall.");
  85. }
  86. Vector<ObjectID> ids = instances_cull_ray(p_from, p_to, p_scenario);
  87. return to_int_array(ids);
  88. }
  89. PackedInt64Array RenderingServer::_instances_cull_convex_bind(const TypedArray<Plane> &p_convex, RID p_scenario) const {
  90. if (RSG::threaded) {
  91. WARN_PRINT_ONCE("Using this function with a threaded renderer hurts performance, as it causes a server stall.");
  92. }
  93. Vector<Plane> planes;
  94. for (int i = 0; i < p_convex.size(); ++i) {
  95. const Variant &v = p_convex[i];
  96. ERR_FAIL_COND_V(v.get_type() != Variant::PLANE, PackedInt64Array());
  97. planes.push_back(v);
  98. }
  99. Vector<ObjectID> ids = instances_cull_convex(planes, p_scenario);
  100. return to_int_array(ids);
  101. }
  102. RID RenderingServer::get_test_texture() {
  103. if (test_texture.is_valid()) {
  104. return test_texture;
  105. };
  106. #define TEST_TEXTURE_SIZE 256
  107. Vector<uint8_t> test_data;
  108. test_data.resize(TEST_TEXTURE_SIZE * TEST_TEXTURE_SIZE * 3);
  109. {
  110. uint8_t *w = test_data.ptrw();
  111. for (int x = 0; x < TEST_TEXTURE_SIZE; x++) {
  112. for (int y = 0; y < TEST_TEXTURE_SIZE; y++) {
  113. Color c;
  114. int r = 255 - (x + y) / 2;
  115. if ((x % (TEST_TEXTURE_SIZE / 8)) < 2 || (y % (TEST_TEXTURE_SIZE / 8)) < 2) {
  116. c.r = y;
  117. c.g = r;
  118. c.b = x;
  119. } else {
  120. c.r = r;
  121. c.g = x;
  122. c.b = y;
  123. }
  124. w[(y * TEST_TEXTURE_SIZE + x) * 3 + 0] = uint8_t(CLAMP(c.r, 0, 255));
  125. w[(y * TEST_TEXTURE_SIZE + x) * 3 + 1] = uint8_t(CLAMP(c.g, 0, 255));
  126. w[(y * TEST_TEXTURE_SIZE + x) * 3 + 2] = uint8_t(CLAMP(c.b, 0, 255));
  127. }
  128. }
  129. }
  130. Ref<Image> data = memnew(Image(TEST_TEXTURE_SIZE, TEST_TEXTURE_SIZE, false, Image::FORMAT_RGB8, test_data));
  131. test_texture = texture_2d_create(data);
  132. return test_texture;
  133. }
  134. void RenderingServer::_free_internal_rids() {
  135. if (test_texture.is_valid()) {
  136. free(test_texture);
  137. }
  138. if (white_texture.is_valid()) {
  139. free(white_texture);
  140. }
  141. if (test_material.is_valid()) {
  142. free(test_material);
  143. }
  144. }
  145. RID RenderingServer::_make_test_cube() {
  146. Vector<Vector3> vertices;
  147. Vector<Vector3> normals;
  148. Vector<float> tangents;
  149. Vector<Vector3> uvs;
  150. #define ADD_VTX(m_idx) \
  151. vertices.push_back(face_points[m_idx]); \
  152. normals.push_back(normal_points[m_idx]); \
  153. tangents.push_back(normal_points[m_idx][1]); \
  154. tangents.push_back(normal_points[m_idx][2]); \
  155. tangents.push_back(normal_points[m_idx][0]); \
  156. tangents.push_back(1.0); \
  157. uvs.push_back(Vector3(uv_points[m_idx * 2 + 0], uv_points[m_idx * 2 + 1], 0));
  158. for (int i = 0; i < 6; i++) {
  159. Vector3 face_points[4];
  160. Vector3 normal_points[4];
  161. float uv_points[8] = { 0, 0, 0, 1, 1, 1, 1, 0 };
  162. for (int j = 0; j < 4; j++) {
  163. float v[3];
  164. v[0] = 1.0;
  165. v[1] = 1 - 2 * ((j >> 1) & 1);
  166. v[2] = v[1] * (1 - 2 * (j & 1));
  167. for (int k = 0; k < 3; k++) {
  168. if (i < 3) {
  169. face_points[j][(i + k) % 3] = v[k];
  170. } else {
  171. face_points[3 - j][(i + k) % 3] = -v[k];
  172. }
  173. }
  174. normal_points[j] = Vector3();
  175. normal_points[j][i % 3] = (i >= 3 ? -1 : 1);
  176. }
  177. // Tri 1
  178. ADD_VTX(0);
  179. ADD_VTX(1);
  180. ADD_VTX(2);
  181. // Tri 2
  182. ADD_VTX(2);
  183. ADD_VTX(3);
  184. ADD_VTX(0);
  185. }
  186. RID test_cube = mesh_create();
  187. Array d;
  188. d.resize(RS::ARRAY_MAX);
  189. d[RenderingServer::ARRAY_NORMAL] = normals;
  190. d[RenderingServer::ARRAY_TANGENT] = tangents;
  191. d[RenderingServer::ARRAY_TEX_UV] = uvs;
  192. d[RenderingServer::ARRAY_VERTEX] = vertices;
  193. Vector<int> indices;
  194. indices.resize(vertices.size());
  195. for (int i = 0; i < vertices.size(); i++) {
  196. indices.set(i, i);
  197. }
  198. d[RenderingServer::ARRAY_INDEX] = indices;
  199. mesh_add_surface_from_arrays(test_cube, PRIMITIVE_TRIANGLES, d);
  200. /*
  201. test_material = fixed_material_create();
  202. //material_set_flag(material, MATERIAL_FLAG_BILLBOARD_TOGGLE,true);
  203. fixed_material_set_texture( test_material, FIXED_MATERIAL_PARAM_DIFFUSE, get_test_texture() );
  204. fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_SPECULAR_EXP, 70 );
  205. fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_EMISSION, Color(0.2,0.2,0.2) );
  206. fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_DIFFUSE, Color(1, 1, 1) );
  207. fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_SPECULAR, Color(1,1,1) );
  208. */
  209. mesh_surface_set_material(test_cube, 0, test_material);
  210. return test_cube;
  211. }
  212. RID RenderingServer::make_sphere_mesh(int p_lats, int p_lons, real_t p_radius) {
  213. Vector<Vector3> vertices;
  214. Vector<Vector3> normals;
  215. const double lat_step = Math_TAU / p_lats;
  216. const double lon_step = Math_TAU / p_lons;
  217. for (int i = 1; i <= p_lats; i++) {
  218. double lat0 = lat_step * (i - 1) - Math_TAU / 4;
  219. double z0 = Math::sin(lat0);
  220. double zr0 = Math::cos(lat0);
  221. double lat1 = lat_step * i - Math_TAU / 4;
  222. double z1 = Math::sin(lat1);
  223. double zr1 = Math::cos(lat1);
  224. for (int j = p_lons; j >= 1; j--) {
  225. double lng0 = lon_step * (j - 1);
  226. double x0 = Math::cos(lng0);
  227. double y0 = Math::sin(lng0);
  228. double lng1 = lon_step * j;
  229. double x1 = Math::cos(lng1);
  230. double y1 = Math::sin(lng1);
  231. Vector3 v[4] = {
  232. Vector3(x1 * zr0, z0, y1 * zr0),
  233. Vector3(x1 * zr1, z1, y1 * zr1),
  234. Vector3(x0 * zr1, z1, y0 * zr1),
  235. Vector3(x0 * zr0, z0, y0 * zr0)
  236. };
  237. #define ADD_POINT(m_idx) \
  238. normals.push_back(v[m_idx]); \
  239. vertices.push_back(v[m_idx] * p_radius);
  240. ADD_POINT(0);
  241. ADD_POINT(1);
  242. ADD_POINT(2);
  243. ADD_POINT(2);
  244. ADD_POINT(3);
  245. ADD_POINT(0);
  246. }
  247. }
  248. RID mesh = mesh_create();
  249. Array d;
  250. d.resize(RS::ARRAY_MAX);
  251. d[ARRAY_VERTEX] = vertices;
  252. d[ARRAY_NORMAL] = normals;
  253. mesh_add_surface_from_arrays(mesh, PRIMITIVE_TRIANGLES, d);
  254. return mesh;
  255. }
  256. RID RenderingServer::get_white_texture() {
  257. if (white_texture.is_valid()) {
  258. return white_texture;
  259. }
  260. Vector<uint8_t> wt;
  261. wt.resize(16 * 3);
  262. {
  263. uint8_t *w = wt.ptrw();
  264. for (int i = 0; i < 16 * 3; i++) {
  265. w[i] = 255;
  266. }
  267. }
  268. Ref<Image> white = memnew(Image(4, 4, 0, Image::FORMAT_RGB8, wt));
  269. white_texture = texture_2d_create(white);
  270. return white_texture;
  271. }
  272. void _get_axis_angle(const Vector3 &p_normal, const Vector4 &p_tangent, float &r_angle, Vector3 &r_axis) {
  273. Vector3 normal = p_normal.normalized();
  274. Vector3 tangent = Vector3(p_tangent.x, p_tangent.y, p_tangent.z).normalized();
  275. float d = p_tangent.w;
  276. Vector3 binormal = normal.cross(tangent).normalized();
  277. real_t angle;
  278. Basis tbn = Basis();
  279. tbn.rows[0] = tangent;
  280. tbn.rows[1] = binormal;
  281. tbn.rows[2] = normal;
  282. tbn.get_axis_angle(r_axis, angle);
  283. r_angle = float(angle);
  284. if (d < 0.0) {
  285. r_angle = CLAMP((1.0 - r_angle / Math_PI) * 0.5, 0.0, 0.49999);
  286. } else {
  287. r_angle = CLAMP((r_angle / Math_PI) * 0.5 + 0.5, 0.500008, 1.0);
  288. }
  289. }
  290. // The inputs to this function should match the outputs of _get_axis_angle. I.e. p_axis is a normalized vector
  291. // and p_angle includes the binormal direction.
  292. void _get_tbn_from_axis_angle(const Vector3 &p_axis, float p_angle, Vector3 &r_normal, Vector4 &r_tangent) {
  293. float binormal_sign = p_angle > 0.5 ? 1.0 : -1.0;
  294. float angle = Math::abs(p_angle * 2.0 - 1.0) * Math_PI;
  295. Basis tbn = Basis(p_axis, angle);
  296. Vector3 tan = tbn.rows[0];
  297. r_tangent = Vector4(tan.x, tan.y, tan.z, binormal_sign);
  298. r_normal = tbn.rows[2];
  299. }
  300. Error RenderingServer::_surface_set_data(Array p_arrays, uint64_t p_format, uint32_t *p_offsets, uint32_t p_vertex_stride, uint32_t p_normal_stride, uint32_t p_attrib_stride, uint32_t p_skin_stride, Vector<uint8_t> &r_vertex_array, Vector<uint8_t> &r_attrib_array, Vector<uint8_t> &r_skin_array, int p_vertex_array_len, Vector<uint8_t> &r_index_array, int p_index_array_len, AABB &r_aabb, Vector<AABB> &r_bone_aabb, Vector4 &r_uv_scale) {
  301. uint8_t *vw = r_vertex_array.ptrw();
  302. uint8_t *aw = r_attrib_array.ptrw();
  303. uint8_t *sw = r_skin_array.ptrw();
  304. uint8_t *iw = nullptr;
  305. if (r_index_array.size()) {
  306. iw = r_index_array.ptrw();
  307. }
  308. int max_bone = 0;
  309. // Preprocess UVs if compression is enabled
  310. if (p_format & RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES && ((p_format & RS::ARRAY_FORMAT_TEX_UV) || (p_format & RS::ARRAY_FORMAT_TEX_UV2))) {
  311. const Vector2 *uv_src = nullptr;
  312. if (p_format & RS::ARRAY_FORMAT_TEX_UV) {
  313. Vector<Vector2> array = p_arrays[RS::ARRAY_TEX_UV];
  314. uv_src = array.ptr();
  315. }
  316. const Vector2 *uv2_src = nullptr;
  317. if (p_format & RS::ARRAY_FORMAT_TEX_UV2) {
  318. Vector<Vector2> array = p_arrays[RS::ARRAY_TEX_UV2];
  319. uv2_src = array.ptr();
  320. }
  321. Vector2 max_val = Vector2(0.0, 0.0);
  322. Vector2 min_val = Vector2(0.0, 0.0);
  323. Vector2 max_val2 = Vector2(0.0, 0.0);
  324. Vector2 min_val2 = Vector2(0.0, 0.0);
  325. for (int i = 0; i < p_vertex_array_len; i++) {
  326. if (p_format & RS::ARRAY_FORMAT_TEX_UV) {
  327. max_val = max_val.max(uv_src[i]);
  328. min_val = min_val.min(uv_src[i]);
  329. }
  330. if (p_format & RS::ARRAY_FORMAT_TEX_UV2) {
  331. max_val2 = max_val2.max(uv2_src[i]);
  332. min_val2 = min_val2.min(uv2_src[i]);
  333. }
  334. }
  335. max_val = max_val.abs().max(min_val.abs());
  336. max_val2 = max_val2.abs().max(min_val2.abs());
  337. if (min_val.x >= 0.0 && min_val2.x >= 0.0 && max_val.x <= 1.0 && max_val2.x <= 1.0 &&
  338. min_val.y >= 0.0 && min_val2.y >= 0.0 && max_val.y <= 1.0 && max_val2.y <= 1.0) {
  339. // When all channels are in the 0-1 range, we will compress to 16-bit without scaling to
  340. // preserve the bits as best as possible.
  341. r_uv_scale = Vector4(0.0, 0.0, 0.0, 0.0);
  342. } else {
  343. r_uv_scale = Vector4(max_val.x, max_val.y, max_val2.x, max_val2.y) * Vector4(2.0, 2.0, 2.0, 2.0);
  344. }
  345. }
  346. for (int ai = 0; ai < RS::ARRAY_MAX; ai++) {
  347. if (!(p_format & (1ULL << ai))) { // No array
  348. continue;
  349. }
  350. switch (ai) {
  351. case RS::ARRAY_VERTEX: {
  352. if (p_format & RS::ARRAY_FLAG_USE_2D_VERTICES) {
  353. Vector<Vector2> array = p_arrays[ai];
  354. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  355. const Vector2 *src = array.ptr();
  356. // Setting vertices means regenerating the AABB.
  357. Rect2 aabb;
  358. {
  359. for (int i = 0; i < p_vertex_array_len; i++) {
  360. float vector[2] = { (float)src[i].x, (float)src[i].y };
  361. memcpy(&vw[p_offsets[ai] + i * p_vertex_stride], vector, sizeof(float) * 2);
  362. if (i == 0) {
  363. aabb = Rect2(src[i], SMALL_VEC2); // Must have a bit of size.
  364. } else {
  365. aabb.expand_to(src[i]);
  366. }
  367. }
  368. }
  369. r_aabb = AABB(Vector3(aabb.position.x, aabb.position.y, 0), Vector3(aabb.size.x, aabb.size.y, 0));
  370. } else {
  371. Vector<Vector3> array = p_arrays[ai];
  372. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  373. const Vector3 *src = array.ptr();
  374. r_aabb = AABB();
  375. if (p_format & ARRAY_FLAG_COMPRESS_ATTRIBUTES) {
  376. // First we need to generate the AABB for the entire surface.
  377. for (int i = 0; i < p_vertex_array_len; i++) {
  378. if (i == 0) {
  379. r_aabb = AABB(src[i], SMALL_VEC3);
  380. } else {
  381. r_aabb.expand_to(src[i]);
  382. }
  383. }
  384. if (!(p_format & RS::ARRAY_FORMAT_NORMAL)) {
  385. // Early out if we are only setting vertex positions.
  386. for (int i = 0; i < p_vertex_array_len; i++) {
  387. Vector3 pos = (src[i] - r_aabb.position) / r_aabb.size;
  388. uint16_t vector[4] = {
  389. (uint16_t)CLAMP(pos.x * 65535, 0, 65535),
  390. (uint16_t)CLAMP(pos.y * 65535, 0, 65535),
  391. (uint16_t)CLAMP(pos.z * 65535, 0, 65535),
  392. (uint16_t)0
  393. };
  394. memcpy(&vw[p_offsets[ai] + i * p_vertex_stride], vector, sizeof(uint16_t) * 4);
  395. }
  396. continue;
  397. }
  398. // Validate normal and tangent arrays.
  399. ERR_FAIL_COND_V(p_arrays[RS::ARRAY_NORMAL].get_type() != Variant::PACKED_VECTOR3_ARRAY, ERR_INVALID_PARAMETER);
  400. Vector<Vector3> normal_array = p_arrays[RS::ARRAY_NORMAL];
  401. ERR_FAIL_COND_V(normal_array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  402. const Vector3 *normal_src = normal_array.ptr();
  403. Variant::Type tangent_type = p_arrays[RS::ARRAY_TANGENT].get_type();
  404. ERR_FAIL_COND_V(tangent_type != Variant::PACKED_FLOAT32_ARRAY && tangent_type != Variant::PACKED_FLOAT64_ARRAY && tangent_type != Variant::NIL, ERR_INVALID_PARAMETER);
  405. // We need a different version if using double precision tangents.
  406. if (tangent_type == Variant::PACKED_FLOAT32_ARRAY) {
  407. Vector<float> tangent_array = p_arrays[RS::ARRAY_TANGENT];
  408. ERR_FAIL_COND_V(tangent_array.size() != p_vertex_array_len * 4, ERR_INVALID_PARAMETER);
  409. const float *tangent_src = tangent_array.ptr();
  410. // Set data for vertex, normal, and tangent.
  411. for (int i = 0; i < p_vertex_array_len; i++) {
  412. float angle = 0.0;
  413. Vector3 axis;
  414. Vector4 tangent = Vector4(tangent_src[i * 4 + 0], tangent_src[i * 4 + 1], tangent_src[i * 4 + 2], tangent_src[i * 4 + 3]);
  415. _get_axis_angle(normal_src[i], tangent, angle, axis);
  416. // Store axis.
  417. {
  418. Vector2 res = axis.octahedron_encode();
  419. uint16_t vector[2] = {
  420. (uint16_t)CLAMP(res.x * 65535, 0, 65535),
  421. (uint16_t)CLAMP(res.y * 65535, 0, 65535),
  422. };
  423. memcpy(&vw[p_offsets[RS::ARRAY_NORMAL] + i * p_normal_stride], vector, 4);
  424. }
  425. // Store vertex position + angle.
  426. {
  427. Vector3 pos = (src[i] - r_aabb.position) / r_aabb.size;
  428. uint16_t vector[4] = {
  429. (uint16_t)CLAMP(pos.x * 65535, 0, 65535),
  430. (uint16_t)CLAMP(pos.y * 65535, 0, 65535),
  431. (uint16_t)CLAMP(pos.z * 65535, 0, 65535),
  432. (uint16_t)CLAMP(angle * 65535, 0, 65535)
  433. };
  434. memcpy(&vw[p_offsets[ai] + i * p_vertex_stride], vector, sizeof(uint16_t) * 4);
  435. }
  436. }
  437. } else if (tangent_type == Variant::PACKED_FLOAT64_ARRAY) {
  438. Vector<double> tangent_array = p_arrays[RS::ARRAY_TANGENT];
  439. ERR_FAIL_COND_V(tangent_array.size() != p_vertex_array_len * 4, ERR_INVALID_PARAMETER);
  440. const double *tangent_src = tangent_array.ptr();
  441. // Set data for vertex, normal, and tangent.
  442. for (int i = 0; i < p_vertex_array_len; i++) {
  443. float angle;
  444. Vector3 axis;
  445. Vector4 tangent = Vector4(tangent_src[i * 4 + 0], tangent_src[i * 4 + 1], tangent_src[i * 4 + 2], tangent_src[i * 4 + 3]);
  446. _get_axis_angle(normal_src[i], tangent, angle, axis);
  447. // Store axis.
  448. {
  449. Vector2 res = axis.octahedron_encode();
  450. uint16_t vector[2] = {
  451. (uint16_t)CLAMP(res.x * 65535, 0, 65535),
  452. (uint16_t)CLAMP(res.y * 65535, 0, 65535),
  453. };
  454. memcpy(&vw[p_offsets[RS::ARRAY_NORMAL] + i * p_normal_stride], vector, 4);
  455. }
  456. // Store vertex position + angle.
  457. {
  458. Vector3 pos = (src[i] - r_aabb.position) / r_aabb.size;
  459. uint16_t vector[4] = {
  460. (uint16_t)CLAMP(pos.x * 65535, 0, 65535),
  461. (uint16_t)CLAMP(pos.y * 65535, 0, 65535),
  462. (uint16_t)CLAMP(pos.z * 65535, 0, 65535),
  463. (uint16_t)CLAMP(angle * 65535, 0, 65535)
  464. };
  465. memcpy(&vw[p_offsets[ai] + i * p_vertex_stride], vector, sizeof(uint16_t) * 4);
  466. }
  467. }
  468. } else { // No tangent array.
  469. // Set data for vertex, normal, and tangent.
  470. for (int i = 0; i < p_vertex_array_len; i++) {
  471. float angle;
  472. Vector3 axis;
  473. // Generate an arbitrary vector that is tangential to normal.
  474. // This assumes that the normal is never (0,0,0).
  475. Vector3 tan = Vector3(normal_src[i].z, -normal_src[i].x, normal_src[i].y).cross(normal_src[i].normalized()).normalized();
  476. Vector4 tangent = Vector4(tan.x, tan.y, tan.z, 1.0);
  477. _get_axis_angle(normal_src[i], tangent, angle, axis);
  478. // Store axis.
  479. {
  480. Vector2 res = axis.octahedron_encode();
  481. uint16_t vector[2] = {
  482. (uint16_t)CLAMP(res.x * 65535, 0, 65535),
  483. (uint16_t)CLAMP(res.y * 65535, 0, 65535),
  484. };
  485. memcpy(&vw[p_offsets[RS::ARRAY_NORMAL] + i * p_normal_stride], vector, 4);
  486. }
  487. // Store vertex position + angle.
  488. {
  489. Vector3 pos = (src[i] - r_aabb.position) / r_aabb.size;
  490. uint16_t vector[4] = {
  491. (uint16_t)CLAMP(pos.x * 65535, 0, 65535),
  492. (uint16_t)CLAMP(pos.y * 65535, 0, 65535),
  493. (uint16_t)CLAMP(pos.z * 65535, 0, 65535),
  494. (uint16_t)CLAMP(angle * 65535, 0, 65535)
  495. };
  496. memcpy(&vw[p_offsets[ai] + i * p_vertex_stride], vector, sizeof(uint16_t) * 4);
  497. }
  498. }
  499. }
  500. } else {
  501. for (int i = 0; i < p_vertex_array_len; i++) {
  502. float vector[3] = { (float)src[i].x, (float)src[i].y, (float)src[i].z };
  503. memcpy(&vw[p_offsets[ai] + i * p_vertex_stride], vector, sizeof(float) * 3);
  504. if (i == 0) {
  505. r_aabb = AABB(src[i], SMALL_VEC3);
  506. } else {
  507. r_aabb.expand_to(src[i]);
  508. }
  509. }
  510. }
  511. }
  512. } break;
  513. case RS::ARRAY_NORMAL: {
  514. // If using compression we store normal while storing vertices.
  515. if (!(p_format & RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES)) {
  516. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::PACKED_VECTOR3_ARRAY, ERR_INVALID_PARAMETER);
  517. Vector<Vector3> array = p_arrays[ai];
  518. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  519. const Vector3 *src = array.ptr();
  520. for (int i = 0; i < p_vertex_array_len; i++) {
  521. Vector2 res = src[i].octahedron_encode();
  522. uint16_t vector[2] = {
  523. (uint16_t)CLAMP(res.x * 65535, 0, 65535),
  524. (uint16_t)CLAMP(res.y * 65535, 0, 65535),
  525. };
  526. memcpy(&vw[p_offsets[ai] + i * p_normal_stride], vector, 4);
  527. }
  528. }
  529. } break;
  530. case RS::ARRAY_TANGENT: {
  531. // If using compression we store tangent while storing vertices.
  532. if (!(p_format & RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES)) {
  533. Variant::Type type = p_arrays[ai].get_type();
  534. ERR_FAIL_COND_V(type != Variant::PACKED_FLOAT32_ARRAY && type != Variant::PACKED_FLOAT64_ARRAY && type != Variant::NIL, ERR_INVALID_PARAMETER);
  535. if (type == Variant::PACKED_FLOAT32_ARRAY) {
  536. Vector<float> array = p_arrays[ai];
  537. ERR_FAIL_COND_V(array.size() != p_vertex_array_len * 4, ERR_INVALID_PARAMETER);
  538. const float *src_ptr = array.ptr();
  539. for (int i = 0; i < p_vertex_array_len; i++) {
  540. const Vector3 src(src_ptr[i * 4 + 0], src_ptr[i * 4 + 1], src_ptr[i * 4 + 2]);
  541. Vector2 res = src.octahedron_tangent_encode(src_ptr[i * 4 + 3]);
  542. uint16_t vector[2] = {
  543. (uint16_t)CLAMP(res.x * 65535, 0, 65535),
  544. (uint16_t)CLAMP(res.y * 65535, 0, 65535),
  545. };
  546. if (vector[0] == 0 && vector[1] == 65535) {
  547. // (1, 1) and (0, 1) decode to the same value, but (0, 1) messes with our compression detection.
  548. // So we sanitize here.
  549. vector[0] = 65535;
  550. }
  551. memcpy(&vw[p_offsets[ai] + i * p_normal_stride], vector, 4);
  552. }
  553. } else if (type == Variant::PACKED_FLOAT64_ARRAY) {
  554. Vector<double> array = p_arrays[ai];
  555. ERR_FAIL_COND_V(array.size() != p_vertex_array_len * 4, ERR_INVALID_PARAMETER);
  556. const double *src_ptr = array.ptr();
  557. for (int i = 0; i < p_vertex_array_len; i++) {
  558. const Vector3 src(src_ptr[i * 4 + 0], src_ptr[i * 4 + 1], src_ptr[i * 4 + 2]);
  559. Vector2 res = src.octahedron_tangent_encode(src_ptr[i * 4 + 3]);
  560. uint16_t vector[2] = {
  561. (uint16_t)CLAMP(res.x * 65535, 0, 65535),
  562. (uint16_t)CLAMP(res.y * 65535, 0, 65535),
  563. };
  564. if (vector[0] == 0 && vector[1] == 65535) {
  565. // (1, 1) and (0, 1) decode to the same value, but (0, 1) messes with our compression detection.
  566. // So we sanitize here.
  567. vector[0] = 65535;
  568. }
  569. memcpy(&vw[p_offsets[ai] + i * p_normal_stride], vector, 4);
  570. }
  571. } else { // No tangent array.
  572. ERR_FAIL_COND_V(p_arrays[RS::ARRAY_NORMAL].get_type() != Variant::PACKED_VECTOR3_ARRAY, ERR_INVALID_PARAMETER);
  573. Vector<Vector3> normal_array = p_arrays[RS::ARRAY_NORMAL];
  574. ERR_FAIL_COND_V(normal_array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  575. const Vector3 *normal_src = normal_array.ptr();
  576. // Set data for tangent.
  577. for (int i = 0; i < p_vertex_array_len; i++) {
  578. // Generate an arbitrary vector that is tangential to normal.
  579. // This assumes that the normal is never (0,0,0).
  580. Vector3 tan = Vector3(normal_src[i].z, -normal_src[i].x, normal_src[i].y).cross(normal_src[i].normalized()).normalized();
  581. Vector2 res = tan.octahedron_tangent_encode(1.0);
  582. uint16_t vector[2] = {
  583. (uint16_t)CLAMP(res.x * 65535, 0, 65535),
  584. (uint16_t)CLAMP(res.y * 65535, 0, 65535),
  585. };
  586. if (vector[0] == 0 && vector[1] == 65535) {
  587. // (1, 1) and (0, 1) decode to the same value, but (0, 1) messes with our compression detection.
  588. // So we sanitize here.
  589. vector[0] = 65535;
  590. }
  591. memcpy(&vw[p_offsets[ai] + i * p_normal_stride], vector, 4);
  592. }
  593. }
  594. }
  595. } break;
  596. case RS::ARRAY_COLOR: {
  597. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::PACKED_COLOR_ARRAY, ERR_INVALID_PARAMETER);
  598. Vector<Color> array = p_arrays[ai];
  599. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  600. const Color *src = array.ptr();
  601. for (int i = 0; i < p_vertex_array_len; i++) {
  602. uint8_t color8[4] = {
  603. uint8_t(CLAMP(src[i].r * 255.0, 0.0, 255.0)),
  604. uint8_t(CLAMP(src[i].g * 255.0, 0.0, 255.0)),
  605. uint8_t(CLAMP(src[i].b * 255.0, 0.0, 255.0)),
  606. uint8_t(CLAMP(src[i].a * 255.0, 0.0, 255.0))
  607. };
  608. memcpy(&aw[p_offsets[ai] + i * p_attrib_stride], color8, 4);
  609. }
  610. } break;
  611. case RS::ARRAY_TEX_UV: {
  612. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::PACKED_VECTOR3_ARRAY && p_arrays[ai].get_type() != Variant::PACKED_VECTOR2_ARRAY, ERR_INVALID_PARAMETER);
  613. Vector<Vector2> array = p_arrays[ai];
  614. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  615. const Vector2 *src = array.ptr();
  616. if (p_format & RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES) {
  617. for (int i = 0; i < p_vertex_array_len; i++) {
  618. Vector2 vec = src[i];
  619. if (!r_uv_scale.is_zero_approx()) {
  620. // Normalize into 0-1 from possible range -uv_scale - uv_scale.
  621. vec = vec / (Vector2(r_uv_scale.x, r_uv_scale.y)) + Vector2(0.5, 0.5);
  622. }
  623. uint16_t uv[2] = { (uint16_t)CLAMP(vec.x * 65535, 0, 65535), (uint16_t)CLAMP(vec.y * 65535, 0, 65535) };
  624. memcpy(&aw[p_offsets[ai] + i * p_attrib_stride], uv, 4);
  625. }
  626. } else {
  627. for (int i = 0; i < p_vertex_array_len; i++) {
  628. float uv[2] = { (float)src[i].x, (float)src[i].y };
  629. memcpy(&aw[p_offsets[ai] + i * p_attrib_stride], uv, 2 * 4);
  630. }
  631. }
  632. } break;
  633. case RS::ARRAY_TEX_UV2: {
  634. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::PACKED_VECTOR3_ARRAY && p_arrays[ai].get_type() != Variant::PACKED_VECTOR2_ARRAY, ERR_INVALID_PARAMETER);
  635. Vector<Vector2> array = p_arrays[ai];
  636. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  637. const Vector2 *src = array.ptr();
  638. if (p_format & RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES) {
  639. for (int i = 0; i < p_vertex_array_len; i++) {
  640. Vector2 vec = src[i];
  641. if (!r_uv_scale.is_zero_approx()) {
  642. // Normalize into 0-1 from possible range -uv_scale - uv_scale.
  643. vec = vec / (Vector2(r_uv_scale.z, r_uv_scale.w)) + Vector2(0.5, 0.5);
  644. }
  645. uint16_t uv[2] = { (uint16_t)CLAMP(vec.x * 65535, 0, 65535), (uint16_t)CLAMP(vec.y * 65535, 0, 65535) };
  646. memcpy(&aw[p_offsets[ai] + i * p_attrib_stride], uv, 4);
  647. }
  648. } else {
  649. for (int i = 0; i < p_vertex_array_len; i++) {
  650. float uv[2] = { (float)src[i].x, (float)src[i].y };
  651. memcpy(&aw[p_offsets[ai] + i * p_attrib_stride], uv, 2 * 4);
  652. }
  653. }
  654. } break;
  655. case RS::ARRAY_CUSTOM0:
  656. case RS::ARRAY_CUSTOM1:
  657. case RS::ARRAY_CUSTOM2:
  658. case RS::ARRAY_CUSTOM3: {
  659. uint32_t type = (p_format >> (ARRAY_FORMAT_CUSTOM_BASE + ARRAY_FORMAT_CUSTOM_BITS * (ai - RS::ARRAY_CUSTOM0))) & ARRAY_FORMAT_CUSTOM_MASK;
  660. switch (type) {
  661. case ARRAY_CUSTOM_RGBA8_UNORM:
  662. case ARRAY_CUSTOM_RGBA8_SNORM:
  663. case ARRAY_CUSTOM_RG_HALF: {
  664. // Size 4
  665. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::PACKED_BYTE_ARRAY, ERR_INVALID_PARAMETER);
  666. Vector<uint8_t> array = p_arrays[ai];
  667. ERR_FAIL_COND_V(array.size() != p_vertex_array_len * 4, ERR_INVALID_PARAMETER);
  668. const uint8_t *src = array.ptr();
  669. for (int i = 0; i < p_vertex_array_len; i++) {
  670. memcpy(&aw[p_offsets[ai] + i * p_attrib_stride], &src[i * 4], 4);
  671. }
  672. } break;
  673. case ARRAY_CUSTOM_RGBA_HALF: {
  674. // Size 8
  675. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::PACKED_BYTE_ARRAY, ERR_INVALID_PARAMETER);
  676. Vector<uint8_t> array = p_arrays[ai];
  677. ERR_FAIL_COND_V(array.size() != p_vertex_array_len * 8, ERR_INVALID_PARAMETER);
  678. const uint8_t *src = array.ptr();
  679. for (int i = 0; i < p_vertex_array_len; i++) {
  680. memcpy(&aw[p_offsets[ai] + i * p_attrib_stride], &src[i * 8], 8);
  681. }
  682. } break;
  683. case ARRAY_CUSTOM_R_FLOAT:
  684. case ARRAY_CUSTOM_RG_FLOAT:
  685. case ARRAY_CUSTOM_RGB_FLOAT:
  686. case ARRAY_CUSTOM_RGBA_FLOAT: {
  687. // RF
  688. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::PACKED_FLOAT32_ARRAY, ERR_INVALID_PARAMETER);
  689. Vector<float> array = p_arrays[ai];
  690. int32_t s = type - ARRAY_CUSTOM_R_FLOAT + 1;
  691. ERR_FAIL_COND_V(array.size() != p_vertex_array_len * s, ERR_INVALID_PARAMETER);
  692. const float *src = array.ptr();
  693. for (int i = 0; i < p_vertex_array_len; i++) {
  694. memcpy(&aw[p_offsets[ai] + i * p_attrib_stride], &src[i * s], sizeof(float) * s);
  695. }
  696. } break;
  697. default: {
  698. }
  699. }
  700. } break;
  701. case RS::ARRAY_WEIGHTS: {
  702. Variant::Type type = p_arrays[ai].get_type();
  703. ERR_FAIL_COND_V(type != Variant::PACKED_FLOAT32_ARRAY && type != Variant::PACKED_FLOAT64_ARRAY, ERR_INVALID_PARAMETER);
  704. uint32_t bone_count = (p_format & ARRAY_FLAG_USE_8_BONE_WEIGHTS) ? 8 : 4;
  705. if (type == Variant::PACKED_FLOAT32_ARRAY) {
  706. Vector<float> array = p_arrays[ai];
  707. ERR_FAIL_COND_V(array.size() != (int32_t)(p_vertex_array_len * bone_count), ERR_INVALID_PARAMETER);
  708. const float *src = array.ptr();
  709. {
  710. uint16_t data[8];
  711. for (int i = 0; i < p_vertex_array_len; i++) {
  712. for (uint32_t j = 0; j < bone_count; j++) {
  713. data[j] = CLAMP(src[i * bone_count + j] * 65535, 0, 65535);
  714. }
  715. memcpy(&sw[p_offsets[ai] + i * p_skin_stride], data, 2 * bone_count);
  716. }
  717. }
  718. } else { // PACKED_FLOAT64_ARRAY
  719. Vector<double> array = p_arrays[ai];
  720. ERR_FAIL_COND_V(array.size() != (int32_t)(p_vertex_array_len * bone_count), ERR_INVALID_PARAMETER);
  721. const double *src = array.ptr();
  722. {
  723. uint16_t data[8];
  724. for (int i = 0; i < p_vertex_array_len; i++) {
  725. for (uint32_t j = 0; j < bone_count; j++) {
  726. data[j] = CLAMP(src[i * bone_count + j] * 65535, 0, 65535);
  727. }
  728. memcpy(&sw[p_offsets[ai] + i * p_skin_stride], data, 2 * bone_count);
  729. }
  730. }
  731. }
  732. } break;
  733. case RS::ARRAY_BONES: {
  734. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::PACKED_INT32_ARRAY && p_arrays[ai].get_type() != Variant::PACKED_FLOAT32_ARRAY, ERR_INVALID_PARAMETER);
  735. Vector<int> array = p_arrays[ai];
  736. uint32_t bone_count = (p_format & ARRAY_FLAG_USE_8_BONE_WEIGHTS) ? 8 : 4;
  737. ERR_FAIL_COND_V(array.size() != (int32_t)(p_vertex_array_len * bone_count), ERR_INVALID_PARAMETER);
  738. const int *src = array.ptr();
  739. uint16_t data[8];
  740. for (int i = 0; i < p_vertex_array_len; i++) {
  741. for (uint32_t j = 0; j < bone_count; j++) {
  742. data[j] = src[i * bone_count + j];
  743. max_bone = MAX(data[j], max_bone);
  744. }
  745. memcpy(&sw[p_offsets[ai] + i * p_skin_stride], data, 2 * bone_count);
  746. }
  747. } break;
  748. case RS::ARRAY_INDEX: {
  749. ERR_FAIL_NULL_V(iw, ERR_INVALID_DATA);
  750. ERR_FAIL_COND_V(p_index_array_len <= 0, ERR_INVALID_DATA);
  751. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::PACKED_INT32_ARRAY, ERR_INVALID_PARAMETER);
  752. Vector<int> indices = p_arrays[ai];
  753. ERR_FAIL_COND_V(indices.is_empty(), ERR_INVALID_PARAMETER);
  754. ERR_FAIL_COND_V(indices.size() != p_index_array_len, ERR_INVALID_PARAMETER);
  755. /* determine whether using 16 or 32 bits indices */
  756. const int *src = indices.ptr();
  757. for (int i = 0; i < p_index_array_len; i++) {
  758. if (p_vertex_array_len <= (1 << 16) && p_vertex_array_len > 0) {
  759. uint16_t v = src[i];
  760. memcpy(&iw[i * 2], &v, 2);
  761. } else {
  762. uint32_t v = src[i];
  763. memcpy(&iw[i * 4], &v, 4);
  764. }
  765. }
  766. } break;
  767. default: {
  768. ERR_FAIL_V(ERR_INVALID_DATA);
  769. }
  770. }
  771. }
  772. if (p_format & RS::ARRAY_FORMAT_BONES) {
  773. // Create AABBs for each detected bone.
  774. int total_bones = max_bone + 1;
  775. bool first = r_bone_aabb.size() == 0;
  776. r_bone_aabb.resize(total_bones);
  777. int weight_count = (p_format & ARRAY_FLAG_USE_8_BONE_WEIGHTS) ? 8 : 4;
  778. if (first) {
  779. for (int i = 0; i < total_bones; i++) {
  780. r_bone_aabb.write[i].size = Vector3(-1, -1, -1); // Negative means unused.
  781. }
  782. }
  783. Vector<Vector3> vertices = p_arrays[RS::ARRAY_VERTEX];
  784. Vector<int> bones = p_arrays[RS::ARRAY_BONES];
  785. Vector<float> weights = p_arrays[RS::ARRAY_WEIGHTS];
  786. bool any_valid = false;
  787. if (vertices.size() && bones.size() == vertices.size() * weight_count && weights.size() == bones.size()) {
  788. int vs = vertices.size();
  789. const Vector3 *rv = vertices.ptr();
  790. const int *rb = bones.ptr();
  791. const float *rw = weights.ptr();
  792. AABB *bptr = r_bone_aabb.ptrw();
  793. for (int i = 0; i < vs; i++) {
  794. Vector3 v = rv[i];
  795. for (int j = 0; j < weight_count; j++) {
  796. int idx = rb[i * weight_count + j];
  797. float w = rw[i * weight_count + j];
  798. if (w == 0) {
  799. continue; //break;
  800. }
  801. ERR_FAIL_INDEX_V(idx, total_bones, ERR_INVALID_DATA);
  802. if (bptr[idx].size.x < 0) {
  803. // First
  804. bptr[idx] = AABB(v, SMALL_VEC3);
  805. any_valid = true;
  806. } else {
  807. bptr[idx].expand_to(v);
  808. }
  809. }
  810. }
  811. }
  812. if (!any_valid && first) {
  813. r_bone_aabb.clear();
  814. }
  815. }
  816. return OK;
  817. }
  818. uint32_t RenderingServer::mesh_surface_get_format_offset(BitField<ArrayFormat> p_format, int p_vertex_len, int p_array_index) const {
  819. ERR_FAIL_INDEX_V(p_array_index, ARRAY_MAX, 0);
  820. p_format = uint64_t(p_format) & ~ARRAY_FORMAT_INDEX;
  821. uint32_t offsets[ARRAY_MAX];
  822. uint32_t vstr;
  823. uint32_t ntstr;
  824. uint32_t astr;
  825. uint32_t sstr;
  826. mesh_surface_make_offsets_from_format(p_format, p_vertex_len, 0, offsets, vstr, ntstr, astr, sstr);
  827. return offsets[p_array_index];
  828. }
  829. uint32_t RenderingServer::mesh_surface_get_format_vertex_stride(BitField<ArrayFormat> p_format, int p_vertex_len) const {
  830. p_format = uint64_t(p_format) & ~ARRAY_FORMAT_INDEX;
  831. uint32_t offsets[ARRAY_MAX];
  832. uint32_t vstr;
  833. uint32_t ntstr;
  834. uint32_t astr;
  835. uint32_t sstr;
  836. mesh_surface_make_offsets_from_format(p_format, p_vertex_len, 0, offsets, vstr, ntstr, astr, sstr);
  837. return vstr;
  838. }
  839. uint32_t RenderingServer::mesh_surface_get_format_normal_tangent_stride(BitField<ArrayFormat> p_format, int p_vertex_len) const {
  840. p_format = uint64_t(p_format) & ~ARRAY_FORMAT_INDEX;
  841. uint32_t offsets[ARRAY_MAX];
  842. uint32_t vstr;
  843. uint32_t ntstr;
  844. uint32_t astr;
  845. uint32_t sstr;
  846. mesh_surface_make_offsets_from_format(p_format, p_vertex_len, 0, offsets, vstr, ntstr, astr, sstr);
  847. return ntstr;
  848. }
  849. uint32_t RenderingServer::mesh_surface_get_format_attribute_stride(BitField<ArrayFormat> p_format, int p_vertex_len) const {
  850. p_format = uint64_t(p_format) & ~ARRAY_FORMAT_INDEX;
  851. uint32_t offsets[ARRAY_MAX];
  852. uint32_t vstr;
  853. uint32_t ntstr;
  854. uint32_t astr;
  855. uint32_t sstr;
  856. mesh_surface_make_offsets_from_format(p_format, p_vertex_len, 0, offsets, vstr, ntstr, astr, sstr);
  857. return astr;
  858. }
  859. uint32_t RenderingServer::mesh_surface_get_format_skin_stride(BitField<ArrayFormat> p_format, int p_vertex_len) const {
  860. p_format = uint64_t(p_format) & ~ARRAY_FORMAT_INDEX;
  861. uint32_t offsets[ARRAY_MAX];
  862. uint32_t vstr;
  863. uint32_t ntstr;
  864. uint32_t astr;
  865. uint32_t sstr;
  866. mesh_surface_make_offsets_from_format(p_format, p_vertex_len, 0, offsets, vstr, ntstr, astr, sstr);
  867. return sstr;
  868. }
  869. void RenderingServer::mesh_surface_make_offsets_from_format(uint64_t p_format, int p_vertex_len, int p_index_len, uint32_t *r_offsets, uint32_t &r_vertex_element_size, uint32_t &r_normal_element_size, uint32_t &r_attrib_element_size, uint32_t &r_skin_element_size) const {
  870. r_vertex_element_size = 0;
  871. r_normal_element_size = 0;
  872. r_attrib_element_size = 0;
  873. r_skin_element_size = 0;
  874. uint32_t *size_accum = nullptr;
  875. for (int i = 0; i < RS::ARRAY_MAX; i++) {
  876. r_offsets[i] = 0; // Reset
  877. if (i == RS::ARRAY_VERTEX) {
  878. size_accum = &r_vertex_element_size;
  879. } else if (i == RS::ARRAY_NORMAL) {
  880. size_accum = &r_normal_element_size;
  881. } else if (i == RS::ARRAY_COLOR) {
  882. size_accum = &r_attrib_element_size;
  883. } else if (i == RS::ARRAY_BONES) {
  884. size_accum = &r_skin_element_size;
  885. }
  886. if (!(p_format & (1ULL << i))) { // No array
  887. continue;
  888. }
  889. int elem_size = 0;
  890. switch (i) {
  891. case RS::ARRAY_VERTEX: {
  892. if (p_format & ARRAY_FLAG_USE_2D_VERTICES) {
  893. elem_size = 2;
  894. } else {
  895. elem_size = (p_format & ARRAY_FLAG_COMPRESS_ATTRIBUTES) ? 2 : 3;
  896. }
  897. elem_size *= sizeof(float);
  898. } break;
  899. case RS::ARRAY_NORMAL: {
  900. elem_size = 4;
  901. } break;
  902. case RS::ARRAY_TANGENT: {
  903. elem_size = (p_format & ARRAY_FLAG_COMPRESS_ATTRIBUTES) ? 0 : 4;
  904. } break;
  905. case RS::ARRAY_COLOR: {
  906. elem_size = 4;
  907. } break;
  908. case RS::ARRAY_TEX_UV: {
  909. elem_size = (p_format & ARRAY_FLAG_COMPRESS_ATTRIBUTES) ? 4 : 8;
  910. } break;
  911. case RS::ARRAY_TEX_UV2: {
  912. elem_size = (p_format & ARRAY_FLAG_COMPRESS_ATTRIBUTES) ? 4 : 8;
  913. } break;
  914. case RS::ARRAY_CUSTOM0:
  915. case RS::ARRAY_CUSTOM1:
  916. case RS::ARRAY_CUSTOM2:
  917. case RS::ARRAY_CUSTOM3: {
  918. uint64_t format = (p_format >> (ARRAY_FORMAT_CUSTOM_BASE + (ARRAY_FORMAT_CUSTOM_BITS * (i - ARRAY_CUSTOM0)))) & ARRAY_FORMAT_CUSTOM_MASK;
  919. switch (format) {
  920. case ARRAY_CUSTOM_RGBA8_UNORM: {
  921. elem_size = 4;
  922. } break;
  923. case ARRAY_CUSTOM_RGBA8_SNORM: {
  924. elem_size = 4;
  925. } break;
  926. case ARRAY_CUSTOM_RG_HALF: {
  927. elem_size = 4;
  928. } break;
  929. case ARRAY_CUSTOM_RGBA_HALF: {
  930. elem_size = 8;
  931. } break;
  932. case ARRAY_CUSTOM_R_FLOAT: {
  933. elem_size = 4;
  934. } break;
  935. case ARRAY_CUSTOM_RG_FLOAT: {
  936. elem_size = 8;
  937. } break;
  938. case ARRAY_CUSTOM_RGB_FLOAT: {
  939. elem_size = 12;
  940. } break;
  941. case ARRAY_CUSTOM_RGBA_FLOAT: {
  942. elem_size = 16;
  943. } break;
  944. }
  945. } break;
  946. case RS::ARRAY_WEIGHTS: {
  947. uint32_t bone_count = (p_format & ARRAY_FLAG_USE_8_BONE_WEIGHTS) ? 8 : 4;
  948. elem_size = sizeof(uint16_t) * bone_count;
  949. } break;
  950. case RS::ARRAY_BONES: {
  951. uint32_t bone_count = (p_format & ARRAY_FLAG_USE_8_BONE_WEIGHTS) ? 8 : 4;
  952. elem_size = sizeof(uint16_t) * bone_count;
  953. } break;
  954. case RS::ARRAY_INDEX: {
  955. if (p_index_len <= 0) {
  956. ERR_PRINT("index_array_len==NO_INDEX_ARRAY");
  957. break;
  958. }
  959. /* determine whether using 16 or 32 bits indices */
  960. if (p_vertex_len <= (1 << 16) && p_vertex_len > 0) {
  961. elem_size = 2;
  962. } else {
  963. elem_size = 4;
  964. }
  965. r_offsets[i] = elem_size;
  966. continue;
  967. }
  968. default: {
  969. ERR_FAIL();
  970. }
  971. }
  972. if (size_accum != nullptr) {
  973. r_offsets[i] = (*size_accum);
  974. if (i == RS::ARRAY_NORMAL || i == RS::ARRAY_TANGENT) {
  975. r_offsets[i] += r_vertex_element_size * p_vertex_len;
  976. }
  977. (*size_accum) += elem_size;
  978. } else {
  979. r_offsets[i] = 0;
  980. }
  981. }
  982. }
  983. Error RenderingServer::mesh_create_surface_data_from_arrays(SurfaceData *r_surface_data, PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, const Dictionary &p_lods, uint64_t p_compress_format) {
  984. ERR_FAIL_INDEX_V(p_primitive, RS::PRIMITIVE_MAX, ERR_INVALID_PARAMETER);
  985. ERR_FAIL_COND_V(p_arrays.size() != RS::ARRAY_MAX, ERR_INVALID_PARAMETER);
  986. uint64_t format = 0;
  987. // Validation
  988. int index_array_len = 0;
  989. int array_len = 0;
  990. for (int i = 0; i < p_arrays.size(); i++) {
  991. if (p_arrays[i].get_type() == Variant::NIL) {
  992. continue;
  993. }
  994. format |= (1ULL << i);
  995. if (i == RS::ARRAY_VERTEX) {
  996. switch (p_arrays[i].get_type()) {
  997. case Variant::PACKED_VECTOR2_ARRAY: {
  998. Vector<Vector2> v2 = p_arrays[i];
  999. array_len = v2.size();
  1000. format |= ARRAY_FLAG_USE_2D_VERTICES;
  1001. } break;
  1002. case Variant::PACKED_VECTOR3_ARRAY: {
  1003. ERR_FAIL_COND_V(p_compress_format & ARRAY_FLAG_USE_2D_VERTICES, ERR_INVALID_PARAMETER);
  1004. Vector<Vector3> v3 = p_arrays[i];
  1005. array_len = v3.size();
  1006. } break;
  1007. default: {
  1008. ERR_FAIL_V_MSG(ERR_INVALID_DATA, "Vertex array must be a PackedVector2Array or PackedVector3Array.");
  1009. } break;
  1010. }
  1011. ERR_FAIL_COND_V(array_len == 0, ERR_INVALID_DATA);
  1012. } else if (i == RS::ARRAY_NORMAL) {
  1013. if (p_arrays[RS::ARRAY_TANGENT].get_type() == Variant::NIL) {
  1014. // We must use tangents if using normals.
  1015. format |= (1ULL << RS::ARRAY_TANGENT);
  1016. }
  1017. } else if (i == RS::ARRAY_BONES) {
  1018. switch (p_arrays[i].get_type()) {
  1019. case Variant::PACKED_INT32_ARRAY: {
  1020. Vector<Vector3> vertices = p_arrays[RS::ARRAY_VERTEX];
  1021. Vector<int32_t> bones = p_arrays[i];
  1022. int32_t bone_8_group_count = bones.size() / (ARRAY_WEIGHTS_SIZE * 2);
  1023. int32_t vertex_count = vertices.size();
  1024. if (vertex_count == bone_8_group_count) {
  1025. format |= RS::ARRAY_FLAG_USE_8_BONE_WEIGHTS;
  1026. }
  1027. } break;
  1028. default: {
  1029. ERR_FAIL_V_MSG(ERR_INVALID_DATA, "Bones array must be a PackedInt32Array.");
  1030. } break;
  1031. }
  1032. } else if (i == RS::ARRAY_INDEX) {
  1033. index_array_len = PackedInt32Array(p_arrays[i]).size();
  1034. }
  1035. }
  1036. if (p_blend_shapes.size()) {
  1037. // Validate format for morphs.
  1038. for (int i = 0; i < p_blend_shapes.size(); i++) {
  1039. uint32_t bsformat = 0;
  1040. Array arr = p_blend_shapes[i];
  1041. for (int j = 0; j < arr.size(); j++) {
  1042. if (arr[j].get_type() != Variant::NIL) {
  1043. bsformat |= (1 << j);
  1044. }
  1045. }
  1046. ERR_FAIL_COND_V_MSG(bsformat != (format & RS::ARRAY_FORMAT_BLEND_SHAPE_MASK), ERR_INVALID_PARAMETER, "Blend shape format must match the main array format for Vertex, Normal and Tangent arrays.");
  1047. }
  1048. }
  1049. for (uint32_t i = 0; i < RS::ARRAY_CUSTOM_COUNT; ++i) {
  1050. // Include custom array format type.
  1051. if (format & (1ULL << (ARRAY_CUSTOM0 + i))) {
  1052. format |= (RS::ARRAY_FORMAT_CUSTOM_MASK << (RS::ARRAY_FORMAT_CUSTOM_BASE + i * RS::ARRAY_FORMAT_CUSTOM_BITS)) & p_compress_format;
  1053. }
  1054. }
  1055. uint32_t offsets[RS::ARRAY_MAX];
  1056. uint32_t vertex_element_size;
  1057. uint32_t normal_element_size;
  1058. uint32_t attrib_element_size;
  1059. uint32_t skin_element_size;
  1060. uint64_t mask = (1ULL << ARRAY_MAX) - 1ULL;
  1061. format |= (~mask) & p_compress_format; // Make the full format.
  1062. // Force version to the current version as this function will always return a surface with the current version.
  1063. format &= ~(ARRAY_FLAG_FORMAT_VERSION_MASK << ARRAY_FLAG_FORMAT_VERSION_SHIFT);
  1064. format |= ARRAY_FLAG_FORMAT_CURRENT_VERSION & (ARRAY_FLAG_FORMAT_VERSION_MASK << ARRAY_FLAG_FORMAT_VERSION_SHIFT);
  1065. mesh_surface_make_offsets_from_format(format, array_len, index_array_len, offsets, vertex_element_size, normal_element_size, attrib_element_size, skin_element_size);
  1066. if ((format & RS::ARRAY_FORMAT_VERTEX) == 0 && !(format & RS::ARRAY_FLAG_USES_EMPTY_VERTEX_ARRAY)) {
  1067. ERR_PRINT("Mesh created without vertex array. This mesh will not be visible with the default shader. If using an empty vertex array is intentional, create the mesh with the ARRAY_FLAG_USES_EMPTY_VERTEX_ARRAY flag to silence this error.");
  1068. // Set the flag here after warning to suppress errors down the pipeline.
  1069. format |= RS::ARRAY_FLAG_USES_EMPTY_VERTEX_ARRAY;
  1070. }
  1071. if ((format & RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES) && ((format & RS::ARRAY_FORMAT_NORMAL) || (format & RS::ARRAY_FORMAT_TANGENT))) {
  1072. // If using normals or tangents, then we need all three.
  1073. ERR_FAIL_COND_V_MSG(!(format & RS::ARRAY_FORMAT_VERTEX), ERR_INVALID_PARAMETER, "Can't use compression flag 'ARRAY_FLAG_COMPRESS_ATTRIBUTES' while using normals or tangents without vertex array.");
  1074. ERR_FAIL_COND_V_MSG(!(format & RS::ARRAY_FORMAT_NORMAL), ERR_INVALID_PARAMETER, "Can't use compression flag 'ARRAY_FLAG_COMPRESS_ATTRIBUTES' while using tangents without normal array.");
  1075. }
  1076. int vertex_array_size = (vertex_element_size + normal_element_size) * array_len;
  1077. int attrib_array_size = attrib_element_size * array_len;
  1078. int skin_array_size = skin_element_size * array_len;
  1079. int index_array_size = offsets[RS::ARRAY_INDEX] * index_array_len;
  1080. Vector<uint8_t> vertex_array;
  1081. vertex_array.resize(vertex_array_size);
  1082. Vector<uint8_t> attrib_array;
  1083. attrib_array.resize(attrib_array_size);
  1084. Vector<uint8_t> skin_array;
  1085. skin_array.resize(skin_array_size);
  1086. Vector<uint8_t> index_array;
  1087. index_array.resize(index_array_size);
  1088. AABB aabb;
  1089. Vector<AABB> bone_aabb;
  1090. Vector4 uv_scale = Vector4(0.0, 0.0, 0.0, 0.0);
  1091. Error err = _surface_set_data(p_arrays, format, offsets, vertex_element_size, normal_element_size, attrib_element_size, skin_element_size, vertex_array, attrib_array, skin_array, array_len, index_array, index_array_len, aabb, bone_aabb, uv_scale);
  1092. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Invalid array format for surface.");
  1093. Vector<uint8_t> blend_shape_data;
  1094. if (p_blend_shapes.size()) {
  1095. uint32_t bs_format = format & RS::ARRAY_FORMAT_BLEND_SHAPE_MASK;
  1096. for (int i = 0; i < p_blend_shapes.size(); i++) {
  1097. Vector<uint8_t> vertex_array_shape;
  1098. vertex_array_shape.resize(vertex_array_size);
  1099. Vector<uint8_t> noindex;
  1100. Vector<uint8_t> noattrib;
  1101. Vector<uint8_t> noskin;
  1102. AABB laabb;
  1103. Vector4 bone_uv_scale; // Not used.
  1104. Error err2 = _surface_set_data(p_blend_shapes[i], bs_format, offsets, vertex_element_size, normal_element_size, 0, 0, vertex_array_shape, noattrib, noskin, array_len, noindex, 0, laabb, bone_aabb, bone_uv_scale);
  1105. aabb.merge_with(laabb);
  1106. ERR_FAIL_COND_V_MSG(err2 != OK, ERR_INVALID_DATA, "Invalid blend shape array format for surface.");
  1107. blend_shape_data.append_array(vertex_array_shape);
  1108. }
  1109. }
  1110. Vector<SurfaceData::LOD> lods;
  1111. if (index_array_len) {
  1112. List<Variant> keys;
  1113. p_lods.get_key_list(&keys);
  1114. keys.sort(); // otherwise lod levels may get skipped
  1115. for (const Variant &E : keys) {
  1116. float distance = E;
  1117. ERR_CONTINUE(distance <= 0.0);
  1118. Vector<int> indices = p_lods[E];
  1119. ERR_CONTINUE(indices.is_empty());
  1120. uint32_t index_count = indices.size();
  1121. ERR_CONTINUE(index_count >= (uint32_t)index_array_len); // Should be smaller..
  1122. const int *r = indices.ptr();
  1123. Vector<uint8_t> data;
  1124. if (array_len <= 65536) {
  1125. // 16 bits indices
  1126. data.resize(indices.size() * 2);
  1127. uint8_t *w = data.ptrw();
  1128. uint16_t *index_ptr = (uint16_t *)w;
  1129. for (uint32_t i = 0; i < index_count; i++) {
  1130. index_ptr[i] = r[i];
  1131. }
  1132. } else {
  1133. // 32 bits indices
  1134. data.resize(indices.size() * 4);
  1135. uint8_t *w = data.ptrw();
  1136. uint32_t *index_ptr = (uint32_t *)w;
  1137. for (uint32_t i = 0; i < index_count; i++) {
  1138. index_ptr[i] = r[i];
  1139. }
  1140. }
  1141. SurfaceData::LOD lod;
  1142. lod.edge_length = distance;
  1143. lod.index_data = data;
  1144. lods.push_back(lod);
  1145. }
  1146. }
  1147. SurfaceData &surface_data = *r_surface_data;
  1148. surface_data.format = format;
  1149. surface_data.primitive = p_primitive;
  1150. surface_data.aabb = aabb;
  1151. surface_data.vertex_data = vertex_array;
  1152. surface_data.attribute_data = attrib_array;
  1153. surface_data.skin_data = skin_array;
  1154. surface_data.vertex_count = array_len;
  1155. surface_data.index_data = index_array;
  1156. surface_data.index_count = index_array_len;
  1157. surface_data.blend_shape_data = blend_shape_data;
  1158. surface_data.bone_aabbs = bone_aabb;
  1159. surface_data.lods = lods;
  1160. surface_data.uv_scale = uv_scale;
  1161. return OK;
  1162. }
  1163. void RenderingServer::mesh_add_surface_from_arrays(RID p_mesh, PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, const Dictionary &p_lods, BitField<ArrayFormat> p_compress_format) {
  1164. SurfaceData sd;
  1165. Error err = mesh_create_surface_data_from_arrays(&sd, p_primitive, p_arrays, p_blend_shapes, p_lods, p_compress_format);
  1166. if (err != OK) {
  1167. return;
  1168. }
  1169. mesh_add_surface(p_mesh, sd);
  1170. }
  1171. Array RenderingServer::_get_array_from_surface(uint64_t p_format, Vector<uint8_t> p_vertex_data, Vector<uint8_t> p_attrib_data, Vector<uint8_t> p_skin_data, int p_vertex_len, Vector<uint8_t> p_index_data, int p_index_len, const AABB &p_aabb, const Vector4 &p_uv_scale) const {
  1172. uint32_t offsets[RS::ARRAY_MAX];
  1173. uint32_t vertex_elem_size;
  1174. uint32_t normal_elem_size;
  1175. uint32_t attrib_elem_size;
  1176. uint32_t skin_elem_size;
  1177. mesh_surface_make_offsets_from_format(p_format, p_vertex_len, p_index_len, offsets, vertex_elem_size, normal_elem_size, attrib_elem_size, skin_elem_size);
  1178. Array ret;
  1179. ret.resize(RS::ARRAY_MAX);
  1180. const uint8_t *r = p_vertex_data.ptr();
  1181. const uint8_t *ar = p_attrib_data.ptr();
  1182. const uint8_t *sr = p_skin_data.ptr();
  1183. for (int i = 0; i < RS::ARRAY_MAX; i++) {
  1184. if (!(p_format & (1ULL << i))) {
  1185. continue;
  1186. }
  1187. switch (i) {
  1188. case RS::ARRAY_VERTEX: {
  1189. if (p_format & ARRAY_FLAG_USE_2D_VERTICES) {
  1190. Vector<Vector2> arr_2d;
  1191. arr_2d.resize(p_vertex_len);
  1192. {
  1193. Vector2 *w = arr_2d.ptrw();
  1194. for (int j = 0; j < p_vertex_len; j++) {
  1195. const float *v = reinterpret_cast<const float *>(&r[j * vertex_elem_size + offsets[i]]);
  1196. w[j] = Vector2(v[0], v[1]);
  1197. }
  1198. }
  1199. ret[i] = arr_2d;
  1200. } else {
  1201. Vector<Vector3> arr_3d;
  1202. arr_3d.resize(p_vertex_len);
  1203. {
  1204. Vector3 *w = arr_3d.ptrw();
  1205. if (p_format & ARRAY_FLAG_COMPRESS_ATTRIBUTES) {
  1206. // We only have vertices to read, so just read them and skip everything else.
  1207. if (!(p_format & RS::ARRAY_FORMAT_NORMAL)) {
  1208. for (int j = 0; j < p_vertex_len; j++) {
  1209. const uint16_t *v = reinterpret_cast<const uint16_t *>(&r[j * vertex_elem_size + offsets[i]]);
  1210. Vector3 vec = Vector3(float(v[0]) / 65535.0, float(v[1]) / 65535.0, float(v[2]) / 65535.0);
  1211. w[j] = (vec * p_aabb.size) + p_aabb.position;
  1212. }
  1213. continue;
  1214. }
  1215. Vector<Vector3> normals;
  1216. normals.resize(p_vertex_len);
  1217. Vector3 *normalsw = normals.ptrw();
  1218. Vector<float> tangents;
  1219. tangents.resize(p_vertex_len * 4);
  1220. float *tangentsw = tangents.ptrw();
  1221. for (int j = 0; j < p_vertex_len; j++) {
  1222. const uint32_t n = *(const uint32_t *)&r[j * normal_elem_size + offsets[RS::ARRAY_NORMAL]];
  1223. Vector3 axis = Vector3::octahedron_decode(Vector2((n & 0xFFFF) / 65535.0, ((n >> 16) & 0xFFFF) / 65535.0));
  1224. const uint16_t *v = reinterpret_cast<const uint16_t *>(&r[j * vertex_elem_size + offsets[i]]);
  1225. Vector3 vec = Vector3(float(v[0]) / 65535.0, float(v[1]) / 65535.0, float(v[2]) / 65535.0);
  1226. float angle = float(v[3]) / 65535.0;
  1227. w[j] = (vec * p_aabb.size) + p_aabb.position;
  1228. Vector3 normal;
  1229. Vector4 tan;
  1230. _get_tbn_from_axis_angle(axis, angle, normal, tan);
  1231. normalsw[j] = normal;
  1232. tangentsw[j * 4 + 0] = tan.x;
  1233. tangentsw[j * 4 + 1] = tan.y;
  1234. tangentsw[j * 4 + 2] = tan.z;
  1235. tangentsw[j * 4 + 3] = tan.w;
  1236. }
  1237. ret[RS::ARRAY_NORMAL] = normals;
  1238. ret[RS::ARRAY_TANGENT] = tangents;
  1239. } else {
  1240. for (int j = 0; j < p_vertex_len; j++) {
  1241. const float *v = reinterpret_cast<const float *>(&r[j * vertex_elem_size + offsets[i]]);
  1242. w[j] = Vector3(v[0], v[1], v[2]);
  1243. }
  1244. }
  1245. }
  1246. ret[i] = arr_3d;
  1247. }
  1248. } break;
  1249. case RS::ARRAY_NORMAL: {
  1250. if (!(p_format & RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES)) {
  1251. Vector<Vector3> arr;
  1252. arr.resize(p_vertex_len);
  1253. Vector3 *w = arr.ptrw();
  1254. for (int j = 0; j < p_vertex_len; j++) {
  1255. const uint32_t v = *(const uint32_t *)&r[j * normal_elem_size + offsets[i]];
  1256. w[j] = Vector3::octahedron_decode(Vector2((v & 0xFFFF) / 65535.0, ((v >> 16) & 0xFFFF) / 65535.0));
  1257. }
  1258. ret[i] = arr;
  1259. }
  1260. } break;
  1261. case RS::ARRAY_TANGENT: {
  1262. if (!(p_format & RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES)) {
  1263. Vector<float> arr;
  1264. arr.resize(p_vertex_len * 4);
  1265. float *w = arr.ptrw();
  1266. for (int j = 0; j < p_vertex_len; j++) {
  1267. const uint32_t v = *(const uint32_t *)&r[j * normal_elem_size + offsets[i]];
  1268. float tangent_sign;
  1269. Vector3 res = Vector3::octahedron_tangent_decode(Vector2((v & 0xFFFF) / 65535.0, ((v >> 16) & 0xFFFF) / 65535.0), &tangent_sign);
  1270. w[j * 4 + 0] = res.x;
  1271. w[j * 4 + 1] = res.y;
  1272. w[j * 4 + 2] = res.z;
  1273. w[j * 4 + 3] = tangent_sign;
  1274. }
  1275. ret[i] = arr;
  1276. }
  1277. } break;
  1278. case RS::ARRAY_COLOR: {
  1279. Vector<Color> arr;
  1280. arr.resize(p_vertex_len);
  1281. Color *w = arr.ptrw();
  1282. for (int32_t j = 0; j < p_vertex_len; j++) {
  1283. const uint8_t *v = reinterpret_cast<const uint8_t *>(&ar[j * attrib_elem_size + offsets[i]]);
  1284. w[j] = Color(v[0] / 255.0, v[1] / 255.0, v[2] / 255.0, v[3] / 255.0);
  1285. }
  1286. ret[i] = arr;
  1287. } break;
  1288. case RS::ARRAY_TEX_UV: {
  1289. Vector<Vector2> arr;
  1290. arr.resize(p_vertex_len);
  1291. Vector2 *w = arr.ptrw();
  1292. if (p_format & ARRAY_FLAG_COMPRESS_ATTRIBUTES) {
  1293. for (int j = 0; j < p_vertex_len; j++) {
  1294. const uint16_t *v = reinterpret_cast<const uint16_t *>(&ar[j * attrib_elem_size + offsets[i]]);
  1295. Vector2 vec = Vector2(float(v[0]) / 65535.0, float(v[1]) / 65535.0);
  1296. if (!p_uv_scale.is_zero_approx()) {
  1297. vec = (vec - Vector2(0.5, 0.5)) * Vector2(p_uv_scale.x, p_uv_scale.y);
  1298. }
  1299. w[j] = vec;
  1300. }
  1301. } else {
  1302. for (int j = 0; j < p_vertex_len; j++) {
  1303. const float *v = reinterpret_cast<const float *>(&ar[j * attrib_elem_size + offsets[i]]);
  1304. w[j] = Vector2(v[0], v[1]);
  1305. }
  1306. }
  1307. ret[i] = arr;
  1308. } break;
  1309. case RS::ARRAY_TEX_UV2: {
  1310. Vector<Vector2> arr;
  1311. arr.resize(p_vertex_len);
  1312. Vector2 *w = arr.ptrw();
  1313. if (p_format & ARRAY_FLAG_COMPRESS_ATTRIBUTES) {
  1314. for (int j = 0; j < p_vertex_len; j++) {
  1315. const uint16_t *v = reinterpret_cast<const uint16_t *>(&ar[j * attrib_elem_size + offsets[i]]);
  1316. Vector2 vec = Vector2(float(v[0]) / 65535.0, float(v[1]) / 65535.0);
  1317. if (!p_uv_scale.is_zero_approx()) {
  1318. vec = (vec - Vector2(0.5, 0.5)) * Vector2(p_uv_scale.z, p_uv_scale.w);
  1319. }
  1320. w[j] = vec;
  1321. }
  1322. } else {
  1323. for (int j = 0; j < p_vertex_len; j++) {
  1324. const float *v = reinterpret_cast<const float *>(&ar[j * attrib_elem_size + offsets[i]]);
  1325. w[j] = Vector2(v[0], v[1]);
  1326. }
  1327. }
  1328. ret[i] = arr;
  1329. } break;
  1330. case RS::ARRAY_CUSTOM0:
  1331. case RS::ARRAY_CUSTOM1:
  1332. case RS::ARRAY_CUSTOM2:
  1333. case RS::ARRAY_CUSTOM3: {
  1334. uint32_t type = (p_format >> (ARRAY_FORMAT_CUSTOM_BASE + ARRAY_FORMAT_CUSTOM_BITS * (i - RS::ARRAY_CUSTOM0))) & ARRAY_FORMAT_CUSTOM_MASK;
  1335. switch (type) {
  1336. case ARRAY_CUSTOM_RGBA8_UNORM:
  1337. case ARRAY_CUSTOM_RGBA8_SNORM:
  1338. case ARRAY_CUSTOM_RG_HALF:
  1339. case ARRAY_CUSTOM_RGBA_HALF: {
  1340. // Size 4
  1341. int s = type == ARRAY_CUSTOM_RGBA_HALF ? 8 : 4;
  1342. Vector<uint8_t> arr;
  1343. arr.resize(p_vertex_len * s);
  1344. uint8_t *w = arr.ptrw();
  1345. for (int j = 0; j < p_vertex_len; j++) {
  1346. const uint8_t *v = reinterpret_cast<const uint8_t *>(&ar[j * attrib_elem_size + offsets[i]]);
  1347. memcpy(&w[j * s], v, s);
  1348. }
  1349. ret[i] = arr;
  1350. } break;
  1351. case ARRAY_CUSTOM_R_FLOAT:
  1352. case ARRAY_CUSTOM_RG_FLOAT:
  1353. case ARRAY_CUSTOM_RGB_FLOAT:
  1354. case ARRAY_CUSTOM_RGBA_FLOAT: {
  1355. uint32_t s = type - ARRAY_CUSTOM_R_FLOAT + 1;
  1356. Vector<float> arr;
  1357. arr.resize(s * p_vertex_len);
  1358. float *w = arr.ptrw();
  1359. for (int j = 0; j < p_vertex_len; j++) {
  1360. const float *v = reinterpret_cast<const float *>(&ar[j * attrib_elem_size + offsets[i]]);
  1361. memcpy(&w[j * s], v, s * sizeof(float));
  1362. }
  1363. ret[i] = arr;
  1364. } break;
  1365. default: {
  1366. }
  1367. }
  1368. } break;
  1369. case RS::ARRAY_WEIGHTS: {
  1370. uint32_t bone_count = (p_format & ARRAY_FLAG_USE_8_BONE_WEIGHTS) ? 8 : 4;
  1371. Vector<float> arr;
  1372. arr.resize(p_vertex_len * bone_count);
  1373. {
  1374. float *w = arr.ptrw();
  1375. for (int j = 0; j < p_vertex_len; j++) {
  1376. const uint16_t *v = (const uint16_t *)&sr[j * skin_elem_size + offsets[i]];
  1377. for (uint32_t k = 0; k < bone_count; k++) {
  1378. w[j * bone_count + k] = float(v[k] / 65535.0);
  1379. }
  1380. }
  1381. }
  1382. ret[i] = arr;
  1383. } break;
  1384. case RS::ARRAY_BONES: {
  1385. uint32_t bone_count = (p_format & ARRAY_FLAG_USE_8_BONE_WEIGHTS) ? 8 : 4;
  1386. Vector<int> arr;
  1387. arr.resize(p_vertex_len * bone_count);
  1388. int *w = arr.ptrw();
  1389. for (int j = 0; j < p_vertex_len; j++) {
  1390. const uint16_t *v = (const uint16_t *)&sr[j * skin_elem_size + offsets[i]];
  1391. for (uint32_t k = 0; k < bone_count; k++) {
  1392. w[j * bone_count + k] = v[k];
  1393. }
  1394. }
  1395. ret[i] = arr;
  1396. } break;
  1397. case RS::ARRAY_INDEX: {
  1398. /* determine whether using 16 or 32 bits indices */
  1399. const uint8_t *ir = p_index_data.ptr();
  1400. Vector<int> arr;
  1401. arr.resize(p_index_len);
  1402. if (p_vertex_len <= (1 << 16)) {
  1403. int *w = arr.ptrw();
  1404. for (int j = 0; j < p_index_len; j++) {
  1405. const uint16_t *v = (const uint16_t *)&ir[j * 2];
  1406. w[j] = *v;
  1407. }
  1408. } else {
  1409. int *w = arr.ptrw();
  1410. for (int j = 0; j < p_index_len; j++) {
  1411. const int *v = (const int *)&ir[j * 4];
  1412. w[j] = *v;
  1413. }
  1414. }
  1415. ret[i] = arr;
  1416. } break;
  1417. default: {
  1418. ERR_FAIL_V(ret);
  1419. }
  1420. }
  1421. }
  1422. return ret;
  1423. }
  1424. Array RenderingServer::mesh_surface_get_arrays(RID p_mesh, int p_surface) const {
  1425. SurfaceData sd = mesh_get_surface(p_mesh, p_surface);
  1426. return mesh_create_arrays_from_surface_data(sd);
  1427. }
  1428. Dictionary RenderingServer::mesh_surface_get_lods(RID p_mesh, int p_surface) const {
  1429. SurfaceData sd = mesh_get_surface(p_mesh, p_surface);
  1430. ERR_FAIL_COND_V(sd.vertex_count == 0, Dictionary());
  1431. Dictionary ret;
  1432. for (int i = 0; i < sd.lods.size(); i++) {
  1433. Vector<int> lods;
  1434. if (sd.vertex_count <= 65536) {
  1435. uint32_t lc = sd.lods[i].index_data.size() / 2;
  1436. lods.resize(lc);
  1437. const uint8_t *r = sd.lods[i].index_data.ptr();
  1438. const uint16_t *rptr = (const uint16_t *)r;
  1439. int *w = lods.ptrw();
  1440. for (uint32_t j = 0; j < lc; j++) {
  1441. w[j] = rptr[i];
  1442. }
  1443. } else {
  1444. uint32_t lc = sd.lods[i].index_data.size() / 4;
  1445. lods.resize(lc);
  1446. const uint8_t *r = sd.lods[i].index_data.ptr();
  1447. const uint32_t *rptr = (const uint32_t *)r;
  1448. int *w = lods.ptrw();
  1449. for (uint32_t j = 0; j < lc; j++) {
  1450. w[j] = rptr[i];
  1451. }
  1452. }
  1453. ret[sd.lods[i].edge_length] = lods;
  1454. }
  1455. return ret;
  1456. }
  1457. TypedArray<Array> RenderingServer::mesh_surface_get_blend_shape_arrays(RID p_mesh, int p_surface) const {
  1458. SurfaceData sd = mesh_get_surface(p_mesh, p_surface);
  1459. ERR_FAIL_COND_V(sd.vertex_count == 0, Array());
  1460. Vector<uint8_t> blend_shape_data = sd.blend_shape_data;
  1461. if (blend_shape_data.size() > 0) {
  1462. uint32_t bs_offsets[RS::ARRAY_MAX];
  1463. uint32_t bs_format = (sd.format & RS::ARRAY_FORMAT_BLEND_SHAPE_MASK);
  1464. uint32_t vertex_elem_size;
  1465. uint32_t normal_elem_size;
  1466. uint32_t attrib_elem_size;
  1467. uint32_t skin_elem_size;
  1468. mesh_surface_make_offsets_from_format(bs_format, sd.vertex_count, 0, bs_offsets, vertex_elem_size, normal_elem_size, attrib_elem_size, skin_elem_size);
  1469. int divisor = (vertex_elem_size + normal_elem_size) * sd.vertex_count;
  1470. ERR_FAIL_COND_V((blend_shape_data.size() % divisor) != 0, Array());
  1471. uint32_t blend_shape_count = blend_shape_data.size() / divisor;
  1472. ERR_FAIL_COND_V(blend_shape_count != (uint32_t)mesh_get_blend_shape_count(p_mesh), Array());
  1473. TypedArray<Array> blend_shape_array;
  1474. blend_shape_array.resize(mesh_get_blend_shape_count(p_mesh));
  1475. for (uint32_t i = 0; i < blend_shape_count; i++) {
  1476. Vector<uint8_t> bs_data = blend_shape_data.slice(i * divisor, (i + 1) * divisor);
  1477. Vector<uint8_t> unused;
  1478. blend_shape_array.set(i, _get_array_from_surface(bs_format, bs_data, unused, unused, sd.vertex_count, unused, 0, sd.aabb, sd.uv_scale));
  1479. }
  1480. return blend_shape_array;
  1481. } else {
  1482. return TypedArray<Array>();
  1483. }
  1484. }
  1485. Array RenderingServer::mesh_create_arrays_from_surface_data(const SurfaceData &p_data) const {
  1486. Vector<uint8_t> vertex_data = p_data.vertex_data;
  1487. Vector<uint8_t> attrib_data = p_data.attribute_data;
  1488. Vector<uint8_t> skin_data = p_data.skin_data;
  1489. ERR_FAIL_COND_V(vertex_data.is_empty() && (p_data.format & RS::ARRAY_FORMAT_VERTEX), Array());
  1490. int vertex_len = p_data.vertex_count;
  1491. Vector<uint8_t> index_data = p_data.index_data;
  1492. int index_len = p_data.index_count;
  1493. uint64_t format = p_data.format;
  1494. return _get_array_from_surface(format, vertex_data, attrib_data, skin_data, vertex_len, index_data, index_len, p_data.aabb, p_data.uv_scale);
  1495. }
  1496. #if 0
  1497. Array RenderingServer::_mesh_surface_get_skeleton_aabb_bind(RID p_mesh, int p_surface) const {
  1498. Vector<AABB> vec = RS::get_singleton()->mesh_surface_get_skeleton_aabb(p_mesh, p_surface);
  1499. Array arr;
  1500. for (int i = 0; i < vec.size(); i++) {
  1501. arr[i] = vec[i];
  1502. }
  1503. return arr;
  1504. }
  1505. #endif
  1506. Rect2 RenderingServer::debug_canvas_item_get_rect(RID p_item) {
  1507. #ifdef TOOLS_ENABLED
  1508. return _debug_canvas_item_get_rect(p_item);
  1509. #else
  1510. return Rect2();
  1511. #endif
  1512. }
  1513. int RenderingServer::global_shader_uniform_type_get_shader_datatype(GlobalShaderParameterType p_type) {
  1514. switch (p_type) {
  1515. case RS::GLOBAL_VAR_TYPE_BOOL:
  1516. return ShaderLanguage::TYPE_BOOL;
  1517. case RS::GLOBAL_VAR_TYPE_BVEC2:
  1518. return ShaderLanguage::TYPE_BVEC2;
  1519. case RS::GLOBAL_VAR_TYPE_BVEC3:
  1520. return ShaderLanguage::TYPE_BVEC3;
  1521. case RS::GLOBAL_VAR_TYPE_BVEC4:
  1522. return ShaderLanguage::TYPE_BVEC4;
  1523. case RS::GLOBAL_VAR_TYPE_INT:
  1524. return ShaderLanguage::TYPE_INT;
  1525. case RS::GLOBAL_VAR_TYPE_IVEC2:
  1526. return ShaderLanguage::TYPE_IVEC2;
  1527. case RS::GLOBAL_VAR_TYPE_IVEC3:
  1528. return ShaderLanguage::TYPE_IVEC3;
  1529. case RS::GLOBAL_VAR_TYPE_IVEC4:
  1530. return ShaderLanguage::TYPE_IVEC4;
  1531. case RS::GLOBAL_VAR_TYPE_RECT2I:
  1532. return ShaderLanguage::TYPE_IVEC4;
  1533. case RS::GLOBAL_VAR_TYPE_UINT:
  1534. return ShaderLanguage::TYPE_UINT;
  1535. case RS::GLOBAL_VAR_TYPE_UVEC2:
  1536. return ShaderLanguage::TYPE_UVEC2;
  1537. case RS::GLOBAL_VAR_TYPE_UVEC3:
  1538. return ShaderLanguage::TYPE_UVEC3;
  1539. case RS::GLOBAL_VAR_TYPE_UVEC4:
  1540. return ShaderLanguage::TYPE_UVEC4;
  1541. case RS::GLOBAL_VAR_TYPE_FLOAT:
  1542. return ShaderLanguage::TYPE_FLOAT;
  1543. case RS::GLOBAL_VAR_TYPE_VEC2:
  1544. return ShaderLanguage::TYPE_VEC2;
  1545. case RS::GLOBAL_VAR_TYPE_VEC3:
  1546. return ShaderLanguage::TYPE_VEC3;
  1547. case RS::GLOBAL_VAR_TYPE_VEC4:
  1548. return ShaderLanguage::TYPE_VEC4;
  1549. case RS::GLOBAL_VAR_TYPE_COLOR:
  1550. return ShaderLanguage::TYPE_VEC4;
  1551. case RS::GLOBAL_VAR_TYPE_RECT2:
  1552. return ShaderLanguage::TYPE_VEC4;
  1553. case RS::GLOBAL_VAR_TYPE_MAT2:
  1554. return ShaderLanguage::TYPE_MAT2;
  1555. case RS::GLOBAL_VAR_TYPE_MAT3:
  1556. return ShaderLanguage::TYPE_MAT3;
  1557. case RS::GLOBAL_VAR_TYPE_MAT4:
  1558. return ShaderLanguage::TYPE_MAT4;
  1559. case RS::GLOBAL_VAR_TYPE_TRANSFORM_2D:
  1560. return ShaderLanguage::TYPE_MAT3;
  1561. case RS::GLOBAL_VAR_TYPE_TRANSFORM:
  1562. return ShaderLanguage::TYPE_MAT4;
  1563. case RS::GLOBAL_VAR_TYPE_SAMPLER2D:
  1564. return ShaderLanguage::TYPE_SAMPLER2D;
  1565. case RS::GLOBAL_VAR_TYPE_SAMPLER2DARRAY:
  1566. return ShaderLanguage::TYPE_SAMPLER2DARRAY;
  1567. case RS::GLOBAL_VAR_TYPE_SAMPLER3D:
  1568. return ShaderLanguage::TYPE_SAMPLER3D;
  1569. case RS::GLOBAL_VAR_TYPE_SAMPLERCUBE:
  1570. return ShaderLanguage::TYPE_SAMPLERCUBE;
  1571. default:
  1572. return ShaderLanguage::TYPE_MAX; // Invalid or not found.
  1573. }
  1574. }
  1575. RenderingDevice *RenderingServer::get_rendering_device() const {
  1576. // Return the rendering device we're using globally.
  1577. return RenderingDevice::get_singleton();
  1578. }
  1579. RenderingDevice *RenderingServer::create_local_rendering_device() const {
  1580. RenderingDevice *device = RenderingDevice::get_singleton();
  1581. if (!device) {
  1582. return nullptr;
  1583. }
  1584. return device->create_local_device();
  1585. }
  1586. static Vector<Ref<Image>> _get_imgvec(const TypedArray<Image> &p_layers) {
  1587. Vector<Ref<Image>> images;
  1588. images.resize(p_layers.size());
  1589. for (int i = 0; i < p_layers.size(); i++) {
  1590. images.write[i] = p_layers[i];
  1591. }
  1592. return images;
  1593. }
  1594. RID RenderingServer::_texture_2d_layered_create(const TypedArray<Image> &p_layers, TextureLayeredType p_layered_type) {
  1595. return texture_2d_layered_create(_get_imgvec(p_layers), p_layered_type);
  1596. }
  1597. RID RenderingServer::_texture_3d_create(Image::Format p_format, int p_width, int p_height, int p_depth, bool p_mipmaps, const TypedArray<Image> &p_data) {
  1598. return texture_3d_create(p_format, p_width, p_height, p_depth, p_mipmaps, _get_imgvec(p_data));
  1599. }
  1600. void RenderingServer::_texture_3d_update(RID p_texture, const TypedArray<Image> &p_data) {
  1601. texture_3d_update(p_texture, _get_imgvec(p_data));
  1602. }
  1603. TypedArray<Image> RenderingServer::_texture_3d_get(RID p_texture) const {
  1604. Vector<Ref<Image>> images = texture_3d_get(p_texture);
  1605. TypedArray<Image> ret;
  1606. ret.resize(images.size());
  1607. for (int i = 0; i < images.size(); i++) {
  1608. ret[i] = images[i];
  1609. }
  1610. return ret;
  1611. }
  1612. TypedArray<Dictionary> RenderingServer::_shader_get_shader_parameter_list(RID p_shader) const {
  1613. List<PropertyInfo> l;
  1614. get_shader_parameter_list(p_shader, &l);
  1615. return convert_property_list(&l);
  1616. }
  1617. static RS::SurfaceData _dict_to_surf(const Dictionary &p_dictionary) {
  1618. ERR_FAIL_COND_V(!p_dictionary.has("primitive"), RS::SurfaceData());
  1619. ERR_FAIL_COND_V(!p_dictionary.has("format"), RS::SurfaceData());
  1620. ERR_FAIL_COND_V(!p_dictionary.has("vertex_data"), RS::SurfaceData());
  1621. ERR_FAIL_COND_V(!p_dictionary.has("vertex_count"), RS::SurfaceData());
  1622. ERR_FAIL_COND_V(!p_dictionary.has("aabb"), RS::SurfaceData());
  1623. RS::SurfaceData sd;
  1624. sd.primitive = RS::PrimitiveType(int(p_dictionary["primitive"]));
  1625. sd.format = p_dictionary["format"];
  1626. sd.vertex_data = p_dictionary["vertex_data"];
  1627. if (p_dictionary.has("attribute_data")) {
  1628. sd.attribute_data = p_dictionary["attribute_data"];
  1629. }
  1630. if (p_dictionary.has("skin_data")) {
  1631. sd.skin_data = p_dictionary["skin_data"];
  1632. }
  1633. sd.vertex_count = p_dictionary["vertex_count"];
  1634. if (p_dictionary.has("index_data")) {
  1635. sd.index_data = p_dictionary["index_data"];
  1636. ERR_FAIL_COND_V(!p_dictionary.has("index_count"), RS::SurfaceData());
  1637. sd.index_count = p_dictionary["index_count"];
  1638. }
  1639. sd.aabb = p_dictionary["aabb"];
  1640. if (p_dictionary.has("uv_scale")) {
  1641. sd.uv_scale = p_dictionary["uv_scale"];
  1642. }
  1643. if (p_dictionary.has("lods")) {
  1644. Array lods = p_dictionary["lods"];
  1645. for (int i = 0; i < lods.size(); i++) {
  1646. Dictionary lod = lods[i];
  1647. ERR_CONTINUE(!lod.has("edge_length"));
  1648. ERR_CONTINUE(!lod.has("index_data"));
  1649. RS::SurfaceData::LOD l;
  1650. l.edge_length = lod["edge_length"];
  1651. l.index_data = lod["index_data"];
  1652. sd.lods.push_back(l);
  1653. }
  1654. }
  1655. if (p_dictionary.has("bone_aabbs")) {
  1656. Array aabbs = p_dictionary["bone_aabbs"];
  1657. for (int i = 0; i < aabbs.size(); i++) {
  1658. AABB aabb = aabbs[i];
  1659. sd.bone_aabbs.push_back(aabb);
  1660. }
  1661. }
  1662. if (p_dictionary.has("blend_shape_data")) {
  1663. sd.blend_shape_data = p_dictionary["blend_shape_data"];
  1664. }
  1665. if (p_dictionary.has("material")) {
  1666. sd.material = p_dictionary["material"];
  1667. }
  1668. return sd;
  1669. }
  1670. RID RenderingServer::_mesh_create_from_surfaces(const TypedArray<Dictionary> &p_surfaces, int p_blend_shape_count) {
  1671. Vector<RS::SurfaceData> surfaces;
  1672. for (int i = 0; i < p_surfaces.size(); i++) {
  1673. surfaces.push_back(_dict_to_surf(p_surfaces[i]));
  1674. }
  1675. return mesh_create_from_surfaces(surfaces);
  1676. }
  1677. void RenderingServer::_mesh_add_surface(RID p_mesh, const Dictionary &p_surface) {
  1678. mesh_add_surface(p_mesh, _dict_to_surf(p_surface));
  1679. }
  1680. Dictionary RenderingServer::_mesh_get_surface(RID p_mesh, int p_idx) {
  1681. RS::SurfaceData sd = mesh_get_surface(p_mesh, p_idx);
  1682. Dictionary d;
  1683. d["primitive"] = sd.primitive;
  1684. d["format"] = sd.format;
  1685. d["vertex_data"] = sd.vertex_data;
  1686. if (sd.attribute_data.size()) {
  1687. d["attribute_data"] = sd.attribute_data;
  1688. }
  1689. if (sd.skin_data.size()) {
  1690. d["skin_data"] = sd.skin_data;
  1691. }
  1692. d["vertex_count"] = sd.vertex_count;
  1693. if (sd.index_count) {
  1694. d["index_data"] = sd.index_data;
  1695. d["index_count"] = sd.index_count;
  1696. }
  1697. d["aabb"] = sd.aabb;
  1698. d["uv_scale"] = sd.uv_scale;
  1699. if (sd.lods.size()) {
  1700. Array lods;
  1701. for (int i = 0; i < sd.lods.size(); i++) {
  1702. Dictionary ld;
  1703. ld["edge_length"] = sd.lods[i].edge_length;
  1704. ld["index_data"] = sd.lods[i].index_data;
  1705. lods.push_back(lods);
  1706. }
  1707. d["lods"] = lods;
  1708. }
  1709. if (sd.bone_aabbs.size()) {
  1710. Array aabbs;
  1711. for (int i = 0; i < sd.bone_aabbs.size(); i++) {
  1712. aabbs.push_back(sd.bone_aabbs[i]);
  1713. }
  1714. d["bone_aabbs"] = aabbs;
  1715. }
  1716. if (sd.blend_shape_data.size()) {
  1717. d["blend_shape_data"] = sd.blend_shape_data;
  1718. }
  1719. if (sd.material.is_valid()) {
  1720. d["material"] = sd.material;
  1721. }
  1722. return d;
  1723. }
  1724. TypedArray<Dictionary> RenderingServer::_instance_geometry_get_shader_parameter_list(RID p_instance) const {
  1725. List<PropertyInfo> params;
  1726. instance_geometry_get_shader_parameter_list(p_instance, &params);
  1727. return convert_property_list(&params);
  1728. }
  1729. TypedArray<Image> RenderingServer::_bake_render_uv2(RID p_base, const TypedArray<RID> &p_material_overrides, const Size2i &p_image_size) {
  1730. TypedArray<RID> mat_overrides;
  1731. for (int i = 0; i < p_material_overrides.size(); i++) {
  1732. mat_overrides.push_back(p_material_overrides[i]);
  1733. }
  1734. return bake_render_uv2(p_base, mat_overrides, p_image_size);
  1735. }
  1736. void RenderingServer::_particles_set_trail_bind_poses(RID p_particles, const TypedArray<Transform3D> &p_bind_poses) {
  1737. Vector<Transform3D> tbposes;
  1738. tbposes.resize(p_bind_poses.size());
  1739. for (int i = 0; i < p_bind_poses.size(); i++) {
  1740. tbposes.write[i] = p_bind_poses[i];
  1741. }
  1742. particles_set_trail_bind_poses(p_particles, tbposes);
  1743. }
  1744. Vector<uint8_t> _convert_surface_version_1_to_surface_version_2(uint64_t p_format, Vector<uint8_t> p_vertex_data, uint32_t p_vertex_count, uint32_t p_old_stride, uint32_t p_vertex_size, uint32_t p_normal_size, uint32_t p_position_stride, uint32_t p_normal_tangent_stride) {
  1745. Vector<uint8_t> new_vertex_data;
  1746. new_vertex_data.resize(p_vertex_data.size());
  1747. uint8_t *dst_vertex_ptr = new_vertex_data.ptrw();
  1748. const uint8_t *src_vertex_ptr = p_vertex_data.ptr();
  1749. uint32_t position_size = p_position_stride * p_vertex_count;
  1750. for (uint32_t j = 0; j < RS::ARRAY_COLOR; j++) {
  1751. if (!(p_format & (1ULL << j))) {
  1752. continue;
  1753. }
  1754. switch (j) {
  1755. case RS::ARRAY_VERTEX: {
  1756. if (p_format & RS::ARRAY_FLAG_USE_2D_VERTICES) {
  1757. for (uint32_t i = 0; i < p_vertex_count; i++) {
  1758. const float *src = (const float *)&src_vertex_ptr[i * p_old_stride];
  1759. float *dst = (float *)&dst_vertex_ptr[i * p_position_stride];
  1760. dst[0] = src[0];
  1761. dst[1] = src[1];
  1762. }
  1763. } else {
  1764. for (uint32_t i = 0; i < p_vertex_count; i++) {
  1765. const float *src = (const float *)&src_vertex_ptr[i * p_old_stride];
  1766. float *dst = (float *)&dst_vertex_ptr[i * p_position_stride];
  1767. dst[0] = src[0];
  1768. dst[1] = src[1];
  1769. dst[2] = src[2];
  1770. }
  1771. }
  1772. } break;
  1773. case RS::ARRAY_NORMAL: {
  1774. for (uint32_t i = 0; i < p_vertex_count; i++) {
  1775. const uint16_t *src = (const uint16_t *)&src_vertex_ptr[i * p_old_stride + p_vertex_size];
  1776. uint16_t *dst = (uint16_t *)&dst_vertex_ptr[i * p_normal_tangent_stride + position_size];
  1777. dst[0] = src[0];
  1778. dst[1] = src[1];
  1779. }
  1780. } break;
  1781. case RS::ARRAY_TANGENT: {
  1782. for (uint32_t i = 0; i < p_vertex_count; i++) {
  1783. const uint16_t *src = (const uint16_t *)&src_vertex_ptr[i * p_old_stride + p_vertex_size + p_normal_size];
  1784. uint16_t *dst = (uint16_t *)&dst_vertex_ptr[i * p_normal_tangent_stride + position_size + p_normal_size];
  1785. dst[0] = src[0];
  1786. dst[1] = src[1];
  1787. }
  1788. } break;
  1789. }
  1790. }
  1791. return new_vertex_data;
  1792. }
  1793. #ifdef TOOLS_ENABLED
  1794. void RenderingServer::set_surface_upgrade_callback(SurfaceUpgradeCallback p_callback) {
  1795. surface_upgrade_callback = p_callback;
  1796. }
  1797. void RenderingServer::set_warn_on_surface_upgrade(bool p_warn) {
  1798. warn_on_surface_upgrade = p_warn;
  1799. }
  1800. #endif
  1801. #ifndef DISABLE_DEPRECATED
  1802. void RenderingServer::fix_surface_compatibility(SurfaceData &p_surface, const String &p_path) {
  1803. uint64_t surface_version = p_surface.format & (ARRAY_FLAG_FORMAT_VERSION_MASK << ARRAY_FLAG_FORMAT_VERSION_SHIFT);
  1804. ERR_FAIL_COND_MSG(surface_version > ARRAY_FLAG_FORMAT_CURRENT_VERSION, "Cannot convert surface with version provided (" + itos((surface_version >> RS::ARRAY_FLAG_FORMAT_VERSION_SHIFT) & RS::ARRAY_FLAG_FORMAT_VERSION_MASK) + ") to current version (" + itos((RS::ARRAY_FLAG_FORMAT_CURRENT_VERSION >> RS::ARRAY_FLAG_FORMAT_VERSION_SHIFT) & RS::ARRAY_FLAG_FORMAT_VERSION_MASK) + ")");
  1805. #ifdef TOOLS_ENABLED
  1806. // Editor callback to ask user about re-saving all meshes.
  1807. if (surface_upgrade_callback && warn_on_surface_upgrade) {
  1808. surface_upgrade_callback();
  1809. }
  1810. if (warn_on_surface_upgrade) {
  1811. WARN_PRINT_ONCE_ED("At least one surface uses an old surface format and needs to be upgraded. The upgrade happens automatically at load time every time until the mesh is saved again or re-imported. Once saved (or re-imported), this mesh will be incompatible with earlier versions of Godot.");
  1812. if (!p_path.is_empty()) {
  1813. WARN_PRINT("A surface of " + p_path + " uses an old surface format and needs to be upgraded.");
  1814. }
  1815. }
  1816. #endif
  1817. if (surface_version == ARRAY_FLAG_FORMAT_VERSION_1) {
  1818. // The only difference for now is that Version 1 uses interleaved vertex positions while version 2 does not.
  1819. // I.e. PNTPNTPNT -> PPPNTNTNT.
  1820. if (p_surface.vertex_data.size() > 0 && p_surface.vertex_count > 0) {
  1821. int vertex_size = 0;
  1822. int normal_size = 0;
  1823. int tangent_size = 0;
  1824. if (p_surface.format & ARRAY_FORMAT_VERTEX) {
  1825. if (p_surface.format & ARRAY_FLAG_USE_2D_VERTICES) {
  1826. vertex_size = sizeof(float) * 2;
  1827. } else {
  1828. vertex_size = sizeof(float) * 3;
  1829. }
  1830. }
  1831. if (p_surface.format & ARRAY_FORMAT_NORMAL) {
  1832. normal_size += sizeof(uint16_t) * 2;
  1833. }
  1834. if (p_surface.format & ARRAY_FORMAT_TANGENT) {
  1835. tangent_size = sizeof(uint16_t) * 2;
  1836. }
  1837. int stride = p_surface.vertex_data.size() / p_surface.vertex_count;
  1838. int position_stride = vertex_size;
  1839. int normal_tangent_stride = normal_size + tangent_size;
  1840. p_surface.vertex_data = _convert_surface_version_1_to_surface_version_2(p_surface.format, p_surface.vertex_data, p_surface.vertex_count, stride, vertex_size, normal_size, position_stride, normal_tangent_stride);
  1841. if (p_surface.blend_shape_data.size() > 0) {
  1842. // The size of one blend shape.
  1843. int divisor = (vertex_size + normal_size + tangent_size) * p_surface.vertex_count;
  1844. ERR_FAIL_COND((p_surface.blend_shape_data.size() % divisor) != 0);
  1845. uint32_t blend_shape_count = p_surface.blend_shape_data.size() / divisor;
  1846. Vector<uint8_t> new_blend_shape_data;
  1847. for (uint32_t i = 0; i < blend_shape_count; i++) {
  1848. Vector<uint8_t> bs_data = p_surface.blend_shape_data.slice(i * divisor, (i + 1) * divisor);
  1849. Vector<uint8_t> blend_shape = _convert_surface_version_1_to_surface_version_2(p_surface.format, bs_data, p_surface.vertex_count, stride, vertex_size, normal_size, position_stride, normal_tangent_stride);
  1850. new_blend_shape_data.append_array(blend_shape);
  1851. }
  1852. ERR_FAIL_COND(p_surface.blend_shape_data.size() != new_blend_shape_data.size());
  1853. p_surface.blend_shape_data = new_blend_shape_data;
  1854. }
  1855. }
  1856. }
  1857. p_surface.format &= ~(ARRAY_FLAG_FORMAT_VERSION_MASK << ARRAY_FLAG_FORMAT_VERSION_SHIFT);
  1858. p_surface.format |= ARRAY_FLAG_FORMAT_CURRENT_VERSION & (ARRAY_FLAG_FORMAT_VERSION_MASK << ARRAY_FLAG_FORMAT_VERSION_SHIFT);
  1859. }
  1860. #endif
  1861. #ifdef TOOLS_ENABLED
  1862. void RenderingServer::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
  1863. const String pf = p_function;
  1864. if (p_idx == 0) {
  1865. if (pf == "global_shader_parameter_set" || pf == "global_shader_parameter_set_override" ||
  1866. pf == "global_shader_parameter_get" || pf == "global_shader_parameter_get_type" || pf == "global_shader_parameter_remove") {
  1867. for (const StringName &E : global_shader_parameter_get_list()) {
  1868. r_options->push_back(E.operator String().quote());
  1869. }
  1870. } else if (pf == "has_os_feature") {
  1871. for (const String E : { "\"rgtc\"", "\"s3tc\"", "\"bptc\"", "\"etc\"", "\"etc2\"", "\"astc\"" }) {
  1872. r_options->push_back(E);
  1873. }
  1874. }
  1875. }
  1876. Object::get_argument_options(p_function, p_idx, r_options);
  1877. }
  1878. #endif
  1879. void RenderingServer::_bind_methods() {
  1880. BIND_CONSTANT(NO_INDEX_ARRAY);
  1881. BIND_CONSTANT(ARRAY_WEIGHTS_SIZE);
  1882. BIND_CONSTANT(CANVAS_ITEM_Z_MIN);
  1883. BIND_CONSTANT(CANVAS_ITEM_Z_MAX);
  1884. BIND_CONSTANT(MAX_GLOW_LEVELS);
  1885. BIND_CONSTANT(MAX_CURSORS);
  1886. BIND_CONSTANT(MAX_2D_DIRECTIONAL_LIGHTS);
  1887. /* TEXTURE */
  1888. ClassDB::bind_method(D_METHOD("texture_2d_create", "image"), &RenderingServer::texture_2d_create);
  1889. ClassDB::bind_method(D_METHOD("texture_2d_layered_create", "layers", "layered_type"), &RenderingServer::_texture_2d_layered_create);
  1890. ClassDB::bind_method(D_METHOD("texture_3d_create", "format", "width", "height", "depth", "mipmaps", "data"), &RenderingServer::_texture_3d_create);
  1891. ClassDB::bind_method(D_METHOD("texture_proxy_create", "base"), &RenderingServer::texture_proxy_create);
  1892. ClassDB::bind_method(D_METHOD("texture_2d_update", "texture", "image", "layer"), &RenderingServer::texture_2d_update);
  1893. ClassDB::bind_method(D_METHOD("texture_3d_update", "texture", "data"), &RenderingServer::_texture_3d_update);
  1894. ClassDB::bind_method(D_METHOD("texture_proxy_update", "texture", "proxy_to"), &RenderingServer::texture_proxy_update);
  1895. ClassDB::bind_method(D_METHOD("texture_2d_placeholder_create"), &RenderingServer::texture_2d_placeholder_create);
  1896. ClassDB::bind_method(D_METHOD("texture_2d_layered_placeholder_create", "layered_type"), &RenderingServer::texture_2d_layered_placeholder_create);
  1897. ClassDB::bind_method(D_METHOD("texture_3d_placeholder_create"), &RenderingServer::texture_3d_placeholder_create);
  1898. ClassDB::bind_method(D_METHOD("texture_2d_get", "texture"), &RenderingServer::texture_2d_get);
  1899. ClassDB::bind_method(D_METHOD("texture_2d_layer_get", "texture", "layer"), &RenderingServer::texture_2d_layer_get);
  1900. ClassDB::bind_method(D_METHOD("texture_3d_get", "texture"), &RenderingServer::_texture_3d_get);
  1901. ClassDB::bind_method(D_METHOD("texture_replace", "texture", "by_texture"), &RenderingServer::texture_replace);
  1902. ClassDB::bind_method(D_METHOD("texture_set_size_override", "texture", "width", "height"), &RenderingServer::texture_set_size_override);
  1903. ClassDB::bind_method(D_METHOD("texture_set_path", "texture", "path"), &RenderingServer::texture_set_path);
  1904. ClassDB::bind_method(D_METHOD("texture_get_path", "texture"), &RenderingServer::texture_get_path);
  1905. ClassDB::bind_method(D_METHOD("texture_get_format", "texture"), &RenderingServer::texture_get_format);
  1906. ClassDB::bind_method(D_METHOD("texture_set_force_redraw_if_visible", "texture", "enable"), &RenderingServer::texture_set_force_redraw_if_visible);
  1907. ClassDB::bind_method(D_METHOD("texture_rd_create", "rd_texture", "layer_type"), &RenderingServer::texture_rd_create, DEFVAL(RenderingServer::TEXTURE_LAYERED_2D_ARRAY));
  1908. ClassDB::bind_method(D_METHOD("texture_get_rd_texture", "texture", "srgb"), &RenderingServer::texture_get_rd_texture, DEFVAL(false));
  1909. ClassDB::bind_method(D_METHOD("texture_get_native_handle", "texture", "srgb"), &RenderingServer::texture_get_native_handle, DEFVAL(false));
  1910. BIND_ENUM_CONSTANT(TEXTURE_LAYERED_2D_ARRAY);
  1911. BIND_ENUM_CONSTANT(TEXTURE_LAYERED_CUBEMAP);
  1912. BIND_ENUM_CONSTANT(TEXTURE_LAYERED_CUBEMAP_ARRAY);
  1913. BIND_ENUM_CONSTANT(CUBEMAP_LAYER_LEFT);
  1914. BIND_ENUM_CONSTANT(CUBEMAP_LAYER_RIGHT);
  1915. BIND_ENUM_CONSTANT(CUBEMAP_LAYER_BOTTOM);
  1916. BIND_ENUM_CONSTANT(CUBEMAP_LAYER_TOP);
  1917. BIND_ENUM_CONSTANT(CUBEMAP_LAYER_FRONT);
  1918. BIND_ENUM_CONSTANT(CUBEMAP_LAYER_BACK);
  1919. /* SHADER */
  1920. ClassDB::bind_method(D_METHOD("shader_create"), &RenderingServer::shader_create);
  1921. ClassDB::bind_method(D_METHOD("shader_set_code", "shader", "code"), &RenderingServer::shader_set_code);
  1922. ClassDB::bind_method(D_METHOD("shader_set_path_hint", "shader", "path"), &RenderingServer::shader_set_path_hint);
  1923. ClassDB::bind_method(D_METHOD("shader_get_code", "shader"), &RenderingServer::shader_get_code);
  1924. ClassDB::bind_method(D_METHOD("get_shader_parameter_list", "shader"), &RenderingServer::_shader_get_shader_parameter_list);
  1925. ClassDB::bind_method(D_METHOD("shader_get_parameter_default", "shader", "name"), &RenderingServer::shader_get_parameter_default);
  1926. ClassDB::bind_method(D_METHOD("shader_set_default_texture_parameter", "shader", "name", "texture", "index"), &RenderingServer::shader_set_default_texture_parameter, DEFVAL(0));
  1927. ClassDB::bind_method(D_METHOD("shader_get_default_texture_parameter", "shader", "name", "index"), &RenderingServer::shader_get_default_texture_parameter, DEFVAL(0));
  1928. BIND_ENUM_CONSTANT(SHADER_SPATIAL);
  1929. BIND_ENUM_CONSTANT(SHADER_CANVAS_ITEM);
  1930. BIND_ENUM_CONSTANT(SHADER_PARTICLES);
  1931. BIND_ENUM_CONSTANT(SHADER_SKY);
  1932. BIND_ENUM_CONSTANT(SHADER_FOG);
  1933. BIND_ENUM_CONSTANT(SHADER_MAX);
  1934. /* MATERIAL */
  1935. ClassDB::bind_method(D_METHOD("material_create"), &RenderingServer::material_create);
  1936. ClassDB::bind_method(D_METHOD("material_set_shader", "shader_material", "shader"), &RenderingServer::material_set_shader);
  1937. ClassDB::bind_method(D_METHOD("material_set_param", "material", "parameter", "value"), &RenderingServer::material_set_param);
  1938. ClassDB::bind_method(D_METHOD("material_get_param", "material", "parameter"), &RenderingServer::material_get_param);
  1939. ClassDB::bind_method(D_METHOD("material_set_render_priority", "material", "priority"), &RenderingServer::material_set_render_priority);
  1940. ClassDB::bind_method(D_METHOD("material_set_next_pass", "material", "next_material"), &RenderingServer::material_set_next_pass);
  1941. BIND_CONSTANT(MATERIAL_RENDER_PRIORITY_MIN);
  1942. BIND_CONSTANT(MATERIAL_RENDER_PRIORITY_MAX);
  1943. /* MESH API */
  1944. ClassDB::bind_method(D_METHOD("mesh_create_from_surfaces", "surfaces", "blend_shape_count"), &RenderingServer::_mesh_create_from_surfaces, DEFVAL(0));
  1945. ClassDB::bind_method(D_METHOD("mesh_create"), &RenderingServer::mesh_create);
  1946. ClassDB::bind_method(D_METHOD("mesh_surface_get_format_offset", "format", "vertex_count", "array_index"), &RenderingServer::mesh_surface_get_format_offset);
  1947. ClassDB::bind_method(D_METHOD("mesh_surface_get_format_vertex_stride", "format", "vertex_count"), &RenderingServer::mesh_surface_get_format_vertex_stride);
  1948. ClassDB::bind_method(D_METHOD("mesh_surface_get_format_normal_tangent_stride", "format", "vertex_count"), &RenderingServer::mesh_surface_get_format_normal_tangent_stride);
  1949. ClassDB::bind_method(D_METHOD("mesh_surface_get_format_attribute_stride", "format", "vertex_count"), &RenderingServer::mesh_surface_get_format_attribute_stride);
  1950. ClassDB::bind_method(D_METHOD("mesh_surface_get_format_skin_stride", "format", "vertex_count"), &RenderingServer::mesh_surface_get_format_skin_stride);
  1951. ClassDB::bind_method(D_METHOD("mesh_add_surface", "mesh", "surface"), &RenderingServer::_mesh_add_surface);
  1952. ClassDB::bind_method(D_METHOD("mesh_add_surface_from_arrays", "mesh", "primitive", "arrays", "blend_shapes", "lods", "compress_format"), &RenderingServer::mesh_add_surface_from_arrays, DEFVAL(Array()), DEFVAL(Dictionary()), DEFVAL(0));
  1953. ClassDB::bind_method(D_METHOD("mesh_get_blend_shape_count", "mesh"), &RenderingServer::mesh_get_blend_shape_count);
  1954. ClassDB::bind_method(D_METHOD("mesh_set_blend_shape_mode", "mesh", "mode"), &RenderingServer::mesh_set_blend_shape_mode);
  1955. ClassDB::bind_method(D_METHOD("mesh_get_blend_shape_mode", "mesh"), &RenderingServer::mesh_get_blend_shape_mode);
  1956. ClassDB::bind_method(D_METHOD("mesh_surface_set_material", "mesh", "surface", "material"), &RenderingServer::mesh_surface_set_material);
  1957. ClassDB::bind_method(D_METHOD("mesh_surface_get_material", "mesh", "surface"), &RenderingServer::mesh_surface_get_material);
  1958. ClassDB::bind_method(D_METHOD("mesh_get_surface", "mesh", "surface"), &RenderingServer::_mesh_get_surface);
  1959. ClassDB::bind_method(D_METHOD("mesh_surface_get_arrays", "mesh", "surface"), &RenderingServer::mesh_surface_get_arrays);
  1960. ClassDB::bind_method(D_METHOD("mesh_surface_get_blend_shape_arrays", "mesh", "surface"), &RenderingServer::mesh_surface_get_blend_shape_arrays);
  1961. ClassDB::bind_method(D_METHOD("mesh_get_surface_count", "mesh"), &RenderingServer::mesh_get_surface_count);
  1962. ClassDB::bind_method(D_METHOD("mesh_set_custom_aabb", "mesh", "aabb"), &RenderingServer::mesh_set_custom_aabb);
  1963. ClassDB::bind_method(D_METHOD("mesh_get_custom_aabb", "mesh"), &RenderingServer::mesh_get_custom_aabb);
  1964. ClassDB::bind_method(D_METHOD("mesh_clear", "mesh"), &RenderingServer::mesh_clear);
  1965. ClassDB::bind_method(D_METHOD("mesh_surface_update_vertex_region", "mesh", "surface", "offset", "data"), &RenderingServer::mesh_surface_update_vertex_region);
  1966. ClassDB::bind_method(D_METHOD("mesh_surface_update_attribute_region", "mesh", "surface", "offset", "data"), &RenderingServer::mesh_surface_update_attribute_region);
  1967. ClassDB::bind_method(D_METHOD("mesh_surface_update_skin_region", "mesh", "surface", "offset", "data"), &RenderingServer::mesh_surface_update_skin_region);
  1968. ClassDB::bind_method(D_METHOD("mesh_set_shadow_mesh", "mesh", "shadow_mesh"), &RenderingServer::mesh_set_shadow_mesh);
  1969. BIND_ENUM_CONSTANT(ARRAY_VERTEX);
  1970. BIND_ENUM_CONSTANT(ARRAY_NORMAL);
  1971. BIND_ENUM_CONSTANT(ARRAY_TANGENT);
  1972. BIND_ENUM_CONSTANT(ARRAY_COLOR);
  1973. BIND_ENUM_CONSTANT(ARRAY_TEX_UV);
  1974. BIND_ENUM_CONSTANT(ARRAY_TEX_UV2);
  1975. BIND_ENUM_CONSTANT(ARRAY_CUSTOM0);
  1976. BIND_ENUM_CONSTANT(ARRAY_CUSTOM1);
  1977. BIND_ENUM_CONSTANT(ARRAY_CUSTOM2);
  1978. BIND_ENUM_CONSTANT(ARRAY_CUSTOM3);
  1979. BIND_ENUM_CONSTANT(ARRAY_BONES);
  1980. BIND_ENUM_CONSTANT(ARRAY_WEIGHTS);
  1981. BIND_ENUM_CONSTANT(ARRAY_INDEX);
  1982. BIND_ENUM_CONSTANT(ARRAY_MAX);
  1983. BIND_CONSTANT(ARRAY_CUSTOM_COUNT);
  1984. BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RGBA8_UNORM);
  1985. BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RGBA8_SNORM);
  1986. BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RG_HALF);
  1987. BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RGBA_HALF);
  1988. BIND_ENUM_CONSTANT(ARRAY_CUSTOM_R_FLOAT);
  1989. BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RG_FLOAT);
  1990. BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RGB_FLOAT);
  1991. BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RGBA_FLOAT);
  1992. BIND_ENUM_CONSTANT(ARRAY_CUSTOM_MAX);
  1993. BIND_BITFIELD_FLAG(ARRAY_FORMAT_VERTEX);
  1994. BIND_BITFIELD_FLAG(ARRAY_FORMAT_NORMAL);
  1995. BIND_BITFIELD_FLAG(ARRAY_FORMAT_TANGENT);
  1996. BIND_BITFIELD_FLAG(ARRAY_FORMAT_COLOR);
  1997. BIND_BITFIELD_FLAG(ARRAY_FORMAT_TEX_UV);
  1998. BIND_BITFIELD_FLAG(ARRAY_FORMAT_TEX_UV2);
  1999. BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM0);
  2000. BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM1);
  2001. BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM2);
  2002. BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM3);
  2003. BIND_BITFIELD_FLAG(ARRAY_FORMAT_BONES);
  2004. BIND_BITFIELD_FLAG(ARRAY_FORMAT_WEIGHTS);
  2005. BIND_BITFIELD_FLAG(ARRAY_FORMAT_INDEX);
  2006. BIND_BITFIELD_FLAG(ARRAY_FORMAT_BLEND_SHAPE_MASK);
  2007. BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM_BASE);
  2008. BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM_BITS);
  2009. BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM0_SHIFT);
  2010. BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM1_SHIFT);
  2011. BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM2_SHIFT);
  2012. BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM3_SHIFT);
  2013. BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM_MASK);
  2014. BIND_BITFIELD_FLAG(ARRAY_COMPRESS_FLAGS_BASE);
  2015. BIND_BITFIELD_FLAG(ARRAY_FLAG_USE_2D_VERTICES);
  2016. BIND_BITFIELD_FLAG(ARRAY_FLAG_USE_DYNAMIC_UPDATE);
  2017. BIND_BITFIELD_FLAG(ARRAY_FLAG_USE_8_BONE_WEIGHTS);
  2018. BIND_BITFIELD_FLAG(ARRAY_FLAG_USES_EMPTY_VERTEX_ARRAY);
  2019. BIND_BITFIELD_FLAG(ARRAY_FLAG_COMPRESS_ATTRIBUTES);
  2020. BIND_BITFIELD_FLAG(ARRAY_FLAG_FORMAT_VERSION_BASE);
  2021. BIND_BITFIELD_FLAG(ARRAY_FLAG_FORMAT_VERSION_SHIFT);
  2022. BIND_BITFIELD_FLAG(ARRAY_FLAG_FORMAT_VERSION_1);
  2023. BIND_BITFIELD_FLAG(ARRAY_FLAG_FORMAT_VERSION_2);
  2024. BIND_BITFIELD_FLAG(ARRAY_FLAG_FORMAT_CURRENT_VERSION);
  2025. BIND_BITFIELD_FLAG(ARRAY_FLAG_FORMAT_VERSION_MASK);
  2026. BIND_ENUM_CONSTANT(PRIMITIVE_POINTS);
  2027. BIND_ENUM_CONSTANT(PRIMITIVE_LINES);
  2028. BIND_ENUM_CONSTANT(PRIMITIVE_LINE_STRIP);
  2029. BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLES);
  2030. BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLE_STRIP);
  2031. BIND_ENUM_CONSTANT(PRIMITIVE_MAX);
  2032. BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_NORMALIZED);
  2033. BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_RELATIVE);
  2034. /* MULTIMESH API */
  2035. ClassDB::bind_method(D_METHOD("multimesh_create"), &RenderingServer::multimesh_create);
  2036. ClassDB::bind_method(D_METHOD("multimesh_allocate_data", "multimesh", "instances", "transform_format", "color_format", "custom_data_format"), &RenderingServer::multimesh_allocate_data, DEFVAL(false), DEFVAL(false));
  2037. ClassDB::bind_method(D_METHOD("multimesh_get_instance_count", "multimesh"), &RenderingServer::multimesh_get_instance_count);
  2038. ClassDB::bind_method(D_METHOD("multimesh_set_mesh", "multimesh", "mesh"), &RenderingServer::multimesh_set_mesh);
  2039. ClassDB::bind_method(D_METHOD("multimesh_instance_set_transform", "multimesh", "index", "transform"), &RenderingServer::multimesh_instance_set_transform);
  2040. ClassDB::bind_method(D_METHOD("multimesh_instance_set_transform_2d", "multimesh", "index", "transform"), &RenderingServer::multimesh_instance_set_transform_2d);
  2041. ClassDB::bind_method(D_METHOD("multimesh_instance_set_color", "multimesh", "index", "color"), &RenderingServer::multimesh_instance_set_color);
  2042. ClassDB::bind_method(D_METHOD("multimesh_instance_set_custom_data", "multimesh", "index", "custom_data"), &RenderingServer::multimesh_instance_set_custom_data);
  2043. ClassDB::bind_method(D_METHOD("multimesh_get_mesh", "multimesh"), &RenderingServer::multimesh_get_mesh);
  2044. ClassDB::bind_method(D_METHOD("multimesh_get_aabb", "multimesh"), &RenderingServer::multimesh_get_aabb);
  2045. ClassDB::bind_method(D_METHOD("multimesh_set_custom_aabb", "multimesh", "aabb"), &RenderingServer::multimesh_set_custom_aabb);
  2046. ClassDB::bind_method(D_METHOD("multimesh_get_custom_aabb", "multimesh"), &RenderingServer::multimesh_get_custom_aabb);
  2047. ClassDB::bind_method(D_METHOD("multimesh_instance_get_transform", "multimesh", "index"), &RenderingServer::multimesh_instance_get_transform);
  2048. ClassDB::bind_method(D_METHOD("multimesh_instance_get_transform_2d", "multimesh", "index"), &RenderingServer::multimesh_instance_get_transform_2d);
  2049. ClassDB::bind_method(D_METHOD("multimesh_instance_get_color", "multimesh", "index"), &RenderingServer::multimesh_instance_get_color);
  2050. ClassDB::bind_method(D_METHOD("multimesh_instance_get_custom_data", "multimesh", "index"), &RenderingServer::multimesh_instance_get_custom_data);
  2051. ClassDB::bind_method(D_METHOD("multimesh_set_visible_instances", "multimesh", "visible"), &RenderingServer::multimesh_set_visible_instances);
  2052. ClassDB::bind_method(D_METHOD("multimesh_get_visible_instances", "multimesh"), &RenderingServer::multimesh_get_visible_instances);
  2053. ClassDB::bind_method(D_METHOD("multimesh_set_buffer", "multimesh", "buffer"), &RenderingServer::multimesh_set_buffer);
  2054. ClassDB::bind_method(D_METHOD("multimesh_get_buffer", "multimesh"), &RenderingServer::multimesh_get_buffer);
  2055. BIND_ENUM_CONSTANT(MULTIMESH_TRANSFORM_2D);
  2056. BIND_ENUM_CONSTANT(MULTIMESH_TRANSFORM_3D);
  2057. /* SKELETON API */
  2058. ClassDB::bind_method(D_METHOD("skeleton_create"), &RenderingServer::skeleton_create);
  2059. ClassDB::bind_method(D_METHOD("skeleton_allocate_data", "skeleton", "bones", "is_2d_skeleton"), &RenderingServer::skeleton_allocate_data, DEFVAL(false));
  2060. ClassDB::bind_method(D_METHOD("skeleton_get_bone_count", "skeleton"), &RenderingServer::skeleton_get_bone_count);
  2061. ClassDB::bind_method(D_METHOD("skeleton_bone_set_transform", "skeleton", "bone", "transform"), &RenderingServer::skeleton_bone_set_transform);
  2062. ClassDB::bind_method(D_METHOD("skeleton_bone_get_transform", "skeleton", "bone"), &RenderingServer::skeleton_bone_get_transform);
  2063. ClassDB::bind_method(D_METHOD("skeleton_bone_set_transform_2d", "skeleton", "bone", "transform"), &RenderingServer::skeleton_bone_set_transform_2d);
  2064. ClassDB::bind_method(D_METHOD("skeleton_bone_get_transform_2d", "skeleton", "bone"), &RenderingServer::skeleton_bone_get_transform_2d);
  2065. ClassDB::bind_method(D_METHOD("skeleton_set_base_transform_2d", "skeleton", "base_transform"), &RenderingServer::skeleton_set_base_transform_2d);
  2066. /* Light API */
  2067. ClassDB::bind_method(D_METHOD("directional_light_create"), &RenderingServer::directional_light_create);
  2068. ClassDB::bind_method(D_METHOD("omni_light_create"), &RenderingServer::omni_light_create);
  2069. ClassDB::bind_method(D_METHOD("spot_light_create"), &RenderingServer::spot_light_create);
  2070. ClassDB::bind_method(D_METHOD("light_set_color", "light", "color"), &RenderingServer::light_set_color);
  2071. ClassDB::bind_method(D_METHOD("light_set_param", "light", "param", "value"), &RenderingServer::light_set_param);
  2072. ClassDB::bind_method(D_METHOD("light_set_shadow", "light", "enabled"), &RenderingServer::light_set_shadow);
  2073. ClassDB::bind_method(D_METHOD("light_set_projector", "light", "texture"), &RenderingServer::light_set_projector);
  2074. ClassDB::bind_method(D_METHOD("light_set_negative", "light", "enable"), &RenderingServer::light_set_negative);
  2075. ClassDB::bind_method(D_METHOD("light_set_cull_mask", "light", "mask"), &RenderingServer::light_set_cull_mask);
  2076. ClassDB::bind_method(D_METHOD("light_set_distance_fade", "decal", "enabled", "begin", "shadow", "length"), &RenderingServer::light_set_distance_fade);
  2077. ClassDB::bind_method(D_METHOD("light_set_reverse_cull_face_mode", "light", "enabled"), &RenderingServer::light_set_reverse_cull_face_mode);
  2078. ClassDB::bind_method(D_METHOD("light_set_bake_mode", "light", "bake_mode"), &RenderingServer::light_set_bake_mode);
  2079. ClassDB::bind_method(D_METHOD("light_set_max_sdfgi_cascade", "light", "cascade"), &RenderingServer::light_set_max_sdfgi_cascade);
  2080. ClassDB::bind_method(D_METHOD("light_omni_set_shadow_mode", "light", "mode"), &RenderingServer::light_omni_set_shadow_mode);
  2081. ClassDB::bind_method(D_METHOD("light_directional_set_shadow_mode", "light", "mode"), &RenderingServer::light_directional_set_shadow_mode);
  2082. ClassDB::bind_method(D_METHOD("light_directional_set_blend_splits", "light", "enable"), &RenderingServer::light_directional_set_blend_splits);
  2083. ClassDB::bind_method(D_METHOD("light_directional_set_sky_mode", "light", "mode"), &RenderingServer::light_directional_set_sky_mode);
  2084. ClassDB::bind_method(D_METHOD("light_projectors_set_filter", "filter"), &RenderingServer::light_projectors_set_filter);
  2085. BIND_ENUM_CONSTANT(LIGHT_PROJECTOR_FILTER_NEAREST);
  2086. BIND_ENUM_CONSTANT(LIGHT_PROJECTOR_FILTER_LINEAR);
  2087. BIND_ENUM_CONSTANT(LIGHT_PROJECTOR_FILTER_NEAREST_MIPMAPS);
  2088. BIND_ENUM_CONSTANT(LIGHT_PROJECTOR_FILTER_LINEAR_MIPMAPS);
  2089. BIND_ENUM_CONSTANT(LIGHT_PROJECTOR_FILTER_NEAREST_MIPMAPS_ANISOTROPIC);
  2090. BIND_ENUM_CONSTANT(LIGHT_PROJECTOR_FILTER_LINEAR_MIPMAPS_ANISOTROPIC);
  2091. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL);
  2092. BIND_ENUM_CONSTANT(LIGHT_OMNI);
  2093. BIND_ENUM_CONSTANT(LIGHT_SPOT);
  2094. BIND_ENUM_CONSTANT(LIGHT_PARAM_ENERGY);
  2095. BIND_ENUM_CONSTANT(LIGHT_PARAM_INDIRECT_ENERGY);
  2096. BIND_ENUM_CONSTANT(LIGHT_PARAM_VOLUMETRIC_FOG_ENERGY);
  2097. BIND_ENUM_CONSTANT(LIGHT_PARAM_SPECULAR);
  2098. BIND_ENUM_CONSTANT(LIGHT_PARAM_RANGE);
  2099. BIND_ENUM_CONSTANT(LIGHT_PARAM_SIZE);
  2100. BIND_ENUM_CONSTANT(LIGHT_PARAM_ATTENUATION);
  2101. BIND_ENUM_CONSTANT(LIGHT_PARAM_SPOT_ANGLE);
  2102. BIND_ENUM_CONSTANT(LIGHT_PARAM_SPOT_ATTENUATION);
  2103. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_MAX_DISTANCE);
  2104. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET);
  2105. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET);
  2106. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET);
  2107. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_FADE_START);
  2108. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_NORMAL_BIAS);
  2109. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_BIAS);
  2110. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_PANCAKE_SIZE);
  2111. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_OPACITY);
  2112. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_BLUR);
  2113. BIND_ENUM_CONSTANT(LIGHT_PARAM_TRANSMITTANCE_BIAS);
  2114. BIND_ENUM_CONSTANT(LIGHT_PARAM_INTENSITY);
  2115. BIND_ENUM_CONSTANT(LIGHT_PARAM_MAX);
  2116. BIND_ENUM_CONSTANT(LIGHT_BAKE_DISABLED);
  2117. BIND_ENUM_CONSTANT(LIGHT_BAKE_STATIC);
  2118. BIND_ENUM_CONSTANT(LIGHT_BAKE_DYNAMIC);
  2119. BIND_ENUM_CONSTANT(LIGHT_OMNI_SHADOW_DUAL_PARABOLOID);
  2120. BIND_ENUM_CONSTANT(LIGHT_OMNI_SHADOW_CUBE);
  2121. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL);
  2122. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS);
  2123. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS);
  2124. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SKY_MODE_LIGHT_AND_SKY);
  2125. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SKY_MODE_LIGHT_ONLY);
  2126. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SKY_MODE_SKY_ONLY);
  2127. ClassDB::bind_method(D_METHOD("positional_soft_shadow_filter_set_quality", "quality"), &RenderingServer::positional_soft_shadow_filter_set_quality);
  2128. ClassDB::bind_method(D_METHOD("directional_soft_shadow_filter_set_quality", "quality"), &RenderingServer::directional_soft_shadow_filter_set_quality);
  2129. ClassDB::bind_method(D_METHOD("directional_shadow_atlas_set_size", "size", "is_16bits"), &RenderingServer::directional_shadow_atlas_set_size);
  2130. BIND_ENUM_CONSTANT(SHADOW_QUALITY_HARD);
  2131. BIND_ENUM_CONSTANT(SHADOW_QUALITY_SOFT_VERY_LOW);
  2132. BIND_ENUM_CONSTANT(SHADOW_QUALITY_SOFT_LOW);
  2133. BIND_ENUM_CONSTANT(SHADOW_QUALITY_SOFT_MEDIUM);
  2134. BIND_ENUM_CONSTANT(SHADOW_QUALITY_SOFT_HIGH);
  2135. BIND_ENUM_CONSTANT(SHADOW_QUALITY_SOFT_ULTRA);
  2136. BIND_ENUM_CONSTANT(SHADOW_QUALITY_MAX);
  2137. /* REFLECTION PROBE */
  2138. ClassDB::bind_method(D_METHOD("reflection_probe_create"), &RenderingServer::reflection_probe_create);
  2139. ClassDB::bind_method(D_METHOD("reflection_probe_set_update_mode", "probe", "mode"), &RenderingServer::reflection_probe_set_update_mode);
  2140. ClassDB::bind_method(D_METHOD("reflection_probe_set_intensity", "probe", "intensity"), &RenderingServer::reflection_probe_set_intensity);
  2141. ClassDB::bind_method(D_METHOD("reflection_probe_set_ambient_mode", "probe", "mode"), &RenderingServer::reflection_probe_set_ambient_mode);
  2142. ClassDB::bind_method(D_METHOD("reflection_probe_set_ambient_color", "probe", "color"), &RenderingServer::reflection_probe_set_ambient_color);
  2143. ClassDB::bind_method(D_METHOD("reflection_probe_set_ambient_energy", "probe", "energy"), &RenderingServer::reflection_probe_set_ambient_energy);
  2144. ClassDB::bind_method(D_METHOD("reflection_probe_set_max_distance", "probe", "distance"), &RenderingServer::reflection_probe_set_max_distance);
  2145. ClassDB::bind_method(D_METHOD("reflection_probe_set_size", "probe", "size"), &RenderingServer::reflection_probe_set_size);
  2146. ClassDB::bind_method(D_METHOD("reflection_probe_set_origin_offset", "probe", "offset"), &RenderingServer::reflection_probe_set_origin_offset);
  2147. ClassDB::bind_method(D_METHOD("reflection_probe_set_as_interior", "probe", "enable"), &RenderingServer::reflection_probe_set_as_interior);
  2148. ClassDB::bind_method(D_METHOD("reflection_probe_set_enable_box_projection", "probe", "enable"), &RenderingServer::reflection_probe_set_enable_box_projection);
  2149. ClassDB::bind_method(D_METHOD("reflection_probe_set_enable_shadows", "probe", "enable"), &RenderingServer::reflection_probe_set_enable_shadows);
  2150. ClassDB::bind_method(D_METHOD("reflection_probe_set_cull_mask", "probe", "layers"), &RenderingServer::reflection_probe_set_cull_mask);
  2151. ClassDB::bind_method(D_METHOD("reflection_probe_set_reflection_mask", "probe", "layers"), &RenderingServer::reflection_probe_set_reflection_mask);
  2152. ClassDB::bind_method(D_METHOD("reflection_probe_set_resolution", "probe", "resolution"), &RenderingServer::reflection_probe_set_resolution);
  2153. ClassDB::bind_method(D_METHOD("reflection_probe_set_mesh_lod_threshold", "probe", "pixels"), &RenderingServer::reflection_probe_set_mesh_lod_threshold);
  2154. BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ONCE);
  2155. BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ALWAYS);
  2156. BIND_ENUM_CONSTANT(REFLECTION_PROBE_AMBIENT_DISABLED);
  2157. BIND_ENUM_CONSTANT(REFLECTION_PROBE_AMBIENT_ENVIRONMENT);
  2158. BIND_ENUM_CONSTANT(REFLECTION_PROBE_AMBIENT_COLOR);
  2159. /* DECAL */
  2160. ClassDB::bind_method(D_METHOD("decal_create"), &RenderingServer::decal_create);
  2161. ClassDB::bind_method(D_METHOD("decal_set_size", "decal", "size"), &RenderingServer::decal_set_size);
  2162. ClassDB::bind_method(D_METHOD("decal_set_texture", "decal", "type", "texture"), &RenderingServer::decal_set_texture);
  2163. ClassDB::bind_method(D_METHOD("decal_set_emission_energy", "decal", "energy"), &RenderingServer::decal_set_emission_energy);
  2164. ClassDB::bind_method(D_METHOD("decal_set_albedo_mix", "decal", "albedo_mix"), &RenderingServer::decal_set_albedo_mix);
  2165. ClassDB::bind_method(D_METHOD("decal_set_modulate", "decal", "color"), &RenderingServer::decal_set_modulate);
  2166. ClassDB::bind_method(D_METHOD("decal_set_cull_mask", "decal", "mask"), &RenderingServer::decal_set_cull_mask);
  2167. ClassDB::bind_method(D_METHOD("decal_set_distance_fade", "decal", "enabled", "begin", "length"), &RenderingServer::decal_set_distance_fade);
  2168. ClassDB::bind_method(D_METHOD("decal_set_fade", "decal", "above", "below"), &RenderingServer::decal_set_fade);
  2169. ClassDB::bind_method(D_METHOD("decal_set_normal_fade", "decal", "fade"), &RenderingServer::decal_set_normal_fade);
  2170. ClassDB::bind_method(D_METHOD("decals_set_filter", "filter"), &RenderingServer::decals_set_filter);
  2171. BIND_ENUM_CONSTANT(DECAL_TEXTURE_ALBEDO);
  2172. BIND_ENUM_CONSTANT(DECAL_TEXTURE_NORMAL);
  2173. BIND_ENUM_CONSTANT(DECAL_TEXTURE_ORM);
  2174. BIND_ENUM_CONSTANT(DECAL_TEXTURE_EMISSION);
  2175. BIND_ENUM_CONSTANT(DECAL_TEXTURE_MAX);
  2176. BIND_ENUM_CONSTANT(DECAL_FILTER_NEAREST);
  2177. BIND_ENUM_CONSTANT(DECAL_FILTER_LINEAR);
  2178. BIND_ENUM_CONSTANT(DECAL_FILTER_NEAREST_MIPMAPS);
  2179. BIND_ENUM_CONSTANT(DECAL_FILTER_LINEAR_MIPMAPS);
  2180. BIND_ENUM_CONSTANT(DECAL_FILTER_NEAREST_MIPMAPS_ANISOTROPIC);
  2181. BIND_ENUM_CONSTANT(DECAL_FILTER_LINEAR_MIPMAPS_ANISOTROPIC);
  2182. /* GI API (affects VoxelGI and SDFGI) */
  2183. ClassDB::bind_method(D_METHOD("gi_set_use_half_resolution", "half_resolution"), &RenderingServer::gi_set_use_half_resolution);
  2184. /* VOXEL GI API */
  2185. ClassDB::bind_method(D_METHOD("voxel_gi_create"), &RenderingServer::voxel_gi_create);
  2186. ClassDB::bind_method(D_METHOD("voxel_gi_allocate_data", "voxel_gi", "to_cell_xform", "aabb", "octree_size", "octree_cells", "data_cells", "distance_field", "level_counts"), &RenderingServer::voxel_gi_allocate_data);
  2187. ClassDB::bind_method(D_METHOD("voxel_gi_get_octree_size", "voxel_gi"), &RenderingServer::voxel_gi_get_octree_size);
  2188. ClassDB::bind_method(D_METHOD("voxel_gi_get_octree_cells", "voxel_gi"), &RenderingServer::voxel_gi_get_octree_cells);
  2189. ClassDB::bind_method(D_METHOD("voxel_gi_get_data_cells", "voxel_gi"), &RenderingServer::voxel_gi_get_data_cells);
  2190. ClassDB::bind_method(D_METHOD("voxel_gi_get_distance_field", "voxel_gi"), &RenderingServer::voxel_gi_get_distance_field);
  2191. ClassDB::bind_method(D_METHOD("voxel_gi_get_level_counts", "voxel_gi"), &RenderingServer::voxel_gi_get_level_counts);
  2192. ClassDB::bind_method(D_METHOD("voxel_gi_get_to_cell_xform", "voxel_gi"), &RenderingServer::voxel_gi_get_to_cell_xform);
  2193. ClassDB::bind_method(D_METHOD("voxel_gi_set_dynamic_range", "voxel_gi", "range"), &RenderingServer::voxel_gi_set_dynamic_range);
  2194. ClassDB::bind_method(D_METHOD("voxel_gi_set_propagation", "voxel_gi", "amount"), &RenderingServer::voxel_gi_set_propagation);
  2195. ClassDB::bind_method(D_METHOD("voxel_gi_set_energy", "voxel_gi", "energy"), &RenderingServer::voxel_gi_set_energy);
  2196. ClassDB::bind_method(D_METHOD("voxel_gi_set_baked_exposure_normalization", "voxel_gi", "baked_exposure"), &RenderingServer::voxel_gi_set_baked_exposure_normalization);
  2197. ClassDB::bind_method(D_METHOD("voxel_gi_set_bias", "voxel_gi", "bias"), &RenderingServer::voxel_gi_set_bias);
  2198. ClassDB::bind_method(D_METHOD("voxel_gi_set_normal_bias", "voxel_gi", "bias"), &RenderingServer::voxel_gi_set_normal_bias);
  2199. ClassDB::bind_method(D_METHOD("voxel_gi_set_interior", "voxel_gi", "enable"), &RenderingServer::voxel_gi_set_interior);
  2200. ClassDB::bind_method(D_METHOD("voxel_gi_set_use_two_bounces", "voxel_gi", "enable"), &RenderingServer::voxel_gi_set_use_two_bounces);
  2201. ClassDB::bind_method(D_METHOD("voxel_gi_set_quality", "quality"), &RenderingServer::voxel_gi_set_quality);
  2202. BIND_ENUM_CONSTANT(VOXEL_GI_QUALITY_LOW);
  2203. BIND_ENUM_CONSTANT(VOXEL_GI_QUALITY_HIGH);
  2204. /* LIGHTMAP */
  2205. ClassDB::bind_method(D_METHOD("lightmap_create"), &RenderingServer::lightmap_create);
  2206. ClassDB::bind_method(D_METHOD("lightmap_set_textures", "lightmap", "light", "uses_sh"), &RenderingServer::lightmap_set_textures);
  2207. ClassDB::bind_method(D_METHOD("lightmap_set_probe_bounds", "lightmap", "bounds"), &RenderingServer::lightmap_set_probe_bounds);
  2208. ClassDB::bind_method(D_METHOD("lightmap_set_probe_interior", "lightmap", "interior"), &RenderingServer::lightmap_set_probe_interior);
  2209. ClassDB::bind_method(D_METHOD("lightmap_set_probe_capture_data", "lightmap", "points", "point_sh", "tetrahedra", "bsp_tree"), &RenderingServer::lightmap_set_probe_capture_data);
  2210. ClassDB::bind_method(D_METHOD("lightmap_get_probe_capture_points", "lightmap"), &RenderingServer::lightmap_get_probe_capture_points);
  2211. ClassDB::bind_method(D_METHOD("lightmap_get_probe_capture_sh", "lightmap"), &RenderingServer::lightmap_get_probe_capture_sh);
  2212. ClassDB::bind_method(D_METHOD("lightmap_get_probe_capture_tetrahedra", "lightmap"), &RenderingServer::lightmap_get_probe_capture_tetrahedra);
  2213. ClassDB::bind_method(D_METHOD("lightmap_get_probe_capture_bsp_tree", "lightmap"), &RenderingServer::lightmap_get_probe_capture_bsp_tree);
  2214. ClassDB::bind_method(D_METHOD("lightmap_set_baked_exposure_normalization", "lightmap", "baked_exposure"), &RenderingServer::lightmap_set_baked_exposure_normalization);
  2215. ClassDB::bind_method(D_METHOD("lightmap_set_probe_capture_update_speed", "speed"), &RenderingServer::lightmap_set_probe_capture_update_speed);
  2216. /* PARTICLES API */
  2217. ClassDB::bind_method(D_METHOD("particles_create"), &RenderingServer::particles_create);
  2218. ClassDB::bind_method(D_METHOD("particles_set_mode", "particles", "mode"), &RenderingServer::particles_set_mode);
  2219. ClassDB::bind_method(D_METHOD("particles_set_emitting", "particles", "emitting"), &RenderingServer::particles_set_emitting);
  2220. ClassDB::bind_method(D_METHOD("particles_get_emitting", "particles"), &RenderingServer::particles_get_emitting);
  2221. ClassDB::bind_method(D_METHOD("particles_set_amount", "particles", "amount"), &RenderingServer::particles_set_amount);
  2222. ClassDB::bind_method(D_METHOD("particles_set_amount_ratio", "particles", "ratio"), &RenderingServer::particles_set_amount_ratio);
  2223. ClassDB::bind_method(D_METHOD("particles_set_lifetime", "particles", "lifetime"), &RenderingServer::particles_set_lifetime);
  2224. ClassDB::bind_method(D_METHOD("particles_set_one_shot", "particles", "one_shot"), &RenderingServer::particles_set_one_shot);
  2225. ClassDB::bind_method(D_METHOD("particles_set_pre_process_time", "particles", "time"), &RenderingServer::particles_set_pre_process_time);
  2226. ClassDB::bind_method(D_METHOD("particles_set_explosiveness_ratio", "particles", "ratio"), &RenderingServer::particles_set_explosiveness_ratio);
  2227. ClassDB::bind_method(D_METHOD("particles_set_randomness_ratio", "particles", "ratio"), &RenderingServer::particles_set_randomness_ratio);
  2228. ClassDB::bind_method(D_METHOD("particles_set_interp_to_end", "particles", "factor"), &RenderingServer::particles_set_interp_to_end);
  2229. ClassDB::bind_method(D_METHOD("particles_set_emitter_velocity", "particles", "velocity"), &RenderingServer::particles_set_emitter_velocity);
  2230. ClassDB::bind_method(D_METHOD("particles_set_custom_aabb", "particles", "aabb"), &RenderingServer::particles_set_custom_aabb);
  2231. ClassDB::bind_method(D_METHOD("particles_set_speed_scale", "particles", "scale"), &RenderingServer::particles_set_speed_scale);
  2232. ClassDB::bind_method(D_METHOD("particles_set_use_local_coordinates", "particles", "enable"), &RenderingServer::particles_set_use_local_coordinates);
  2233. ClassDB::bind_method(D_METHOD("particles_set_process_material", "particles", "material"), &RenderingServer::particles_set_process_material);
  2234. ClassDB::bind_method(D_METHOD("particles_set_fixed_fps", "particles", "fps"), &RenderingServer::particles_set_fixed_fps);
  2235. ClassDB::bind_method(D_METHOD("particles_set_interpolate", "particles", "enable"), &RenderingServer::particles_set_interpolate);
  2236. ClassDB::bind_method(D_METHOD("particles_set_fractional_delta", "particles", "enable"), &RenderingServer::particles_set_fractional_delta);
  2237. ClassDB::bind_method(D_METHOD("particles_set_collision_base_size", "particles", "size"), &RenderingServer::particles_set_collision_base_size);
  2238. ClassDB::bind_method(D_METHOD("particles_set_transform_align", "particles", "align"), &RenderingServer::particles_set_transform_align);
  2239. ClassDB::bind_method(D_METHOD("particles_set_trails", "particles", "enable", "length_sec"), &RenderingServer::particles_set_trails);
  2240. ClassDB::bind_method(D_METHOD("particles_set_trail_bind_poses", "particles", "bind_poses"), &RenderingServer::_particles_set_trail_bind_poses);
  2241. ClassDB::bind_method(D_METHOD("particles_is_inactive", "particles"), &RenderingServer::particles_is_inactive);
  2242. ClassDB::bind_method(D_METHOD("particles_request_process", "particles"), &RenderingServer::particles_request_process);
  2243. ClassDB::bind_method(D_METHOD("particles_restart", "particles"), &RenderingServer::particles_restart);
  2244. ClassDB::bind_method(D_METHOD("particles_set_subemitter", "particles", "subemitter_particles"), &RenderingServer::particles_set_subemitter);
  2245. ClassDB::bind_method(D_METHOD("particles_emit", "particles", "transform", "velocity", "color", "custom", "emit_flags"), &RenderingServer::particles_emit);
  2246. ClassDB::bind_method(D_METHOD("particles_set_draw_order", "particles", "order"), &RenderingServer::particles_set_draw_order);
  2247. ClassDB::bind_method(D_METHOD("particles_set_draw_passes", "particles", "count"), &RenderingServer::particles_set_draw_passes);
  2248. ClassDB::bind_method(D_METHOD("particles_set_draw_pass_mesh", "particles", "pass", "mesh"), &RenderingServer::particles_set_draw_pass_mesh);
  2249. ClassDB::bind_method(D_METHOD("particles_get_current_aabb", "particles"), &RenderingServer::particles_get_current_aabb);
  2250. ClassDB::bind_method(D_METHOD("particles_set_emission_transform", "particles", "transform"), &RenderingServer::particles_set_emission_transform);
  2251. BIND_ENUM_CONSTANT(PARTICLES_MODE_2D);
  2252. BIND_ENUM_CONSTANT(PARTICLES_MODE_3D);
  2253. BIND_ENUM_CONSTANT(PARTICLES_TRANSFORM_ALIGN_DISABLED);
  2254. BIND_ENUM_CONSTANT(PARTICLES_TRANSFORM_ALIGN_Z_BILLBOARD);
  2255. BIND_ENUM_CONSTANT(PARTICLES_TRANSFORM_ALIGN_Y_TO_VELOCITY);
  2256. BIND_ENUM_CONSTANT(PARTICLES_TRANSFORM_ALIGN_Z_BILLBOARD_Y_TO_VELOCITY);
  2257. BIND_CONSTANT(PARTICLES_EMIT_FLAG_POSITION);
  2258. BIND_CONSTANT(PARTICLES_EMIT_FLAG_ROTATION_SCALE);
  2259. BIND_CONSTANT(PARTICLES_EMIT_FLAG_VELOCITY);
  2260. BIND_CONSTANT(PARTICLES_EMIT_FLAG_COLOR);
  2261. BIND_CONSTANT(PARTICLES_EMIT_FLAG_CUSTOM);
  2262. BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_INDEX);
  2263. BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_LIFETIME);
  2264. BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_REVERSE_LIFETIME);
  2265. BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_VIEW_DEPTH);
  2266. /* PARTICLES COLLISION */
  2267. ClassDB::bind_method(D_METHOD("particles_collision_create"), &RenderingServer::particles_collision_create);
  2268. ClassDB::bind_method(D_METHOD("particles_collision_set_collision_type", "particles_collision", "type"), &RenderingServer::particles_collision_set_collision_type);
  2269. ClassDB::bind_method(D_METHOD("particles_collision_set_cull_mask", "particles_collision", "mask"), &RenderingServer::particles_collision_set_cull_mask);
  2270. ClassDB::bind_method(D_METHOD("particles_collision_set_sphere_radius", "particles_collision", "radius"), &RenderingServer::particles_collision_set_sphere_radius);
  2271. ClassDB::bind_method(D_METHOD("particles_collision_set_box_extents", "particles_collision", "extents"), &RenderingServer::particles_collision_set_box_extents);
  2272. ClassDB::bind_method(D_METHOD("particles_collision_set_attractor_strength", "particles_collision", "strength"), &RenderingServer::particles_collision_set_attractor_strength);
  2273. ClassDB::bind_method(D_METHOD("particles_collision_set_attractor_directionality", "particles_collision", "amount"), &RenderingServer::particles_collision_set_attractor_directionality);
  2274. ClassDB::bind_method(D_METHOD("particles_collision_set_attractor_attenuation", "particles_collision", "curve"), &RenderingServer::particles_collision_set_attractor_attenuation);
  2275. ClassDB::bind_method(D_METHOD("particles_collision_set_field_texture", "particles_collision", "texture"), &RenderingServer::particles_collision_set_field_texture);
  2276. ClassDB::bind_method(D_METHOD("particles_collision_height_field_update", "particles_collision"), &RenderingServer::particles_collision_height_field_update);
  2277. ClassDB::bind_method(D_METHOD("particles_collision_set_height_field_resolution", "particles_collision", "resolution"), &RenderingServer::particles_collision_set_height_field_resolution);
  2278. BIND_ENUM_CONSTANT(PARTICLES_COLLISION_TYPE_SPHERE_ATTRACT);
  2279. BIND_ENUM_CONSTANT(PARTICLES_COLLISION_TYPE_BOX_ATTRACT);
  2280. BIND_ENUM_CONSTANT(PARTICLES_COLLISION_TYPE_VECTOR_FIELD_ATTRACT);
  2281. BIND_ENUM_CONSTANT(PARTICLES_COLLISION_TYPE_SPHERE_COLLIDE);
  2282. BIND_ENUM_CONSTANT(PARTICLES_COLLISION_TYPE_BOX_COLLIDE);
  2283. BIND_ENUM_CONSTANT(PARTICLES_COLLISION_TYPE_SDF_COLLIDE);
  2284. BIND_ENUM_CONSTANT(PARTICLES_COLLISION_TYPE_HEIGHTFIELD_COLLIDE);
  2285. BIND_ENUM_CONSTANT(PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_256);
  2286. BIND_ENUM_CONSTANT(PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_512);
  2287. BIND_ENUM_CONSTANT(PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_1024);
  2288. BIND_ENUM_CONSTANT(PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_2048);
  2289. BIND_ENUM_CONSTANT(PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_4096);
  2290. BIND_ENUM_CONSTANT(PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_8192);
  2291. BIND_ENUM_CONSTANT(PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_MAX);
  2292. /* FOG VOLUMES */
  2293. ClassDB::bind_method(D_METHOD("fog_volume_create"), &RenderingServer::fog_volume_create);
  2294. ClassDB::bind_method(D_METHOD("fog_volume_set_shape", "fog_volume", "shape"), &RenderingServer::fog_volume_set_shape);
  2295. ClassDB::bind_method(D_METHOD("fog_volume_set_size", "fog_volume", "size"), &RenderingServer::fog_volume_set_size);
  2296. ClassDB::bind_method(D_METHOD("fog_volume_set_material", "fog_volume", "material"), &RenderingServer::fog_volume_set_material);
  2297. BIND_ENUM_CONSTANT(FOG_VOLUME_SHAPE_ELLIPSOID);
  2298. BIND_ENUM_CONSTANT(FOG_VOLUME_SHAPE_CONE);
  2299. BIND_ENUM_CONSTANT(FOG_VOLUME_SHAPE_CYLINDER);
  2300. BIND_ENUM_CONSTANT(FOG_VOLUME_SHAPE_BOX);
  2301. BIND_ENUM_CONSTANT(FOG_VOLUME_SHAPE_WORLD);
  2302. BIND_ENUM_CONSTANT(FOG_VOLUME_SHAPE_MAX);
  2303. /* VISIBILITY NOTIFIER */
  2304. ClassDB::bind_method(D_METHOD("visibility_notifier_create"), &RenderingServer::visibility_notifier_create);
  2305. ClassDB::bind_method(D_METHOD("visibility_notifier_set_aabb", "notifier", "aabb"), &RenderingServer::visibility_notifier_set_aabb);
  2306. ClassDB::bind_method(D_METHOD("visibility_notifier_set_callbacks", "notifier", "enter_callable", "exit_callable"), &RenderingServer::visibility_notifier_set_callbacks);
  2307. /* OCCLUDER */
  2308. ClassDB::bind_method(D_METHOD("occluder_create"), &RenderingServer::occluder_create);
  2309. ClassDB::bind_method(D_METHOD("occluder_set_mesh", "occluder", "vertices", "indices"), &RenderingServer::occluder_set_mesh);
  2310. /* CAMERA */
  2311. ClassDB::bind_method(D_METHOD("camera_create"), &RenderingServer::camera_create);
  2312. ClassDB::bind_method(D_METHOD("camera_set_perspective", "camera", "fovy_degrees", "z_near", "z_far"), &RenderingServer::camera_set_perspective);
  2313. ClassDB::bind_method(D_METHOD("camera_set_orthogonal", "camera", "size", "z_near", "z_far"), &RenderingServer::camera_set_orthogonal);
  2314. ClassDB::bind_method(D_METHOD("camera_set_frustum", "camera", "size", "offset", "z_near", "z_far"), &RenderingServer::camera_set_frustum);
  2315. ClassDB::bind_method(D_METHOD("camera_set_transform", "camera", "transform"), &RenderingServer::camera_set_transform);
  2316. ClassDB::bind_method(D_METHOD("camera_set_cull_mask", "camera", "layers"), &RenderingServer::camera_set_cull_mask);
  2317. ClassDB::bind_method(D_METHOD("camera_set_environment", "camera", "env"), &RenderingServer::camera_set_environment);
  2318. ClassDB::bind_method(D_METHOD("camera_set_camera_attributes", "camera", "effects"), &RenderingServer::camera_set_camera_attributes);
  2319. ClassDB::bind_method(D_METHOD("camera_set_compositor", "camera", "compositor"), &RenderingServer::camera_set_compositor);
  2320. ClassDB::bind_method(D_METHOD("camera_set_use_vertical_aspect", "camera", "enable"), &RenderingServer::camera_set_use_vertical_aspect);
  2321. /* VIEWPORT */
  2322. ClassDB::bind_method(D_METHOD("viewport_create"), &RenderingServer::viewport_create);
  2323. ClassDB::bind_method(D_METHOD("viewport_set_use_xr", "viewport", "use_xr"), &RenderingServer::viewport_set_use_xr);
  2324. ClassDB::bind_method(D_METHOD("viewport_set_size", "viewport", "width", "height"), &RenderingServer::viewport_set_size);
  2325. ClassDB::bind_method(D_METHOD("viewport_set_active", "viewport", "active"), &RenderingServer::viewport_set_active);
  2326. ClassDB::bind_method(D_METHOD("viewport_set_parent_viewport", "viewport", "parent_viewport"), &RenderingServer::viewport_set_parent_viewport);
  2327. ClassDB::bind_method(D_METHOD("viewport_attach_to_screen", "viewport", "rect", "screen"), &RenderingServer::viewport_attach_to_screen, DEFVAL(Rect2()), DEFVAL(DisplayServer::MAIN_WINDOW_ID));
  2328. ClassDB::bind_method(D_METHOD("viewport_set_render_direct_to_screen", "viewport", "enabled"), &RenderingServer::viewport_set_render_direct_to_screen);
  2329. ClassDB::bind_method(D_METHOD("viewport_set_canvas_cull_mask", "viewport", "canvas_cull_mask"), &RenderingServer::viewport_set_canvas_cull_mask);
  2330. ClassDB::bind_method(D_METHOD("viewport_set_scaling_3d_mode", "viewport", "scaling_3d_mode"), &RenderingServer::viewport_set_scaling_3d_mode);
  2331. ClassDB::bind_method(D_METHOD("viewport_set_scaling_3d_scale", "viewport", "scale"), &RenderingServer::viewport_set_scaling_3d_scale);
  2332. ClassDB::bind_method(D_METHOD("viewport_set_fsr_sharpness", "viewport", "sharpness"), &RenderingServer::viewport_set_fsr_sharpness);
  2333. ClassDB::bind_method(D_METHOD("viewport_set_texture_mipmap_bias", "viewport", "mipmap_bias"), &RenderingServer::viewport_set_texture_mipmap_bias);
  2334. ClassDB::bind_method(D_METHOD("viewport_set_update_mode", "viewport", "update_mode"), &RenderingServer::viewport_set_update_mode);
  2335. ClassDB::bind_method(D_METHOD("viewport_set_clear_mode", "viewport", "clear_mode"), &RenderingServer::viewport_set_clear_mode);
  2336. ClassDB::bind_method(D_METHOD("viewport_get_render_target", "viewport"), &RenderingServer::viewport_get_render_target);
  2337. ClassDB::bind_method(D_METHOD("viewport_get_texture", "viewport"), &RenderingServer::viewport_get_texture);
  2338. ClassDB::bind_method(D_METHOD("viewport_set_disable_3d", "viewport", "disable"), &RenderingServer::viewport_set_disable_3d);
  2339. ClassDB::bind_method(D_METHOD("viewport_set_disable_2d", "viewport", "disable"), &RenderingServer::viewport_set_disable_2d);
  2340. ClassDB::bind_method(D_METHOD("viewport_set_environment_mode", "viewport", "mode"), &RenderingServer::viewport_set_environment_mode);
  2341. ClassDB::bind_method(D_METHOD("viewport_attach_camera", "viewport", "camera"), &RenderingServer::viewport_attach_camera);
  2342. ClassDB::bind_method(D_METHOD("viewport_set_scenario", "viewport", "scenario"), &RenderingServer::viewport_set_scenario);
  2343. ClassDB::bind_method(D_METHOD("viewport_attach_canvas", "viewport", "canvas"), &RenderingServer::viewport_attach_canvas);
  2344. ClassDB::bind_method(D_METHOD("viewport_remove_canvas", "viewport", "canvas"), &RenderingServer::viewport_remove_canvas);
  2345. ClassDB::bind_method(D_METHOD("viewport_set_snap_2d_transforms_to_pixel", "viewport", "enabled"), &RenderingServer::viewport_set_snap_2d_transforms_to_pixel);
  2346. ClassDB::bind_method(D_METHOD("viewport_set_snap_2d_vertices_to_pixel", "viewport", "enabled"), &RenderingServer::viewport_set_snap_2d_vertices_to_pixel);
  2347. ClassDB::bind_method(D_METHOD("viewport_set_default_canvas_item_texture_filter", "viewport", "filter"), &RenderingServer::viewport_set_default_canvas_item_texture_filter);
  2348. ClassDB::bind_method(D_METHOD("viewport_set_default_canvas_item_texture_repeat", "viewport", "repeat"), &RenderingServer::viewport_set_default_canvas_item_texture_repeat);
  2349. ClassDB::bind_method(D_METHOD("viewport_set_canvas_transform", "viewport", "canvas", "offset"), &RenderingServer::viewport_set_canvas_transform);
  2350. ClassDB::bind_method(D_METHOD("viewport_set_canvas_stacking", "viewport", "canvas", "layer", "sublayer"), &RenderingServer::viewport_set_canvas_stacking);
  2351. ClassDB::bind_method(D_METHOD("viewport_set_transparent_background", "viewport", "enabled"), &RenderingServer::viewport_set_transparent_background);
  2352. ClassDB::bind_method(D_METHOD("viewport_set_global_canvas_transform", "viewport", "transform"), &RenderingServer::viewport_set_global_canvas_transform);
  2353. ClassDB::bind_method(D_METHOD("viewport_set_sdf_oversize_and_scale", "viewport", "oversize", "scale"), &RenderingServer::viewport_set_sdf_oversize_and_scale);
  2354. ClassDB::bind_method(D_METHOD("viewport_set_positional_shadow_atlas_size", "viewport", "size", "use_16_bits"), &RenderingServer::viewport_set_positional_shadow_atlas_size, DEFVAL(false));
  2355. ClassDB::bind_method(D_METHOD("viewport_set_positional_shadow_atlas_quadrant_subdivision", "viewport", "quadrant", "subdivision"), &RenderingServer::viewport_set_positional_shadow_atlas_quadrant_subdivision);
  2356. ClassDB::bind_method(D_METHOD("viewport_set_msaa_3d", "viewport", "msaa"), &RenderingServer::viewport_set_msaa_3d);
  2357. ClassDB::bind_method(D_METHOD("viewport_set_msaa_2d", "viewport", "msaa"), &RenderingServer::viewport_set_msaa_2d);
  2358. ClassDB::bind_method(D_METHOD("viewport_set_use_hdr_2d", "viewport", "enabled"), &RenderingServer::viewport_set_use_hdr_2d);
  2359. ClassDB::bind_method(D_METHOD("viewport_set_screen_space_aa", "viewport", "mode"), &RenderingServer::viewport_set_screen_space_aa);
  2360. ClassDB::bind_method(D_METHOD("viewport_set_use_taa", "viewport", "enable"), &RenderingServer::viewport_set_use_taa);
  2361. ClassDB::bind_method(D_METHOD("viewport_set_use_debanding", "viewport", "enable"), &RenderingServer::viewport_set_use_debanding);
  2362. ClassDB::bind_method(D_METHOD("viewport_set_use_occlusion_culling", "viewport", "enable"), &RenderingServer::viewport_set_use_occlusion_culling);
  2363. ClassDB::bind_method(D_METHOD("viewport_set_occlusion_rays_per_thread", "rays_per_thread"), &RenderingServer::viewport_set_occlusion_rays_per_thread);
  2364. ClassDB::bind_method(D_METHOD("viewport_set_occlusion_culling_build_quality", "quality"), &RenderingServer::viewport_set_occlusion_culling_build_quality);
  2365. ClassDB::bind_method(D_METHOD("viewport_get_render_info", "viewport", "type", "info"), &RenderingServer::viewport_get_render_info);
  2366. ClassDB::bind_method(D_METHOD("viewport_set_debug_draw", "viewport", "draw"), &RenderingServer::viewport_set_debug_draw);
  2367. ClassDB::bind_method(D_METHOD("viewport_set_measure_render_time", "viewport", "enable"), &RenderingServer::viewport_set_measure_render_time);
  2368. ClassDB::bind_method(D_METHOD("viewport_get_measured_render_time_cpu", "viewport"), &RenderingServer::viewport_get_measured_render_time_cpu);
  2369. ClassDB::bind_method(D_METHOD("viewport_get_measured_render_time_gpu", "viewport"), &RenderingServer::viewport_get_measured_render_time_gpu);
  2370. ClassDB::bind_method(D_METHOD("viewport_set_vrs_mode", "viewport", "mode"), &RenderingServer::viewport_set_vrs_mode);
  2371. ClassDB::bind_method(D_METHOD("viewport_set_vrs_texture", "viewport", "texture"), &RenderingServer::viewport_set_vrs_texture);
  2372. BIND_ENUM_CONSTANT(VIEWPORT_SCALING_3D_MODE_BILINEAR);
  2373. BIND_ENUM_CONSTANT(VIEWPORT_SCALING_3D_MODE_FSR);
  2374. BIND_ENUM_CONSTANT(VIEWPORT_SCALING_3D_MODE_FSR2);
  2375. BIND_ENUM_CONSTANT(VIEWPORT_SCALING_3D_MODE_MAX);
  2376. BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_DISABLED);
  2377. BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_ONCE); // Then goes to disabled); must be manually updated.
  2378. BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_WHEN_VISIBLE); // Default
  2379. BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE);
  2380. BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_ALWAYS);
  2381. BIND_ENUM_CONSTANT(VIEWPORT_CLEAR_ALWAYS);
  2382. BIND_ENUM_CONSTANT(VIEWPORT_CLEAR_NEVER);
  2383. BIND_ENUM_CONSTANT(VIEWPORT_CLEAR_ONLY_NEXT_FRAME);
  2384. BIND_ENUM_CONSTANT(VIEWPORT_ENVIRONMENT_DISABLED);
  2385. BIND_ENUM_CONSTANT(VIEWPORT_ENVIRONMENT_ENABLED);
  2386. BIND_ENUM_CONSTANT(VIEWPORT_ENVIRONMENT_INHERIT);
  2387. BIND_ENUM_CONSTANT(VIEWPORT_ENVIRONMENT_MAX);
  2388. BIND_ENUM_CONSTANT(VIEWPORT_SDF_OVERSIZE_100_PERCENT);
  2389. BIND_ENUM_CONSTANT(VIEWPORT_SDF_OVERSIZE_120_PERCENT);
  2390. BIND_ENUM_CONSTANT(VIEWPORT_SDF_OVERSIZE_150_PERCENT);
  2391. BIND_ENUM_CONSTANT(VIEWPORT_SDF_OVERSIZE_200_PERCENT);
  2392. BIND_ENUM_CONSTANT(VIEWPORT_SDF_OVERSIZE_MAX);
  2393. BIND_ENUM_CONSTANT(VIEWPORT_SDF_SCALE_100_PERCENT);
  2394. BIND_ENUM_CONSTANT(VIEWPORT_SDF_SCALE_50_PERCENT);
  2395. BIND_ENUM_CONSTANT(VIEWPORT_SDF_SCALE_25_PERCENT);
  2396. BIND_ENUM_CONSTANT(VIEWPORT_SDF_SCALE_MAX);
  2397. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_DISABLED);
  2398. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_2X);
  2399. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_4X);
  2400. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_8X);
  2401. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_MAX);
  2402. BIND_ENUM_CONSTANT(VIEWPORT_SCREEN_SPACE_AA_DISABLED);
  2403. BIND_ENUM_CONSTANT(VIEWPORT_SCREEN_SPACE_AA_FXAA);
  2404. BIND_ENUM_CONSTANT(VIEWPORT_SCREEN_SPACE_AA_MAX);
  2405. BIND_ENUM_CONSTANT(VIEWPORT_OCCLUSION_BUILD_QUALITY_LOW);
  2406. BIND_ENUM_CONSTANT(VIEWPORT_OCCLUSION_BUILD_QUALITY_MEDIUM);
  2407. BIND_ENUM_CONSTANT(VIEWPORT_OCCLUSION_BUILD_QUALITY_HIGH);
  2408. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME);
  2409. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME);
  2410. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME);
  2411. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_MAX);
  2412. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_TYPE_VISIBLE);
  2413. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_TYPE_SHADOW);
  2414. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_TYPE_CANVAS);
  2415. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_TYPE_MAX);
  2416. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_DISABLED);
  2417. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_UNSHADED);
  2418. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_LIGHTING);
  2419. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_OVERDRAW);
  2420. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_WIREFRAME);
  2421. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_NORMAL_BUFFER);
  2422. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_VOXEL_GI_ALBEDO);
  2423. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_VOXEL_GI_LIGHTING);
  2424. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_VOXEL_GI_EMISSION);
  2425. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_SHADOW_ATLAS);
  2426. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_DIRECTIONAL_SHADOW_ATLAS);
  2427. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_SCENE_LUMINANCE);
  2428. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_SSAO);
  2429. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_SSIL);
  2430. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_PSSM_SPLITS);
  2431. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_DECAL_ATLAS);
  2432. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_SDFGI);
  2433. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_SDFGI_PROBES);
  2434. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_GI_BUFFER);
  2435. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_DISABLE_LOD);
  2436. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_CLUSTER_OMNI_LIGHTS);
  2437. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_CLUSTER_SPOT_LIGHTS);
  2438. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_CLUSTER_DECALS);
  2439. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_CLUSTER_REFLECTION_PROBES);
  2440. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_OCCLUDERS);
  2441. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_MOTION_VECTORS);
  2442. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_INTERNAL_BUFFER);
  2443. BIND_ENUM_CONSTANT(VIEWPORT_VRS_DISABLED);
  2444. BIND_ENUM_CONSTANT(VIEWPORT_VRS_TEXTURE);
  2445. BIND_ENUM_CONSTANT(VIEWPORT_VRS_XR);
  2446. BIND_ENUM_CONSTANT(VIEWPORT_VRS_MAX);
  2447. /* SKY API */
  2448. ClassDB::bind_method(D_METHOD("sky_create"), &RenderingServer::sky_create);
  2449. ClassDB::bind_method(D_METHOD("sky_set_radiance_size", "sky", "radiance_size"), &RenderingServer::sky_set_radiance_size);
  2450. ClassDB::bind_method(D_METHOD("sky_set_mode", "sky", "mode"), &RenderingServer::sky_set_mode);
  2451. ClassDB::bind_method(D_METHOD("sky_set_material", "sky", "material"), &RenderingServer::sky_set_material);
  2452. ClassDB::bind_method(D_METHOD("sky_bake_panorama", "sky", "energy", "bake_irradiance", "size"), &RenderingServer::sky_bake_panorama);
  2453. BIND_ENUM_CONSTANT(SKY_MODE_AUTOMATIC);
  2454. BIND_ENUM_CONSTANT(SKY_MODE_QUALITY);
  2455. BIND_ENUM_CONSTANT(SKY_MODE_INCREMENTAL);
  2456. BIND_ENUM_CONSTANT(SKY_MODE_REALTIME);
  2457. /* COMPOSITOR EFFECT API */
  2458. ClassDB::bind_method(D_METHOD("compositor_effect_create"), &RenderingServer::compositor_effect_create);
  2459. ClassDB::bind_method(D_METHOD("compositor_effect_set_enabled", "effect", "enabled"), &RenderingServer::compositor_effect_set_enabled);
  2460. ClassDB::bind_method(D_METHOD("compositor_effect_set_callback", "effect", "callback_type", "callback"), &RenderingServer::compositor_effect_set_callback);
  2461. ClassDB::bind_method(D_METHOD("compositor_effect_set_flag", "effect", "flag", "set"), &RenderingServer::compositor_effect_set_flag);
  2462. BIND_ENUM_CONSTANT(COMPOSITOR_EFFECT_FLAG_ACCESS_RESOLVED_COLOR);
  2463. BIND_ENUM_CONSTANT(COMPOSITOR_EFFECT_FLAG_ACCESS_RESOLVED_DEPTH);
  2464. BIND_ENUM_CONSTANT(COMPOSITOR_EFFECT_FLAG_NEEDS_MOTION_VECTORS);
  2465. BIND_ENUM_CONSTANT(COMPOSITOR_EFFECT_FLAG_NEEDS_ROUGHNESS);
  2466. BIND_ENUM_CONSTANT(COMPOSITOR_EFFECT_FLAG_NEEDS_SEPARATE_SPECULAR);
  2467. BIND_ENUM_CONSTANT(COMPOSITOR_EFFECT_CALLBACK_TYPE_PRE_OPAQUE);
  2468. BIND_ENUM_CONSTANT(COMPOSITOR_EFFECT_CALLBACK_TYPE_POST_OPAQUE);
  2469. BIND_ENUM_CONSTANT(COMPOSITOR_EFFECT_CALLBACK_TYPE_POST_SKY);
  2470. BIND_ENUM_CONSTANT(COMPOSITOR_EFFECT_CALLBACK_TYPE_PRE_TRANSPARENT);
  2471. BIND_ENUM_CONSTANT(COMPOSITOR_EFFECT_CALLBACK_TYPE_POST_TRANSPARENT);
  2472. BIND_ENUM_CONSTANT(COMPOSITOR_EFFECT_CALLBACK_TYPE_ANY);
  2473. /* COMPOSITOR */
  2474. ClassDB::bind_method(D_METHOD("compositor_create"), &RenderingServer::compositor_create);
  2475. ClassDB::bind_method(D_METHOD("compositor_set_compositor_effects", "compositor", "effects"), &RenderingServer::compositor_set_compositor_effects);
  2476. /* ENVIRONMENT */
  2477. ClassDB::bind_method(D_METHOD("environment_create"), &RenderingServer::environment_create);
  2478. ClassDB::bind_method(D_METHOD("environment_set_background", "env", "bg"), &RenderingServer::environment_set_background);
  2479. ClassDB::bind_method(D_METHOD("environment_set_sky", "env", "sky"), &RenderingServer::environment_set_sky);
  2480. ClassDB::bind_method(D_METHOD("environment_set_sky_custom_fov", "env", "scale"), &RenderingServer::environment_set_sky_custom_fov);
  2481. ClassDB::bind_method(D_METHOD("environment_set_sky_orientation", "env", "orientation"), &RenderingServer::environment_set_sky_orientation);
  2482. ClassDB::bind_method(D_METHOD("environment_set_bg_color", "env", "color"), &RenderingServer::environment_set_bg_color);
  2483. ClassDB::bind_method(D_METHOD("environment_set_bg_energy", "env", "multiplier", "exposure_value"), &RenderingServer::environment_set_bg_energy);
  2484. ClassDB::bind_method(D_METHOD("environment_set_canvas_max_layer", "env", "max_layer"), &RenderingServer::environment_set_canvas_max_layer);
  2485. ClassDB::bind_method(D_METHOD("environment_set_ambient_light", "env", "color", "ambient", "energy", "sky_contibution", "reflection_source"), &RenderingServer::environment_set_ambient_light, DEFVAL(RS::ENV_AMBIENT_SOURCE_BG), DEFVAL(1.0), DEFVAL(0.0), DEFVAL(RS::ENV_REFLECTION_SOURCE_BG));
  2486. ClassDB::bind_method(D_METHOD("environment_set_glow", "env", "enable", "levels", "intensity", "strength", "mix", "bloom_threshold", "blend_mode", "hdr_bleed_threshold", "hdr_bleed_scale", "hdr_luminance_cap", "glow_map_strength", "glow_map"), &RenderingServer::environment_set_glow);
  2487. ClassDB::bind_method(D_METHOD("environment_set_tonemap", "env", "tone_mapper", "exposure", "white"), &RenderingServer::environment_set_tonemap);
  2488. ClassDB::bind_method(D_METHOD("environment_set_adjustment", "env", "enable", "brightness", "contrast", "saturation", "use_1d_color_correction", "color_correction"), &RenderingServer::environment_set_adjustment);
  2489. ClassDB::bind_method(D_METHOD("environment_set_ssr", "env", "enable", "max_steps", "fade_in", "fade_out", "depth_tolerance"), &RenderingServer::environment_set_ssr);
  2490. ClassDB::bind_method(D_METHOD("environment_set_ssao", "env", "enable", "radius", "intensity", "power", "detail", "horizon", "sharpness", "light_affect", "ao_channel_affect"), &RenderingServer::environment_set_ssao);
  2491. ClassDB::bind_method(D_METHOD("environment_set_fog", "env", "enable", "light_color", "light_energy", "sun_scatter", "density", "height", "height_density", "aerial_perspective", "sky_affect", "fog_mode"), &RenderingServer::environment_set_fog, DEFVAL(RS::ENV_FOG_MODE_EXPONENTIAL));
  2492. ClassDB::bind_method(D_METHOD("environment_set_sdfgi", "env", "enable", "cascades", "min_cell_size", "y_scale", "use_occlusion", "bounce_feedback", "read_sky", "energy", "normal_bias", "probe_bias"), &RenderingServer::environment_set_sdfgi);
  2493. ClassDB::bind_method(D_METHOD("environment_set_volumetric_fog", "env", "enable", "density", "albedo", "emission", "emission_energy", "anisotropy", "length", "p_detail_spread", "gi_inject", "temporal_reprojection", "temporal_reprojection_amount", "ambient_inject", "sky_affect"), &RenderingServer::environment_set_volumetric_fog);
  2494. ClassDB::bind_method(D_METHOD("environment_glow_set_use_bicubic_upscale", "enable"), &RenderingServer::environment_glow_set_use_bicubic_upscale);
  2495. ClassDB::bind_method(D_METHOD("environment_set_ssr_roughness_quality", "quality"), &RenderingServer::environment_set_ssr_roughness_quality);
  2496. ClassDB::bind_method(D_METHOD("environment_set_ssao_quality", "quality", "half_size", "adaptive_target", "blur_passes", "fadeout_from", "fadeout_to"), &RenderingServer::environment_set_ssao_quality);
  2497. ClassDB::bind_method(D_METHOD("environment_set_ssil_quality", "quality", "half_size", "adaptive_target", "blur_passes", "fadeout_from", "fadeout_to"), &RenderingServer::environment_set_ssil_quality);
  2498. ClassDB::bind_method(D_METHOD("environment_set_sdfgi_ray_count", "ray_count"), &RenderingServer::environment_set_sdfgi_ray_count);
  2499. ClassDB::bind_method(D_METHOD("environment_set_sdfgi_frames_to_converge", "frames"), &RenderingServer::environment_set_sdfgi_frames_to_converge);
  2500. ClassDB::bind_method(D_METHOD("environment_set_sdfgi_frames_to_update_light", "frames"), &RenderingServer::environment_set_sdfgi_frames_to_update_light);
  2501. ClassDB::bind_method(D_METHOD("environment_set_volumetric_fog_volume_size", "size", "depth"), &RenderingServer::environment_set_volumetric_fog_volume_size);
  2502. ClassDB::bind_method(D_METHOD("environment_set_volumetric_fog_filter_active", "active"), &RenderingServer::environment_set_volumetric_fog_filter_active);
  2503. ClassDB::bind_method(D_METHOD("environment_bake_panorama", "environment", "bake_irradiance", "size"), &RenderingServer::environment_bake_panorama);
  2504. ClassDB::bind_method(D_METHOD("screen_space_roughness_limiter_set_active", "enable", "amount", "limit"), &RenderingServer::screen_space_roughness_limiter_set_active);
  2505. ClassDB::bind_method(D_METHOD("sub_surface_scattering_set_quality", "quality"), &RenderingServer::sub_surface_scattering_set_quality);
  2506. ClassDB::bind_method(D_METHOD("sub_surface_scattering_set_scale", "scale", "depth_scale"), &RenderingServer::sub_surface_scattering_set_scale);
  2507. BIND_ENUM_CONSTANT(ENV_BG_CLEAR_COLOR);
  2508. BIND_ENUM_CONSTANT(ENV_BG_COLOR);
  2509. BIND_ENUM_CONSTANT(ENV_BG_SKY);
  2510. BIND_ENUM_CONSTANT(ENV_BG_CANVAS);
  2511. BIND_ENUM_CONSTANT(ENV_BG_KEEP);
  2512. BIND_ENUM_CONSTANT(ENV_BG_CAMERA_FEED);
  2513. BIND_ENUM_CONSTANT(ENV_BG_MAX);
  2514. BIND_ENUM_CONSTANT(ENV_AMBIENT_SOURCE_BG);
  2515. BIND_ENUM_CONSTANT(ENV_AMBIENT_SOURCE_DISABLED);
  2516. BIND_ENUM_CONSTANT(ENV_AMBIENT_SOURCE_COLOR);
  2517. BIND_ENUM_CONSTANT(ENV_AMBIENT_SOURCE_SKY);
  2518. BIND_ENUM_CONSTANT(ENV_REFLECTION_SOURCE_BG);
  2519. BIND_ENUM_CONSTANT(ENV_REFLECTION_SOURCE_DISABLED);
  2520. BIND_ENUM_CONSTANT(ENV_REFLECTION_SOURCE_SKY);
  2521. BIND_ENUM_CONSTANT(ENV_GLOW_BLEND_MODE_ADDITIVE);
  2522. BIND_ENUM_CONSTANT(ENV_GLOW_BLEND_MODE_SCREEN);
  2523. BIND_ENUM_CONSTANT(ENV_GLOW_BLEND_MODE_SOFTLIGHT);
  2524. BIND_ENUM_CONSTANT(ENV_GLOW_BLEND_MODE_REPLACE);
  2525. BIND_ENUM_CONSTANT(ENV_GLOW_BLEND_MODE_MIX);
  2526. BIND_ENUM_CONSTANT(ENV_FOG_MODE_EXPONENTIAL);
  2527. BIND_ENUM_CONSTANT(ENV_FOG_MODE_DEPTH);
  2528. BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_LINEAR);
  2529. BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_REINHARD);
  2530. BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_FILMIC);
  2531. BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_ACES);
  2532. BIND_ENUM_CONSTANT(ENV_SSR_ROUGHNESS_QUALITY_DISABLED);
  2533. BIND_ENUM_CONSTANT(ENV_SSR_ROUGHNESS_QUALITY_LOW);
  2534. BIND_ENUM_CONSTANT(ENV_SSR_ROUGHNESS_QUALITY_MEDIUM);
  2535. BIND_ENUM_CONSTANT(ENV_SSR_ROUGHNESS_QUALITY_HIGH);
  2536. BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_VERY_LOW);
  2537. BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_LOW);
  2538. BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_MEDIUM);
  2539. BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_HIGH);
  2540. BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_ULTRA);
  2541. BIND_ENUM_CONSTANT(ENV_SSIL_QUALITY_VERY_LOW);
  2542. BIND_ENUM_CONSTANT(ENV_SSIL_QUALITY_LOW);
  2543. BIND_ENUM_CONSTANT(ENV_SSIL_QUALITY_MEDIUM);
  2544. BIND_ENUM_CONSTANT(ENV_SSIL_QUALITY_HIGH);
  2545. BIND_ENUM_CONSTANT(ENV_SSIL_QUALITY_ULTRA);
  2546. BIND_ENUM_CONSTANT(ENV_SDFGI_Y_SCALE_50_PERCENT);
  2547. BIND_ENUM_CONSTANT(ENV_SDFGI_Y_SCALE_75_PERCENT);
  2548. BIND_ENUM_CONSTANT(ENV_SDFGI_Y_SCALE_100_PERCENT);
  2549. BIND_ENUM_CONSTANT(ENV_SDFGI_RAY_COUNT_4);
  2550. BIND_ENUM_CONSTANT(ENV_SDFGI_RAY_COUNT_8);
  2551. BIND_ENUM_CONSTANT(ENV_SDFGI_RAY_COUNT_16);
  2552. BIND_ENUM_CONSTANT(ENV_SDFGI_RAY_COUNT_32);
  2553. BIND_ENUM_CONSTANT(ENV_SDFGI_RAY_COUNT_64);
  2554. BIND_ENUM_CONSTANT(ENV_SDFGI_RAY_COUNT_96);
  2555. BIND_ENUM_CONSTANT(ENV_SDFGI_RAY_COUNT_128);
  2556. BIND_ENUM_CONSTANT(ENV_SDFGI_RAY_COUNT_MAX);
  2557. BIND_ENUM_CONSTANT(ENV_SDFGI_CONVERGE_IN_5_FRAMES);
  2558. BIND_ENUM_CONSTANT(ENV_SDFGI_CONVERGE_IN_10_FRAMES);
  2559. BIND_ENUM_CONSTANT(ENV_SDFGI_CONVERGE_IN_15_FRAMES);
  2560. BIND_ENUM_CONSTANT(ENV_SDFGI_CONVERGE_IN_20_FRAMES);
  2561. BIND_ENUM_CONSTANT(ENV_SDFGI_CONVERGE_IN_25_FRAMES);
  2562. BIND_ENUM_CONSTANT(ENV_SDFGI_CONVERGE_IN_30_FRAMES);
  2563. BIND_ENUM_CONSTANT(ENV_SDFGI_CONVERGE_MAX);
  2564. BIND_ENUM_CONSTANT(ENV_SDFGI_UPDATE_LIGHT_IN_1_FRAME);
  2565. BIND_ENUM_CONSTANT(ENV_SDFGI_UPDATE_LIGHT_IN_2_FRAMES);
  2566. BIND_ENUM_CONSTANT(ENV_SDFGI_UPDATE_LIGHT_IN_4_FRAMES);
  2567. BIND_ENUM_CONSTANT(ENV_SDFGI_UPDATE_LIGHT_IN_8_FRAMES);
  2568. BIND_ENUM_CONSTANT(ENV_SDFGI_UPDATE_LIGHT_IN_16_FRAMES);
  2569. BIND_ENUM_CONSTANT(ENV_SDFGI_UPDATE_LIGHT_MAX);
  2570. BIND_ENUM_CONSTANT(SUB_SURFACE_SCATTERING_QUALITY_DISABLED);
  2571. BIND_ENUM_CONSTANT(SUB_SURFACE_SCATTERING_QUALITY_LOW);
  2572. BIND_ENUM_CONSTANT(SUB_SURFACE_SCATTERING_QUALITY_MEDIUM);
  2573. BIND_ENUM_CONSTANT(SUB_SURFACE_SCATTERING_QUALITY_HIGH);
  2574. /* CAMERA EFFECTS */
  2575. ClassDB::bind_method(D_METHOD("camera_attributes_create"), &RenderingServer::camera_attributes_create);
  2576. ClassDB::bind_method(D_METHOD("camera_attributes_set_dof_blur_quality", "quality", "use_jitter"), &RenderingServer::camera_attributes_set_dof_blur_quality);
  2577. ClassDB::bind_method(D_METHOD("camera_attributes_set_dof_blur_bokeh_shape", "shape"), &RenderingServer::camera_attributes_set_dof_blur_bokeh_shape);
  2578. ClassDB::bind_method(D_METHOD("camera_attributes_set_dof_blur", "camera_attributes", "far_enable", "far_distance", "far_transition", "near_enable", "near_distance", "near_transition", "amount"), &RenderingServer::camera_attributes_set_dof_blur);
  2579. ClassDB::bind_method(D_METHOD("camera_attributes_set_exposure", "camera_attributes", "multiplier", "normalization"), &RenderingServer::camera_attributes_set_exposure);
  2580. ClassDB::bind_method(D_METHOD("camera_attributes_set_auto_exposure", "camera_attributes", "enable", "min_sensitivity", "max_sensitivity", "speed", "scale"), &RenderingServer::camera_attributes_set_auto_exposure);
  2581. BIND_ENUM_CONSTANT(DOF_BOKEH_BOX);
  2582. BIND_ENUM_CONSTANT(DOF_BOKEH_HEXAGON);
  2583. BIND_ENUM_CONSTANT(DOF_BOKEH_CIRCLE);
  2584. BIND_ENUM_CONSTANT(DOF_BLUR_QUALITY_VERY_LOW);
  2585. BIND_ENUM_CONSTANT(DOF_BLUR_QUALITY_LOW);
  2586. BIND_ENUM_CONSTANT(DOF_BLUR_QUALITY_MEDIUM);
  2587. BIND_ENUM_CONSTANT(DOF_BLUR_QUALITY_HIGH);
  2588. /* SCENARIO */
  2589. ClassDB::bind_method(D_METHOD("scenario_create"), &RenderingServer::scenario_create);
  2590. ClassDB::bind_method(D_METHOD("scenario_set_environment", "scenario", "environment"), &RenderingServer::scenario_set_environment);
  2591. ClassDB::bind_method(D_METHOD("scenario_set_fallback_environment", "scenario", "environment"), &RenderingServer::scenario_set_fallback_environment);
  2592. ClassDB::bind_method(D_METHOD("scenario_set_camera_attributes", "scenario", "effects"), &RenderingServer::scenario_set_camera_attributes);
  2593. ClassDB::bind_method(D_METHOD("scenario_set_compositor", "scenario", "compositor"), &RenderingServer::scenario_set_compositor);
  2594. /* INSTANCE */
  2595. ClassDB::bind_method(D_METHOD("instance_create2", "base", "scenario"), &RenderingServer::instance_create2);
  2596. ClassDB::bind_method(D_METHOD("instance_create"), &RenderingServer::instance_create);
  2597. ClassDB::bind_method(D_METHOD("instance_set_base", "instance", "base"), &RenderingServer::instance_set_base);
  2598. ClassDB::bind_method(D_METHOD("instance_set_scenario", "instance", "scenario"), &RenderingServer::instance_set_scenario);
  2599. ClassDB::bind_method(D_METHOD("instance_set_layer_mask", "instance", "mask"), &RenderingServer::instance_set_layer_mask);
  2600. ClassDB::bind_method(D_METHOD("instance_set_pivot_data", "instance", "sorting_offset", "use_aabb_center"), &RenderingServer::instance_set_pivot_data);
  2601. ClassDB::bind_method(D_METHOD("instance_set_transform", "instance", "transform"), &RenderingServer::instance_set_transform);
  2602. ClassDB::bind_method(D_METHOD("instance_attach_object_instance_id", "instance", "id"), &RenderingServer::instance_attach_object_instance_id);
  2603. ClassDB::bind_method(D_METHOD("instance_set_blend_shape_weight", "instance", "shape", "weight"), &RenderingServer::instance_set_blend_shape_weight);
  2604. ClassDB::bind_method(D_METHOD("instance_set_surface_override_material", "instance", "surface", "material"), &RenderingServer::instance_set_surface_override_material);
  2605. ClassDB::bind_method(D_METHOD("instance_set_visible", "instance", "visible"), &RenderingServer::instance_set_visible);
  2606. ClassDB::bind_method(D_METHOD("instance_geometry_set_transparency", "instance", "transparency"), &RenderingServer::instance_geometry_set_transparency);
  2607. ClassDB::bind_method(D_METHOD("instance_set_custom_aabb", "instance", "aabb"), &RenderingServer::instance_set_custom_aabb);
  2608. ClassDB::bind_method(D_METHOD("instance_attach_skeleton", "instance", "skeleton"), &RenderingServer::instance_attach_skeleton);
  2609. ClassDB::bind_method(D_METHOD("instance_set_extra_visibility_margin", "instance", "margin"), &RenderingServer::instance_set_extra_visibility_margin);
  2610. ClassDB::bind_method(D_METHOD("instance_set_visibility_parent", "instance", "parent"), &RenderingServer::instance_set_visibility_parent);
  2611. ClassDB::bind_method(D_METHOD("instance_set_ignore_culling", "instance", "enabled"), &RenderingServer::instance_set_ignore_culling);
  2612. ClassDB::bind_method(D_METHOD("instance_geometry_set_flag", "instance", "flag", "enabled"), &RenderingServer::instance_geometry_set_flag);
  2613. ClassDB::bind_method(D_METHOD("instance_geometry_set_cast_shadows_setting", "instance", "shadow_casting_setting"), &RenderingServer::instance_geometry_set_cast_shadows_setting);
  2614. ClassDB::bind_method(D_METHOD("instance_geometry_set_material_override", "instance", "material"), &RenderingServer::instance_geometry_set_material_override);
  2615. ClassDB::bind_method(D_METHOD("instance_geometry_set_material_overlay", "instance", "material"), &RenderingServer::instance_geometry_set_material_overlay);
  2616. ClassDB::bind_method(D_METHOD("instance_geometry_set_visibility_range", "instance", "min", "max", "min_margin", "max_margin", "fade_mode"), &RenderingServer::instance_geometry_set_visibility_range);
  2617. ClassDB::bind_method(D_METHOD("instance_geometry_set_lightmap", "instance", "lightmap", "lightmap_uv_scale", "lightmap_slice"), &RenderingServer::instance_geometry_set_lightmap);
  2618. ClassDB::bind_method(D_METHOD("instance_geometry_set_lod_bias", "instance", "lod_bias"), &RenderingServer::instance_geometry_set_lod_bias);
  2619. ClassDB::bind_method(D_METHOD("instance_geometry_set_shader_parameter", "instance", "parameter", "value"), &RenderingServer::instance_geometry_set_shader_parameter);
  2620. ClassDB::bind_method(D_METHOD("instance_geometry_get_shader_parameter", "instance", "parameter"), &RenderingServer::instance_geometry_get_shader_parameter);
  2621. ClassDB::bind_method(D_METHOD("instance_geometry_get_shader_parameter_default_value", "instance", "parameter"), &RenderingServer::instance_geometry_get_shader_parameter_default_value);
  2622. ClassDB::bind_method(D_METHOD("instance_geometry_get_shader_parameter_list", "instance"), &RenderingServer::_instance_geometry_get_shader_parameter_list);
  2623. ClassDB::bind_method(D_METHOD("instances_cull_aabb", "aabb", "scenario"), &RenderingServer::_instances_cull_aabb_bind, DEFVAL(RID()));
  2624. ClassDB::bind_method(D_METHOD("instances_cull_ray", "from", "to", "scenario"), &RenderingServer::_instances_cull_ray_bind, DEFVAL(RID()));
  2625. ClassDB::bind_method(D_METHOD("instances_cull_convex", "convex", "scenario"), &RenderingServer::_instances_cull_convex_bind, DEFVAL(RID()));
  2626. BIND_ENUM_CONSTANT(INSTANCE_NONE);
  2627. BIND_ENUM_CONSTANT(INSTANCE_MESH);
  2628. BIND_ENUM_CONSTANT(INSTANCE_MULTIMESH);
  2629. BIND_ENUM_CONSTANT(INSTANCE_PARTICLES);
  2630. BIND_ENUM_CONSTANT(INSTANCE_PARTICLES_COLLISION);
  2631. BIND_ENUM_CONSTANT(INSTANCE_LIGHT);
  2632. BIND_ENUM_CONSTANT(INSTANCE_REFLECTION_PROBE);
  2633. BIND_ENUM_CONSTANT(INSTANCE_DECAL);
  2634. BIND_ENUM_CONSTANT(INSTANCE_VOXEL_GI);
  2635. BIND_ENUM_CONSTANT(INSTANCE_LIGHTMAP);
  2636. BIND_ENUM_CONSTANT(INSTANCE_OCCLUDER);
  2637. BIND_ENUM_CONSTANT(INSTANCE_VISIBLITY_NOTIFIER);
  2638. BIND_ENUM_CONSTANT(INSTANCE_FOG_VOLUME);
  2639. BIND_ENUM_CONSTANT(INSTANCE_MAX);
  2640. BIND_ENUM_CONSTANT(INSTANCE_GEOMETRY_MASK);
  2641. BIND_ENUM_CONSTANT(INSTANCE_FLAG_USE_BAKED_LIGHT);
  2642. BIND_ENUM_CONSTANT(INSTANCE_FLAG_USE_DYNAMIC_GI);
  2643. BIND_ENUM_CONSTANT(INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE);
  2644. BIND_ENUM_CONSTANT(INSTANCE_FLAG_IGNORE_OCCLUSION_CULLING);
  2645. BIND_ENUM_CONSTANT(INSTANCE_FLAG_MAX);
  2646. BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_OFF);
  2647. BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_ON);
  2648. BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_DOUBLE_SIDED);
  2649. BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_SHADOWS_ONLY);
  2650. BIND_ENUM_CONSTANT(VISIBILITY_RANGE_FADE_DISABLED);
  2651. BIND_ENUM_CONSTANT(VISIBILITY_RANGE_FADE_SELF);
  2652. BIND_ENUM_CONSTANT(VISIBILITY_RANGE_FADE_DEPENDENCIES);
  2653. /* Bake 3D Object */
  2654. ClassDB::bind_method(D_METHOD("bake_render_uv2", "base", "material_overrides", "image_size"), &RenderingServer::bake_render_uv2);
  2655. BIND_ENUM_CONSTANT(BAKE_CHANNEL_ALBEDO_ALPHA);
  2656. BIND_ENUM_CONSTANT(BAKE_CHANNEL_NORMAL);
  2657. BIND_ENUM_CONSTANT(BAKE_CHANNEL_ORM);
  2658. BIND_ENUM_CONSTANT(BAKE_CHANNEL_EMISSION);
  2659. /* CANVAS (2D) */
  2660. ClassDB::bind_method(D_METHOD("canvas_create"), &RenderingServer::canvas_create);
  2661. ClassDB::bind_method(D_METHOD("canvas_set_item_mirroring", "canvas", "item", "mirroring"), &RenderingServer::canvas_set_item_mirroring);
  2662. ClassDB::bind_method(D_METHOD("canvas_set_item_repeat", "item", "repeat_size", "repeat_times"), &RenderingServer::canvas_set_item_repeat);
  2663. ClassDB::bind_method(D_METHOD("canvas_set_modulate", "canvas", "color"), &RenderingServer::canvas_set_modulate);
  2664. ClassDB::bind_method(D_METHOD("canvas_set_disable_scale", "disable"), &RenderingServer::canvas_set_disable_scale);
  2665. /* CANVAS TEXTURE */
  2666. ClassDB::bind_method(D_METHOD("canvas_texture_create"), &RenderingServer::canvas_texture_create);
  2667. ClassDB::bind_method(D_METHOD("canvas_texture_set_channel", "canvas_texture", "channel", "texture"), &RenderingServer::canvas_texture_set_channel);
  2668. ClassDB::bind_method(D_METHOD("canvas_texture_set_shading_parameters", "canvas_texture", "base_color", "shininess"), &RenderingServer::canvas_texture_set_shading_parameters);
  2669. ClassDB::bind_method(D_METHOD("canvas_texture_set_texture_filter", "canvas_texture", "filter"), &RenderingServer::canvas_texture_set_texture_filter);
  2670. ClassDB::bind_method(D_METHOD("canvas_texture_set_texture_repeat", "canvas_texture", "repeat"), &RenderingServer::canvas_texture_set_texture_repeat);
  2671. BIND_ENUM_CONSTANT(CANVAS_TEXTURE_CHANNEL_DIFFUSE);
  2672. BIND_ENUM_CONSTANT(CANVAS_TEXTURE_CHANNEL_NORMAL);
  2673. BIND_ENUM_CONSTANT(CANVAS_TEXTURE_CHANNEL_SPECULAR);
  2674. /* CANVAS ITEM */
  2675. ClassDB::bind_method(D_METHOD("canvas_item_create"), &RenderingServer::canvas_item_create);
  2676. ClassDB::bind_method(D_METHOD("canvas_item_set_parent", "item", "parent"), &RenderingServer::canvas_item_set_parent);
  2677. ClassDB::bind_method(D_METHOD("canvas_item_set_default_texture_filter", "item", "filter"), &RenderingServer::canvas_item_set_default_texture_filter);
  2678. ClassDB::bind_method(D_METHOD("canvas_item_set_default_texture_repeat", "item", "repeat"), &RenderingServer::canvas_item_set_default_texture_repeat);
  2679. ClassDB::bind_method(D_METHOD("canvas_item_set_visible", "item", "visible"), &RenderingServer::canvas_item_set_visible);
  2680. ClassDB::bind_method(D_METHOD("canvas_item_set_light_mask", "item", "mask"), &RenderingServer::canvas_item_set_light_mask);
  2681. ClassDB::bind_method(D_METHOD("canvas_item_set_visibility_layer", "item", "visibility_layer"), &RenderingServer::canvas_item_set_visibility_layer);
  2682. ClassDB::bind_method(D_METHOD("canvas_item_set_transform", "item", "transform"), &RenderingServer::canvas_item_set_transform);
  2683. ClassDB::bind_method(D_METHOD("canvas_item_set_clip", "item", "clip"), &RenderingServer::canvas_item_set_clip);
  2684. ClassDB::bind_method(D_METHOD("canvas_item_set_distance_field_mode", "item", "enabled"), &RenderingServer::canvas_item_set_distance_field_mode);
  2685. ClassDB::bind_method(D_METHOD("canvas_item_set_custom_rect", "item", "use_custom_rect", "rect"), &RenderingServer::canvas_item_set_custom_rect, DEFVAL(Rect2()));
  2686. ClassDB::bind_method(D_METHOD("canvas_item_set_modulate", "item", "color"), &RenderingServer::canvas_item_set_modulate);
  2687. ClassDB::bind_method(D_METHOD("canvas_item_set_self_modulate", "item", "color"), &RenderingServer::canvas_item_set_self_modulate);
  2688. ClassDB::bind_method(D_METHOD("canvas_item_set_draw_behind_parent", "item", "enabled"), &RenderingServer::canvas_item_set_draw_behind_parent);
  2689. /* Primitives */
  2690. ClassDB::bind_method(D_METHOD("canvas_item_add_line", "item", "from", "to", "color", "width", "antialiased"), &RenderingServer::canvas_item_add_line, DEFVAL(-1.0), DEFVAL(false));
  2691. ClassDB::bind_method(D_METHOD("canvas_item_add_polyline", "item", "points", "colors", "width", "antialiased"), &RenderingServer::canvas_item_add_polyline, DEFVAL(-1.0), DEFVAL(false));
  2692. ClassDB::bind_method(D_METHOD("canvas_item_add_multiline", "item", "points", "colors", "width"), &RenderingServer::canvas_item_add_multiline, DEFVAL(-1.0));
  2693. ClassDB::bind_method(D_METHOD("canvas_item_add_rect", "item", "rect", "color"), &RenderingServer::canvas_item_add_rect);
  2694. ClassDB::bind_method(D_METHOD("canvas_item_add_circle", "item", "pos", "radius", "color"), &RenderingServer::canvas_item_add_circle);
  2695. ClassDB::bind_method(D_METHOD("canvas_item_add_texture_rect", "item", "rect", "texture", "tile", "modulate", "transpose"), &RenderingServer::canvas_item_add_texture_rect, DEFVAL(false), DEFVAL(Color(1, 1, 1)), DEFVAL(false));
  2696. ClassDB::bind_method(D_METHOD("canvas_item_add_msdf_texture_rect_region", "item", "rect", "texture", "src_rect", "modulate", "outline_size", "px_range", "scale"), &RenderingServer::canvas_item_add_msdf_texture_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(0), DEFVAL(1.0), DEFVAL(1.0));
  2697. ClassDB::bind_method(D_METHOD("canvas_item_add_lcd_texture_rect_region", "item", "rect", "texture", "src_rect", "modulate"), &RenderingServer::canvas_item_add_lcd_texture_rect_region);
  2698. ClassDB::bind_method(D_METHOD("canvas_item_add_texture_rect_region", "item", "rect", "texture", "src_rect", "modulate", "transpose", "clip_uv"), &RenderingServer::canvas_item_add_texture_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(true));
  2699. 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"), &RenderingServer::canvas_item_add_nine_patch, DEFVAL(NINE_PATCH_STRETCH), DEFVAL(NINE_PATCH_STRETCH), DEFVAL(true), DEFVAL(Color(1, 1, 1)));
  2700. ClassDB::bind_method(D_METHOD("canvas_item_add_primitive", "item", "points", "colors", "uvs", "texture"), &RenderingServer::canvas_item_add_primitive);
  2701. ClassDB::bind_method(D_METHOD("canvas_item_add_polygon", "item", "points", "colors", "uvs", "texture"), &RenderingServer::canvas_item_add_polygon, DEFVAL(Vector<Point2>()), DEFVAL(RID()));
  2702. ClassDB::bind_method(D_METHOD("canvas_item_add_triangle_array", "item", "indices", "points", "colors", "uvs", "bones", "weights", "texture", "count"), &RenderingServer::canvas_item_add_triangle_array, DEFVAL(Vector<Point2>()), DEFVAL(Vector<int>()), DEFVAL(Vector<float>()), DEFVAL(RID()), DEFVAL(-1));
  2703. ClassDB::bind_method(D_METHOD("canvas_item_add_mesh", "item", "mesh", "transform", "modulate", "texture"), &RenderingServer::canvas_item_add_mesh, DEFVAL(Transform2D()), DEFVAL(Color(1, 1, 1)), DEFVAL(RID()));
  2704. ClassDB::bind_method(D_METHOD("canvas_item_add_multimesh", "item", "mesh", "texture"), &RenderingServer::canvas_item_add_multimesh, DEFVAL(RID()));
  2705. ClassDB::bind_method(D_METHOD("canvas_item_add_particles", "item", "particles", "texture"), &RenderingServer::canvas_item_add_particles);
  2706. ClassDB::bind_method(D_METHOD("canvas_item_add_set_transform", "item", "transform"), &RenderingServer::canvas_item_add_set_transform);
  2707. ClassDB::bind_method(D_METHOD("canvas_item_add_clip_ignore", "item", "ignore"), &RenderingServer::canvas_item_add_clip_ignore);
  2708. ClassDB::bind_method(D_METHOD("canvas_item_add_animation_slice", "item", "animation_length", "slice_begin", "slice_end", "offset"), &RenderingServer::canvas_item_add_animation_slice, DEFVAL(0.0));
  2709. ClassDB::bind_method(D_METHOD("canvas_item_set_sort_children_by_y", "item", "enabled"), &RenderingServer::canvas_item_set_sort_children_by_y);
  2710. ClassDB::bind_method(D_METHOD("canvas_item_set_z_index", "item", "z_index"), &RenderingServer::canvas_item_set_z_index);
  2711. ClassDB::bind_method(D_METHOD("canvas_item_set_z_as_relative_to_parent", "item", "enabled"), &RenderingServer::canvas_item_set_z_as_relative_to_parent);
  2712. ClassDB::bind_method(D_METHOD("canvas_item_set_copy_to_backbuffer", "item", "enabled", "rect"), &RenderingServer::canvas_item_set_copy_to_backbuffer);
  2713. ClassDB::bind_method(D_METHOD("canvas_item_clear", "item"), &RenderingServer::canvas_item_clear);
  2714. ClassDB::bind_method(D_METHOD("canvas_item_set_draw_index", "item", "index"), &RenderingServer::canvas_item_set_draw_index);
  2715. ClassDB::bind_method(D_METHOD("canvas_item_set_material", "item", "material"), &RenderingServer::canvas_item_set_material);
  2716. ClassDB::bind_method(D_METHOD("canvas_item_set_use_parent_material", "item", "enabled"), &RenderingServer::canvas_item_set_use_parent_material);
  2717. ClassDB::bind_method(D_METHOD("canvas_item_set_visibility_notifier", "item", "enable", "area", "enter_callable", "exit_callable"), &RenderingServer::canvas_item_set_visibility_notifier);
  2718. ClassDB::bind_method(D_METHOD("canvas_item_set_canvas_group_mode", "item", "mode", "clear_margin", "fit_empty", "fit_margin", "blur_mipmaps"), &RenderingServer::canvas_item_set_canvas_group_mode, DEFVAL(5.0), DEFVAL(false), DEFVAL(0.0), DEFVAL(false));
  2719. ClassDB::bind_method(D_METHOD("debug_canvas_item_get_rect", "item"), &RenderingServer::debug_canvas_item_get_rect);
  2720. BIND_ENUM_CONSTANT(NINE_PATCH_STRETCH);
  2721. BIND_ENUM_CONSTANT(NINE_PATCH_TILE);
  2722. BIND_ENUM_CONSTANT(NINE_PATCH_TILE_FIT);
  2723. BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_FILTER_DEFAULT);
  2724. BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_FILTER_NEAREST);
  2725. BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_FILTER_LINEAR);
  2726. BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS);
  2727. BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS);
  2728. BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC);
  2729. BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC);
  2730. BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_FILTER_MAX);
  2731. BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT);
  2732. BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
  2733. BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_REPEAT_ENABLED);
  2734. BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_REPEAT_MIRROR);
  2735. BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_REPEAT_MAX);
  2736. BIND_ENUM_CONSTANT(CANVAS_GROUP_MODE_DISABLED);
  2737. BIND_ENUM_CONSTANT(CANVAS_GROUP_MODE_CLIP_ONLY);
  2738. BIND_ENUM_CONSTANT(CANVAS_GROUP_MODE_CLIP_AND_DRAW);
  2739. BIND_ENUM_CONSTANT(CANVAS_GROUP_MODE_TRANSPARENT);
  2740. /* CANVAS LIGHT */
  2741. ClassDB::bind_method(D_METHOD("canvas_light_create"), &RenderingServer::canvas_light_create);
  2742. ClassDB::bind_method(D_METHOD("canvas_light_attach_to_canvas", "light", "canvas"), &RenderingServer::canvas_light_attach_to_canvas);
  2743. ClassDB::bind_method(D_METHOD("canvas_light_set_enabled", "light", "enabled"), &RenderingServer::canvas_light_set_enabled);
  2744. ClassDB::bind_method(D_METHOD("canvas_light_set_texture_scale", "light", "scale"), &RenderingServer::canvas_light_set_texture_scale);
  2745. ClassDB::bind_method(D_METHOD("canvas_light_set_transform", "light", "transform"), &RenderingServer::canvas_light_set_transform);
  2746. ClassDB::bind_method(D_METHOD("canvas_light_set_texture", "light", "texture"), &RenderingServer::canvas_light_set_texture);
  2747. ClassDB::bind_method(D_METHOD("canvas_light_set_texture_offset", "light", "offset"), &RenderingServer::canvas_light_set_texture_offset);
  2748. ClassDB::bind_method(D_METHOD("canvas_light_set_color", "light", "color"), &RenderingServer::canvas_light_set_color);
  2749. ClassDB::bind_method(D_METHOD("canvas_light_set_height", "light", "height"), &RenderingServer::canvas_light_set_height);
  2750. ClassDB::bind_method(D_METHOD("canvas_light_set_energy", "light", "energy"), &RenderingServer::canvas_light_set_energy);
  2751. ClassDB::bind_method(D_METHOD("canvas_light_set_z_range", "light", "min_z", "max_z"), &RenderingServer::canvas_light_set_z_range);
  2752. ClassDB::bind_method(D_METHOD("canvas_light_set_layer_range", "light", "min_layer", "max_layer"), &RenderingServer::canvas_light_set_layer_range);
  2753. ClassDB::bind_method(D_METHOD("canvas_light_set_item_cull_mask", "light", "mask"), &RenderingServer::canvas_light_set_item_cull_mask);
  2754. ClassDB::bind_method(D_METHOD("canvas_light_set_item_shadow_cull_mask", "light", "mask"), &RenderingServer::canvas_light_set_item_shadow_cull_mask);
  2755. ClassDB::bind_method(D_METHOD("canvas_light_set_mode", "light", "mode"), &RenderingServer::canvas_light_set_mode);
  2756. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_enabled", "light", "enabled"), &RenderingServer::canvas_light_set_shadow_enabled);
  2757. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_filter", "light", "filter"), &RenderingServer::canvas_light_set_shadow_filter);
  2758. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_color", "light", "color"), &RenderingServer::canvas_light_set_shadow_color);
  2759. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_smooth", "light", "smooth"), &RenderingServer::canvas_light_set_shadow_smooth);
  2760. ClassDB::bind_method(D_METHOD("canvas_light_set_blend_mode", "light", "mode"), &RenderingServer::canvas_light_set_blend_mode);
  2761. BIND_ENUM_CONSTANT(CANVAS_LIGHT_MODE_POINT);
  2762. BIND_ENUM_CONSTANT(CANVAS_LIGHT_MODE_DIRECTIONAL);
  2763. BIND_ENUM_CONSTANT(CANVAS_LIGHT_BLEND_MODE_ADD);
  2764. BIND_ENUM_CONSTANT(CANVAS_LIGHT_BLEND_MODE_SUB);
  2765. BIND_ENUM_CONSTANT(CANVAS_LIGHT_BLEND_MODE_MIX);
  2766. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_NONE);
  2767. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF5);
  2768. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF13);
  2769. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_MAX);
  2770. /* CANVAS OCCLUDER */
  2771. ClassDB::bind_method(D_METHOD("canvas_light_occluder_create"), &RenderingServer::canvas_light_occluder_create);
  2772. ClassDB::bind_method(D_METHOD("canvas_light_occluder_attach_to_canvas", "occluder", "canvas"), &RenderingServer::canvas_light_occluder_attach_to_canvas);
  2773. ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_enabled", "occluder", "enabled"), &RenderingServer::canvas_light_occluder_set_enabled);
  2774. ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_polygon", "occluder", "polygon"), &RenderingServer::canvas_light_occluder_set_polygon);
  2775. ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_as_sdf_collision", "occluder", "enable"), &RenderingServer::canvas_light_occluder_set_as_sdf_collision);
  2776. ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_transform", "occluder", "transform"), &RenderingServer::canvas_light_occluder_set_transform);
  2777. ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_light_mask", "occluder", "mask"), &RenderingServer::canvas_light_occluder_set_light_mask);
  2778. /* CANVAS LIGHT OCCLUDER POLYGON */
  2779. ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_create"), &RenderingServer::canvas_occluder_polygon_create);
  2780. ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_set_shape", "occluder_polygon", "shape", "closed"), &RenderingServer::canvas_occluder_polygon_set_shape);
  2781. ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_set_cull_mode", "occluder_polygon", "mode"), &RenderingServer::canvas_occluder_polygon_set_cull_mode);
  2782. ClassDB::bind_method(D_METHOD("canvas_set_shadow_texture_size", "size"), &RenderingServer::canvas_set_shadow_texture_size);
  2783. BIND_ENUM_CONSTANT(CANVAS_OCCLUDER_POLYGON_CULL_DISABLED);
  2784. BIND_ENUM_CONSTANT(CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE);
  2785. BIND_ENUM_CONSTANT(CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE);
  2786. /* GLOBAL SHADER UNIFORMS */
  2787. ClassDB::bind_method(D_METHOD("global_shader_parameter_add", "name", "type", "default_value"), &RenderingServer::global_shader_parameter_add);
  2788. ClassDB::bind_method(D_METHOD("global_shader_parameter_remove", "name"), &RenderingServer::global_shader_parameter_remove);
  2789. ClassDB::bind_method(D_METHOD("global_shader_parameter_get_list"), &RenderingServer::_global_shader_parameter_get_list);
  2790. ClassDB::bind_method(D_METHOD("global_shader_parameter_set", "name", "value"), &RenderingServer::global_shader_parameter_set);
  2791. ClassDB::bind_method(D_METHOD("global_shader_parameter_set_override", "name", "value"), &RenderingServer::global_shader_parameter_set_override);
  2792. ClassDB::bind_method(D_METHOD("global_shader_parameter_get", "name"), &RenderingServer::global_shader_parameter_get);
  2793. ClassDB::bind_method(D_METHOD("global_shader_parameter_get_type", "name"), &RenderingServer::global_shader_parameter_get_type);
  2794. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_BOOL);
  2795. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_BVEC2);
  2796. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_BVEC3);
  2797. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_BVEC4);
  2798. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_INT);
  2799. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_IVEC2);
  2800. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_IVEC3);
  2801. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_IVEC4);
  2802. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_RECT2I);
  2803. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_UINT);
  2804. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_UVEC2);
  2805. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_UVEC3);
  2806. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_UVEC4);
  2807. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_FLOAT);
  2808. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_VEC2);
  2809. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_VEC3);
  2810. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_VEC4);
  2811. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_COLOR);
  2812. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_RECT2);
  2813. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_MAT2);
  2814. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_MAT3);
  2815. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_MAT4);
  2816. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_TRANSFORM_2D);
  2817. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_TRANSFORM);
  2818. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_SAMPLER2D);
  2819. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_SAMPLER2DARRAY);
  2820. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_SAMPLER3D);
  2821. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_SAMPLERCUBE);
  2822. BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_MAX);
  2823. /* Free */
  2824. ClassDB::bind_method(D_METHOD("free_rid", "rid"), &RenderingServer::free); // Shouldn't conflict with Object::free().
  2825. /* Misc */
  2826. ClassDB::bind_method(D_METHOD("request_frame_drawn_callback", "callable"), &RenderingServer::request_frame_drawn_callback);
  2827. ClassDB::bind_method(D_METHOD("has_changed"), &RenderingServer::has_changed);
  2828. ClassDB::bind_method(D_METHOD("get_rendering_info", "info"), &RenderingServer::get_rendering_info);
  2829. ClassDB::bind_method(D_METHOD("get_video_adapter_name"), &RenderingServer::get_video_adapter_name);
  2830. ClassDB::bind_method(D_METHOD("get_video_adapter_vendor"), &RenderingServer::get_video_adapter_vendor);
  2831. ClassDB::bind_method(D_METHOD("get_video_adapter_type"), &RenderingServer::get_video_adapter_type);
  2832. ClassDB::bind_method(D_METHOD("get_video_adapter_api_version"), &RenderingServer::get_video_adapter_api_version);
  2833. ClassDB::bind_method(D_METHOD("make_sphere_mesh", "latitudes", "longitudes", "radius"), &RenderingServer::make_sphere_mesh);
  2834. ClassDB::bind_method(D_METHOD("get_test_cube"), &RenderingServer::get_test_cube);
  2835. ClassDB::bind_method(D_METHOD("get_test_texture"), &RenderingServer::get_test_texture);
  2836. ClassDB::bind_method(D_METHOD("get_white_texture"), &RenderingServer::get_white_texture);
  2837. ClassDB::bind_method(D_METHOD("set_boot_image", "image", "color", "scale", "use_filter"), &RenderingServer::set_boot_image, DEFVAL(true));
  2838. ClassDB::bind_method(D_METHOD("get_default_clear_color"), &RenderingServer::get_default_clear_color);
  2839. ClassDB::bind_method(D_METHOD("set_default_clear_color", "color"), &RenderingServer::set_default_clear_color);
  2840. ClassDB::bind_method(D_METHOD("has_os_feature", "feature"), &RenderingServer::has_os_feature);
  2841. ClassDB::bind_method(D_METHOD("set_debug_generate_wireframes", "generate"), &RenderingServer::set_debug_generate_wireframes);
  2842. ClassDB::bind_method(D_METHOD("is_render_loop_enabled"), &RenderingServer::is_render_loop_enabled);
  2843. ClassDB::bind_method(D_METHOD("set_render_loop_enabled", "enabled"), &RenderingServer::set_render_loop_enabled);
  2844. ClassDB::bind_method(D_METHOD("get_frame_setup_time_cpu"), &RenderingServer::get_frame_setup_time_cpu);
  2845. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_loop_enabled"), "set_render_loop_enabled", "is_render_loop_enabled");
  2846. BIND_ENUM_CONSTANT(RENDERING_INFO_TOTAL_OBJECTS_IN_FRAME);
  2847. BIND_ENUM_CONSTANT(RENDERING_INFO_TOTAL_PRIMITIVES_IN_FRAME);
  2848. BIND_ENUM_CONSTANT(RENDERING_INFO_TOTAL_DRAW_CALLS_IN_FRAME);
  2849. BIND_ENUM_CONSTANT(RENDERING_INFO_TEXTURE_MEM_USED);
  2850. BIND_ENUM_CONSTANT(RENDERING_INFO_BUFFER_MEM_USED);
  2851. BIND_ENUM_CONSTANT(RENDERING_INFO_VIDEO_MEM_USED);
  2852. ADD_SIGNAL(MethodInfo("frame_pre_draw"));
  2853. ADD_SIGNAL(MethodInfo("frame_post_draw"));
  2854. ClassDB::bind_method(D_METHOD("force_sync"), &RenderingServer::sync);
  2855. ClassDB::bind_method(D_METHOD("force_draw", "swap_buffers", "frame_step"), &RenderingServer::draw, DEFVAL(true), DEFVAL(0.0));
  2856. ClassDB::bind_method(D_METHOD("get_rendering_device"), &RenderingServer::get_rendering_device);
  2857. ClassDB::bind_method(D_METHOD("create_local_rendering_device"), &RenderingServer::create_local_rendering_device);
  2858. ClassDB::bind_method(D_METHOD("call_on_render_thread", "callable"), &RenderingServer::call_on_render_thread);
  2859. #ifndef DISABLE_DEPRECATED
  2860. ClassDB::bind_method(D_METHOD("has_feature", "feature"), &RenderingServer::has_feature);
  2861. BIND_ENUM_CONSTANT(FEATURE_SHADERS);
  2862. BIND_ENUM_CONSTANT(FEATURE_MULTITHREADED);
  2863. #endif
  2864. }
  2865. void RenderingServer::mesh_add_surface_from_mesh_data(RID p_mesh, const Geometry3D::MeshData &p_mesh_data) {
  2866. Vector<Vector3> vertices;
  2867. Vector<Vector3> normals;
  2868. for (const Geometry3D::MeshData::Face &f : p_mesh_data.faces) {
  2869. for (uint32_t j = 2; j < f.indices.size(); j++) {
  2870. vertices.push_back(p_mesh_data.vertices[f.indices[0]]);
  2871. normals.push_back(f.plane.normal);
  2872. vertices.push_back(p_mesh_data.vertices[f.indices[j - 1]]);
  2873. normals.push_back(f.plane.normal);
  2874. vertices.push_back(p_mesh_data.vertices[f.indices[j]]);
  2875. normals.push_back(f.plane.normal);
  2876. }
  2877. }
  2878. Array d;
  2879. d.resize(RS::ARRAY_MAX);
  2880. d[ARRAY_VERTEX] = vertices;
  2881. d[ARRAY_NORMAL] = normals;
  2882. mesh_add_surface_from_arrays(p_mesh, PRIMITIVE_TRIANGLES, d);
  2883. }
  2884. void RenderingServer::mesh_add_surface_from_planes(RID p_mesh, const Vector<Plane> &p_planes) {
  2885. Geometry3D::MeshData mdata = Geometry3D::build_convex_mesh(p_planes);
  2886. mesh_add_surface_from_mesh_data(p_mesh, mdata);
  2887. }
  2888. RID RenderingServer::instance_create2(RID p_base, RID p_scenario) {
  2889. RID instance = instance_create();
  2890. instance_set_base(instance, p_base);
  2891. instance_set_scenario(instance, p_scenario);
  2892. return instance;
  2893. }
  2894. bool RenderingServer::is_render_loop_enabled() const {
  2895. return render_loop_enabled;
  2896. }
  2897. void RenderingServer::set_render_loop_enabled(bool p_enabled) {
  2898. render_loop_enabled = p_enabled;
  2899. }
  2900. RenderingServer::RenderingServer() {
  2901. //ERR_FAIL_COND(singleton);
  2902. singleton = this;
  2903. }
  2904. TypedArray<StringName> RenderingServer::_global_shader_parameter_get_list() const {
  2905. TypedArray<StringName> gsp;
  2906. Vector<StringName> gsp_sn = global_shader_parameter_get_list();
  2907. gsp.resize(gsp_sn.size());
  2908. for (int i = 0; i < gsp_sn.size(); i++) {
  2909. gsp[i] = gsp_sn[i];
  2910. }
  2911. return gsp;
  2912. }
  2913. void RenderingServer::init() {
  2914. // These are overrides, even if they are false Godot will still
  2915. // import the texture formats that the host platform needs.
  2916. // See `const bool can_s3tc_bptc` in the resource importer.
  2917. GLOBAL_DEF_RST("rendering/textures/vram_compression/import_s3tc_bptc", false);
  2918. GLOBAL_DEF_RST("rendering/textures/vram_compression/import_etc2_astc", false);
  2919. GLOBAL_DEF("rendering/textures/lossless_compression/force_png", false);
  2920. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/textures/webp_compression/compression_method", PROPERTY_HINT_RANGE, "0,6,1"), 2);
  2921. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/textures/webp_compression/lossless_compression_factor", PROPERTY_HINT_RANGE, "0,100,1"), 25);
  2922. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/limits/time/time_rollover_secs", PROPERTY_HINT_RANGE, "0,10000,1,or_greater"), 3600);
  2923. GLOBAL_DEF_RST("rendering/lights_and_shadows/use_physical_light_units", false);
  2924. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/lights_and_shadows/directional_shadow/size", PROPERTY_HINT_RANGE, "256,16384"), 4096);
  2925. GLOBAL_DEF("rendering/lights_and_shadows/directional_shadow/size.mobile", 2048);
  2926. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/lights_and_shadows/directional_shadow/soft_shadow_filter_quality", PROPERTY_HINT_ENUM, "Hard (Fastest),Soft Very Low (Faster),Soft Low (Fast),Soft Medium (Average),Soft High (Slow),Soft Ultra (Slowest)"), 2);
  2927. GLOBAL_DEF("rendering/lights_and_shadows/directional_shadow/soft_shadow_filter_quality.mobile", 0);
  2928. GLOBAL_DEF("rendering/lights_and_shadows/directional_shadow/16_bits", true);
  2929. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/lights_and_shadows/positional_shadow/soft_shadow_filter_quality", PROPERTY_HINT_ENUM, "Hard (Fastest),Soft Very Low (Faster),Soft Low (Fast),Soft Medium (Average),Soft High (Slow),Soft Ultra (Slowest)"), 2);
  2930. GLOBAL_DEF("rendering/lights_and_shadows/positional_shadow/soft_shadow_filter_quality.mobile", 0);
  2931. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/2d/shadow_atlas/size", PROPERTY_HINT_RANGE, "128,16384"), 2048);
  2932. // Number of commands that can be drawn per frame.
  2933. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/gl_compatibility/item_buffer_size", PROPERTY_HINT_RANGE, "128,1048576,1"), 16384);
  2934. GLOBAL_DEF("rendering/shader_compiler/shader_cache/enabled", true);
  2935. GLOBAL_DEF("rendering/shader_compiler/shader_cache/compress", true);
  2936. GLOBAL_DEF("rendering/shader_compiler/shader_cache/use_zstd_compression", true);
  2937. GLOBAL_DEF("rendering/shader_compiler/shader_cache/strip_debug", false);
  2938. GLOBAL_DEF("rendering/shader_compiler/shader_cache/strip_debug.release", true);
  2939. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/reflections/sky_reflections/roughness_layers", PROPERTY_HINT_RANGE, "1,32,1"), 8); // Assumes a 256x256 cubemap
  2940. GLOBAL_DEF_RST("rendering/reflections/sky_reflections/texture_array_reflections", true);
  2941. GLOBAL_DEF("rendering/reflections/sky_reflections/texture_array_reflections.mobile", false);
  2942. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/reflections/sky_reflections/ggx_samples", PROPERTY_HINT_RANGE, "0,256,1"), 32);
  2943. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/reflections/sky_reflections/ggx_samples.mobile", PROPERTY_HINT_RANGE, "0,128,1"), 16);
  2944. GLOBAL_DEF("rendering/reflections/sky_reflections/fast_filter_high_quality", false);
  2945. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/reflections/reflection_atlas/reflection_size", PROPERTY_HINT_RANGE, "0,4096,1"), 256);
  2946. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/reflections/reflection_atlas/reflection_size.mobile", PROPERTY_HINT_RANGE, "0,2048,1"), 128);
  2947. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/reflections/reflection_atlas/reflection_count", PROPERTY_HINT_RANGE, "0,256,1"), 64);
  2948. GLOBAL_DEF("rendering/global_illumination/gi/use_half_resolution", false);
  2949. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/global_illumination/voxel_gi/quality", PROPERTY_HINT_ENUM, "Low (4 Cones - Fast),High (6 Cones - Slow)"), 0);
  2950. GLOBAL_DEF("rendering/shading/overrides/force_vertex_shading", false);
  2951. GLOBAL_DEF("rendering/shading/overrides/force_vertex_shading.mobile", true);
  2952. GLOBAL_DEF("rendering/shading/overrides/force_lambert_over_burley", false);
  2953. GLOBAL_DEF("rendering/shading/overrides/force_lambert_over_burley.mobile", true);
  2954. GLOBAL_DEF_RST("rendering/driver/depth_prepass/enable", true);
  2955. GLOBAL_DEF_RST("rendering/driver/depth_prepass/disable_for_vendors", "PowerVR,Mali,Adreno,Apple");
  2956. GLOBAL_DEF_RST("rendering/textures/default_filters/use_nearest_mipmap_filter", false);
  2957. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/textures/default_filters/anisotropic_filtering_level", PROPERTY_HINT_ENUM, String::utf8("Disabled (Fastest),2× (Faster),4× (Fast),8× (Average),16× (Slow)")), 2);
  2958. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/camera/depth_of_field/depth_of_field_bokeh_shape", PROPERTY_HINT_ENUM, "Box (Fast),Hexagon (Average),Circle (Slowest)"), 1);
  2959. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/camera/depth_of_field/depth_of_field_bokeh_quality", PROPERTY_HINT_ENUM, "Very Low (Fastest),Low (Fast),Medium (Average),High (Slow)"), 1);
  2960. GLOBAL_DEF("rendering/camera/depth_of_field/depth_of_field_use_jitter", false);
  2961. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/environment/ssao/quality", PROPERTY_HINT_ENUM, "Very Low (Fast),Low (Fast),Medium (Average),High (Slow),Ultra (Custom)"), 2);
  2962. GLOBAL_DEF("rendering/environment/ssao/half_size", true);
  2963. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/environment/ssao/adaptive_target", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), 0.5);
  2964. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/environment/ssao/blur_passes", PROPERTY_HINT_RANGE, "0,6"), 2);
  2965. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/environment/ssao/fadeout_from", PROPERTY_HINT_RANGE, "0.0,512,0.1,or_greater"), 50.0);
  2966. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/environment/ssao/fadeout_to", PROPERTY_HINT_RANGE, "64,65536,0.1,or_greater"), 300.0);
  2967. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/environment/ssil/quality", PROPERTY_HINT_ENUM, "Very Low (Fast),Low (Fast),Medium (Average),High (Slow),Ultra (Custom)"), 2);
  2968. GLOBAL_DEF("rendering/environment/ssil/half_size", true);
  2969. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/environment/ssil/adaptive_target", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), 0.5);
  2970. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/environment/ssil/blur_passes", PROPERTY_HINT_RANGE, "0,6"), 4);
  2971. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/environment/ssil/fadeout_from", PROPERTY_HINT_RANGE, "0.0,512,0.1,or_greater"), 50.0);
  2972. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/environment/ssil/fadeout_to", PROPERTY_HINT_RANGE, "64,65536,0.1,or_greater"), 300.0);
  2973. GLOBAL_DEF("rendering/anti_aliasing/screen_space_roughness_limiter/enabled", true);
  2974. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/anti_aliasing/screen_space_roughness_limiter/amount", PROPERTY_HINT_RANGE, "0.01,4.0,0.01"), 0.25);
  2975. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/anti_aliasing/screen_space_roughness_limiter/limit", PROPERTY_HINT_RANGE, "0.01,1.0,0.01"), 0.18);
  2976. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/scaling_3d/mode", PROPERTY_HINT_ENUM, "Bilinear (Fastest),FSR 1.0 (Fast),FSR 2.2 (Slow)"), 0);
  2977. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/scaling_3d/scale", PROPERTY_HINT_RANGE, "0.25,2.0,0.01"), 1.0);
  2978. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/scaling_3d/fsr_sharpness", PROPERTY_HINT_RANGE, "0,2,0.1"), 0.2f);
  2979. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/textures/default_filters/texture_mipmap_bias", PROPERTY_HINT_RANGE, "-2,2,0.001"), 0.0f);
  2980. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/textures/decals/filter", PROPERTY_HINT_ENUM, "Nearest (Fast),Linear (Fast),Nearest Mipmap (Fast),Linear Mipmap (Fast),Nearest Mipmap Anisotropic (Average),Linear Mipmap Anisotropic (Average)"), DECAL_FILTER_LINEAR_MIPMAPS);
  2981. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/textures/light_projectors/filter", PROPERTY_HINT_ENUM, "Nearest (Fast),Linear (Fast),Nearest Mipmap (Fast),Linear Mipmap (Fast),Nearest Mipmap Anisotropic (Average),Linear Mipmap Anisotropic (Average)"), LIGHT_PROJECTOR_FILTER_LINEAR_MIPMAPS);
  2982. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/occlusion_culling/occlusion_rays_per_thread", PROPERTY_HINT_RANGE, "1,2048,1,or_greater"), 512);
  2983. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/environment/glow/upscale_mode", PROPERTY_HINT_ENUM, "Linear (Fast),Bicubic (Slow)"), 1);
  2984. GLOBAL_DEF("rendering/environment/glow/upscale_mode.mobile", 0);
  2985. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/environment/screen_space_reflection/roughness_quality", PROPERTY_HINT_ENUM, "Disabled (Fastest),Low (Fast),Medium (Average),High (Slow)"), 1);
  2986. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/environment/subsurface_scattering/subsurface_scattering_quality", PROPERTY_HINT_ENUM, "Disabled (Fastest),Low (Fast),Medium (Average),High (Slow)"), 1);
  2987. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/environment/subsurface_scattering/subsurface_scattering_scale", PROPERTY_HINT_RANGE, "0.001,1,0.001"), 0.05);
  2988. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/environment/subsurface_scattering/subsurface_scattering_depth_scale", PROPERTY_HINT_RANGE, "0.001,1,0.001"), 0.01);
  2989. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/limits/global_shader_variables/buffer_size", PROPERTY_HINT_RANGE, "1,1048576,1"), 65536);
  2990. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/lightmapping/probe_capture/update_speed", PROPERTY_HINT_RANGE, "0.001,256,0.001"), 15);
  2991. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/lightmapping/primitive_meshes/texel_size", PROPERTY_HINT_RANGE, "0.001,100,0.001"), 0.2);
  2992. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/global_illumination/sdfgi/probe_ray_count", PROPERTY_HINT_ENUM, "8 (Fastest),16,32,64,96,128 (Slowest)"), 1);
  2993. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/global_illumination/sdfgi/frames_to_converge", PROPERTY_HINT_ENUM, "5 (Less Latency but Lower Quality),10,15,20,25,30 (More Latency but Higher Quality)"), 5);
  2994. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/global_illumination/sdfgi/frames_to_update_lights", PROPERTY_HINT_ENUM, "1 (Slower),2,4,8,16 (Faster)"), 2);
  2995. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/environment/volumetric_fog/volume_size", PROPERTY_HINT_RANGE, "16,512,1"), 64);
  2996. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/environment/volumetric_fog/volume_depth", PROPERTY_HINT_RANGE, "16,512,1"), 64);
  2997. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/environment/volumetric_fog/use_filter", PROPERTY_HINT_ENUM, "No (Faster),Yes (Higher Quality)"), 1);
  2998. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/limits/spatial_indexer/update_iterations_per_frame", PROPERTY_HINT_RANGE, "0,1024,1"), 10);
  2999. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/limits/spatial_indexer/threaded_cull_minimum_instances", PROPERTY_HINT_RANGE, "32,65536,1"), 1000);
  3000. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/limits/cluster_builder/max_clustered_elements", PROPERTY_HINT_RANGE, "32,8192,1"), 512);
  3001. // OpenGL limits
  3002. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/limits/opengl/max_renderable_elements", PROPERTY_HINT_RANGE, "1024,65536,1"), 65536);
  3003. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/limits/opengl/max_renderable_lights", PROPERTY_HINT_RANGE, "2,256,1"), 32);
  3004. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/limits/opengl/max_lights_per_object", PROPERTY_HINT_RANGE, "2,1024,1"), 8);
  3005. GLOBAL_DEF_RST_BASIC("xr/shaders/enabled", false);
  3006. GLOBAL_DEF("debug/shader_language/warnings/enable", true);
  3007. GLOBAL_DEF("debug/shader_language/warnings/treat_warnings_as_errors", false);
  3008. #ifdef DEBUG_ENABLED
  3009. for (int i = 0; i < (int)ShaderWarning::WARNING_MAX; i++) {
  3010. GLOBAL_DEF("debug/shader_language/warnings/" + ShaderWarning::get_name_from_code((ShaderWarning::Code)i).to_lower(), true);
  3011. }
  3012. #endif
  3013. }
  3014. RenderingServer::~RenderingServer() {
  3015. singleton = nullptr;
  3016. }