rendering_server.cpp 190 KB

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