renderer_storage_rd.h 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238
  1. /*************************************************************************/
  2. /* renderer_storage_rd.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef RENDERING_SERVER_STORAGE_RD_H
  31. #define RENDERING_SERVER_STORAGE_RD_H
  32. #include "core/templates/list.h"
  33. #include "core/templates/local_vector.h"
  34. #include "core/templates/rid_owner.h"
  35. #include "servers/rendering/renderer_compositor.h"
  36. #include "servers/rendering/renderer_rd/effects_rd.h"
  37. #include "servers/rendering/renderer_rd/shaders/canvas_sdf.glsl.gen.h"
  38. #include "servers/rendering/renderer_rd/shaders/particles.glsl.gen.h"
  39. #include "servers/rendering/renderer_rd/shaders/particles_copy.glsl.gen.h"
  40. #include "servers/rendering/renderer_rd/shaders/skeleton.glsl.gen.h"
  41. #include "servers/rendering/renderer_rd/shaders/voxel_gi_sdf.glsl.gen.h"
  42. #include "servers/rendering/renderer_rd/storage_rd/canvas_texture_storage.h"
  43. #include "servers/rendering/renderer_rd/storage_rd/texture_storage.h"
  44. #include "servers/rendering/renderer_scene_render.h"
  45. #include "servers/rendering/rendering_device.h"
  46. #include "servers/rendering/shader_compiler.h"
  47. class RendererStorageRD : public RendererStorage {
  48. public:
  49. static _FORCE_INLINE_ void store_transform(const Transform3D &p_mtx, float *p_array) {
  50. p_array[0] = p_mtx.basis.elements[0][0];
  51. p_array[1] = p_mtx.basis.elements[1][0];
  52. p_array[2] = p_mtx.basis.elements[2][0];
  53. p_array[3] = 0;
  54. p_array[4] = p_mtx.basis.elements[0][1];
  55. p_array[5] = p_mtx.basis.elements[1][1];
  56. p_array[6] = p_mtx.basis.elements[2][1];
  57. p_array[7] = 0;
  58. p_array[8] = p_mtx.basis.elements[0][2];
  59. p_array[9] = p_mtx.basis.elements[1][2];
  60. p_array[10] = p_mtx.basis.elements[2][2];
  61. p_array[11] = 0;
  62. p_array[12] = p_mtx.origin.x;
  63. p_array[13] = p_mtx.origin.y;
  64. p_array[14] = p_mtx.origin.z;
  65. p_array[15] = 1;
  66. }
  67. static _FORCE_INLINE_ void store_basis_3x4(const Basis &p_mtx, float *p_array) {
  68. p_array[0] = p_mtx.elements[0][0];
  69. p_array[1] = p_mtx.elements[1][0];
  70. p_array[2] = p_mtx.elements[2][0];
  71. p_array[3] = 0;
  72. p_array[4] = p_mtx.elements[0][1];
  73. p_array[5] = p_mtx.elements[1][1];
  74. p_array[6] = p_mtx.elements[2][1];
  75. p_array[7] = 0;
  76. p_array[8] = p_mtx.elements[0][2];
  77. p_array[9] = p_mtx.elements[1][2];
  78. p_array[10] = p_mtx.elements[2][2];
  79. p_array[11] = 0;
  80. }
  81. static _FORCE_INLINE_ void store_transform_3x3(const Basis &p_mtx, float *p_array) {
  82. p_array[0] = p_mtx.elements[0][0];
  83. p_array[1] = p_mtx.elements[1][0];
  84. p_array[2] = p_mtx.elements[2][0];
  85. p_array[3] = 0;
  86. p_array[4] = p_mtx.elements[0][1];
  87. p_array[5] = p_mtx.elements[1][1];
  88. p_array[6] = p_mtx.elements[2][1];
  89. p_array[7] = 0;
  90. p_array[8] = p_mtx.elements[0][2];
  91. p_array[9] = p_mtx.elements[1][2];
  92. p_array[10] = p_mtx.elements[2][2];
  93. p_array[11] = 0;
  94. }
  95. static _FORCE_INLINE_ void store_transform_transposed_3x4(const Transform3D &p_mtx, float *p_array) {
  96. p_array[0] = p_mtx.basis.elements[0][0];
  97. p_array[1] = p_mtx.basis.elements[0][1];
  98. p_array[2] = p_mtx.basis.elements[0][2];
  99. p_array[3] = p_mtx.origin.x;
  100. p_array[4] = p_mtx.basis.elements[1][0];
  101. p_array[5] = p_mtx.basis.elements[1][1];
  102. p_array[6] = p_mtx.basis.elements[1][2];
  103. p_array[7] = p_mtx.origin.y;
  104. p_array[8] = p_mtx.basis.elements[2][0];
  105. p_array[9] = p_mtx.basis.elements[2][1];
  106. p_array[10] = p_mtx.basis.elements[2][2];
  107. p_array[11] = p_mtx.origin.z;
  108. }
  109. static _FORCE_INLINE_ void store_camera(const CameraMatrix &p_mtx, float *p_array) {
  110. for (int i = 0; i < 4; i++) {
  111. for (int j = 0; j < 4; j++) {
  112. p_array[i * 4 + j] = p_mtx.matrix[i][j];
  113. }
  114. }
  115. }
  116. static _FORCE_INLINE_ void store_soft_shadow_kernel(const float *p_kernel, float *p_array) {
  117. for (int i = 0; i < 128; i++) {
  118. p_array[i] = p_kernel[i];
  119. }
  120. }
  121. enum ShaderType {
  122. SHADER_TYPE_2D,
  123. SHADER_TYPE_3D,
  124. SHADER_TYPE_PARTICLES,
  125. SHADER_TYPE_SKY,
  126. SHADER_TYPE_FOG,
  127. SHADER_TYPE_MAX
  128. };
  129. struct ShaderData {
  130. virtual void set_code(const String &p_Code) = 0;
  131. virtual void set_default_texture_param(const StringName &p_name, RID p_texture, int p_index) = 0;
  132. virtual void get_param_list(List<PropertyInfo> *p_param_list) const = 0;
  133. virtual void get_instance_param_list(List<InstanceShaderParam> *p_param_list) const = 0;
  134. virtual bool is_param_texture(const StringName &p_param) const = 0;
  135. virtual bool is_animated() const = 0;
  136. virtual bool casts_shadows() const = 0;
  137. virtual Variant get_default_parameter(const StringName &p_parameter) const = 0;
  138. virtual RS::ShaderNativeSourceCode get_native_source_code() const { return RS::ShaderNativeSourceCode(); }
  139. virtual ~ShaderData() {}
  140. };
  141. typedef ShaderData *(*ShaderDataRequestFunction)();
  142. struct MaterialData {
  143. void update_uniform_buffer(const Map<StringName, ShaderLanguage::ShaderNode::Uniform> &p_uniforms, const uint32_t *p_uniform_offsets, const Map<StringName, Variant> &p_parameters, uint8_t *p_buffer, uint32_t p_buffer_size, bool p_use_linear_color);
  144. void update_textures(const Map<StringName, Variant> &p_parameters, const Map<StringName, Map<int, RID>> &p_default_textures, const Vector<ShaderCompiler::GeneratedCode::Texture> &p_texture_uniforms, RID *p_textures, bool p_use_linear_color);
  145. virtual void set_render_priority(int p_priority) = 0;
  146. virtual void set_next_pass(RID p_pass) = 0;
  147. virtual bool update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) = 0;
  148. virtual ~MaterialData();
  149. //to be used internally by update_parameters, in the most common configuration of material parameters
  150. bool update_parameters_uniform_set(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty, const Map<StringName, ShaderLanguage::ShaderNode::Uniform> &p_uniforms, const uint32_t *p_uniform_offsets, const Vector<ShaderCompiler::GeneratedCode::Texture> &p_texture_uniforms, const Map<StringName, Map<int, RID>> &p_default_texture_params, uint32_t p_ubo_size, RID &uniform_set, RID p_shader, uint32_t p_shader_uniform_set, uint32_t p_barrier = RD::BARRIER_MASK_ALL);
  151. void free_parameters_uniform_set(RID p_uniform_set);
  152. private:
  153. friend class RendererStorageRD;
  154. RID self;
  155. List<RID>::Element *global_buffer_E = nullptr;
  156. List<RID>::Element *global_texture_E = nullptr;
  157. uint64_t global_textures_pass = 0;
  158. Map<StringName, uint64_t> used_global_textures;
  159. //internally by update_parameters_uniform_set
  160. Vector<uint8_t> ubo_data;
  161. RID uniform_buffer;
  162. Vector<RID> texture_cache;
  163. };
  164. typedef MaterialData *(*MaterialDataRequestFunction)(ShaderData *);
  165. static void _material_uniform_set_erased(void *p_material);
  166. enum DefaultRDBuffer {
  167. DEFAULT_RD_BUFFER_VERTEX,
  168. DEFAULT_RD_BUFFER_NORMAL,
  169. DEFAULT_RD_BUFFER_TANGENT,
  170. DEFAULT_RD_BUFFER_COLOR,
  171. DEFAULT_RD_BUFFER_TEX_UV,
  172. DEFAULT_RD_BUFFER_TEX_UV2,
  173. DEFAULT_RD_BUFFER_CUSTOM0,
  174. DEFAULT_RD_BUFFER_CUSTOM1,
  175. DEFAULT_RD_BUFFER_CUSTOM2,
  176. DEFAULT_RD_BUFFER_CUSTOM3,
  177. DEFAULT_RD_BUFFER_BONES,
  178. DEFAULT_RD_BUFFER_WEIGHTS,
  179. DEFAULT_RD_BUFFER_MAX,
  180. };
  181. private:
  182. /* TEXTURE API */
  183. RID default_rd_samplers[RS::CANVAS_ITEM_TEXTURE_FILTER_MAX][RS::CANVAS_ITEM_TEXTURE_REPEAT_MAX];
  184. RID custom_rd_samplers[RS::CANVAS_ITEM_TEXTURE_FILTER_MAX][RS::CANVAS_ITEM_TEXTURE_REPEAT_MAX];
  185. RID default_rd_storage_buffer;
  186. /* DECAL ATLAS */
  187. struct DecalAtlas {
  188. struct Texture {
  189. int panorama_to_dp_users;
  190. int users;
  191. Rect2 uv_rect;
  192. };
  193. struct SortItem {
  194. RID texture;
  195. Size2i pixel_size;
  196. Size2i size;
  197. Point2i pos;
  198. bool operator<(const SortItem &p_item) const {
  199. //sort larger to smaller
  200. if (size.height == p_item.size.height) {
  201. return size.width > p_item.size.width;
  202. } else {
  203. return size.height > p_item.size.height;
  204. }
  205. }
  206. };
  207. HashMap<RID, Texture> textures;
  208. bool dirty = true;
  209. int mipmaps = 5;
  210. RID texture;
  211. RID texture_srgb;
  212. struct MipMap {
  213. RID fb;
  214. RID texture;
  215. Size2i size;
  216. };
  217. Vector<MipMap> texture_mipmaps;
  218. Size2i size;
  219. } decal_atlas;
  220. void _update_decal_atlas();
  221. /* SHADER */
  222. struct Material;
  223. struct Shader {
  224. ShaderData *data;
  225. String code;
  226. ShaderType type;
  227. Map<StringName, Map<int, RID>> default_texture_parameter;
  228. Set<Material *> owners;
  229. };
  230. ShaderDataRequestFunction shader_data_request_func[SHADER_TYPE_MAX];
  231. mutable RID_Owner<Shader, true> shader_owner;
  232. /* Material */
  233. struct Material {
  234. RID self;
  235. MaterialData *data = nullptr;
  236. Shader *shader = nullptr;
  237. //shortcut to shader data and type
  238. ShaderType shader_type = SHADER_TYPE_MAX;
  239. uint32_t shader_id = 0;
  240. bool uniform_dirty = false;
  241. bool texture_dirty = false;
  242. Map<StringName, Variant> params;
  243. int32_t priority = 0;
  244. RID next_pass;
  245. SelfList<Material> update_element;
  246. Dependency dependency;
  247. Material() :
  248. update_element(this) {}
  249. };
  250. MaterialDataRequestFunction material_data_request_func[SHADER_TYPE_MAX];
  251. mutable RID_Owner<Material, true> material_owner;
  252. SelfList<Material>::List material_update_list;
  253. void _material_queue_update(Material *material, bool p_uniform, bool p_texture);
  254. void _update_queued_materials();
  255. /* Mesh */
  256. struct MeshInstance;
  257. struct Mesh {
  258. struct Surface {
  259. RS::PrimitiveType primitive = RS::PRIMITIVE_POINTS;
  260. uint32_t format = 0;
  261. RID vertex_buffer;
  262. RID attribute_buffer;
  263. RID skin_buffer;
  264. uint32_t vertex_count = 0;
  265. uint32_t vertex_buffer_size = 0;
  266. uint32_t skin_buffer_size = 0;
  267. // A different pipeline needs to be allocated
  268. // depending on the inputs available in the
  269. // material.
  270. // There are never that many geometry/material
  271. // combinations, so a simple array is the most
  272. // cache-efficient structure.
  273. struct Version {
  274. uint32_t input_mask = 0;
  275. RD::VertexFormatID vertex_format = 0;
  276. RID vertex_array;
  277. };
  278. SpinLock version_lock; //needed to access versions
  279. Version *versions = nullptr; //allocated on demand
  280. uint32_t version_count = 0;
  281. RID index_buffer;
  282. RID index_array;
  283. uint32_t index_count = 0;
  284. struct LOD {
  285. float edge_length = 0.0;
  286. uint32_t index_count = 0;
  287. RID index_buffer;
  288. RID index_array;
  289. };
  290. LOD *lods = nullptr;
  291. uint32_t lod_count = 0;
  292. AABB aabb;
  293. Vector<AABB> bone_aabbs;
  294. RID blend_shape_buffer;
  295. RID material;
  296. uint32_t render_index = 0;
  297. uint64_t render_pass = 0;
  298. uint32_t multimesh_render_index = 0;
  299. uint64_t multimesh_render_pass = 0;
  300. uint32_t particles_render_index = 0;
  301. uint64_t particles_render_pass = 0;
  302. RID uniform_set;
  303. };
  304. uint32_t blend_shape_count = 0;
  305. RS::BlendShapeMode blend_shape_mode = RS::BLEND_SHAPE_MODE_NORMALIZED;
  306. Surface **surfaces = nullptr;
  307. uint32_t surface_count = 0;
  308. Vector<AABB> bone_aabbs;
  309. bool has_bone_weights = false;
  310. AABB aabb;
  311. AABB custom_aabb;
  312. Vector<RID> material_cache;
  313. List<MeshInstance *> instances;
  314. RID shadow_mesh;
  315. Set<Mesh *> shadow_owners;
  316. Dependency dependency;
  317. };
  318. mutable RID_Owner<Mesh, true> mesh_owner;
  319. struct MeshInstance {
  320. Mesh *mesh;
  321. RID skeleton;
  322. struct Surface {
  323. RID vertex_buffer;
  324. RID uniform_set;
  325. Mesh::Surface::Version *versions = nullptr; //allocated on demand
  326. uint32_t version_count = 0;
  327. };
  328. LocalVector<Surface> surfaces;
  329. LocalVector<float> blend_weights;
  330. RID blend_weights_buffer;
  331. List<MeshInstance *>::Element *I = nullptr; //used to erase itself
  332. uint64_t skeleton_version = 0;
  333. bool dirty = false;
  334. bool weights_dirty = false;
  335. SelfList<MeshInstance> weight_update_list;
  336. SelfList<MeshInstance> array_update_list;
  337. MeshInstance() :
  338. weight_update_list(this), array_update_list(this) {}
  339. };
  340. void _mesh_instance_clear(MeshInstance *mi);
  341. void _mesh_instance_add_surface(MeshInstance *mi, Mesh *mesh, uint32_t p_surface);
  342. mutable RID_Owner<MeshInstance> mesh_instance_owner;
  343. SelfList<MeshInstance>::List dirty_mesh_instance_weights;
  344. SelfList<MeshInstance>::List dirty_mesh_instance_arrays;
  345. struct SkeletonShader {
  346. struct PushConstant {
  347. uint32_t has_normal;
  348. uint32_t has_tangent;
  349. uint32_t has_skeleton;
  350. uint32_t has_blend_shape;
  351. uint32_t vertex_count;
  352. uint32_t vertex_stride;
  353. uint32_t skin_stride;
  354. uint32_t skin_weight_offset;
  355. uint32_t blend_shape_count;
  356. uint32_t normalized_blend_shapes;
  357. uint32_t pad0;
  358. uint32_t pad1;
  359. };
  360. enum {
  361. UNIFORM_SET_INSTANCE = 0,
  362. UNIFORM_SET_SURFACE = 1,
  363. UNIFORM_SET_SKELETON = 2,
  364. };
  365. enum {
  366. SHADER_MODE_2D,
  367. SHADER_MODE_3D,
  368. SHADER_MODE_MAX
  369. };
  370. SkeletonShaderRD shader;
  371. RID version;
  372. RID version_shader[SHADER_MODE_MAX];
  373. RID pipeline[SHADER_MODE_MAX];
  374. RID default_skeleton_uniform_set;
  375. } skeleton_shader;
  376. void _mesh_surface_generate_version_for_input_mask(Mesh::Surface::Version &v, Mesh::Surface *s, uint32_t p_input_mask, MeshInstance::Surface *mis = nullptr);
  377. RID mesh_default_rd_buffers[DEFAULT_RD_BUFFER_MAX];
  378. /* MultiMesh */
  379. struct MultiMesh {
  380. RID mesh;
  381. int instances = 0;
  382. RS::MultimeshTransformFormat xform_format = RS::MULTIMESH_TRANSFORM_3D;
  383. bool uses_colors = false;
  384. bool uses_custom_data = false;
  385. int visible_instances = -1;
  386. AABB aabb;
  387. bool aabb_dirty = false;
  388. bool buffer_set = false;
  389. uint32_t stride_cache = 0;
  390. uint32_t color_offset_cache = 0;
  391. uint32_t custom_data_offset_cache = 0;
  392. Vector<float> data_cache; //used if individual setting is used
  393. bool *data_cache_dirty_regions = nullptr;
  394. uint32_t data_cache_used_dirty_regions = 0;
  395. RID buffer; //storage buffer
  396. RID uniform_set_3d;
  397. RID uniform_set_2d;
  398. bool dirty = false;
  399. MultiMesh *dirty_list = nullptr;
  400. Dependency dependency;
  401. };
  402. mutable RID_Owner<MultiMesh, true> multimesh_owner;
  403. MultiMesh *multimesh_dirty_list = nullptr;
  404. _FORCE_INLINE_ void _multimesh_make_local(MultiMesh *multimesh) const;
  405. _FORCE_INLINE_ void _multimesh_mark_dirty(MultiMesh *multimesh, int p_index, bool p_aabb);
  406. _FORCE_INLINE_ void _multimesh_mark_all_dirty(MultiMesh *multimesh, bool p_data, bool p_aabb);
  407. _FORCE_INLINE_ void _multimesh_re_create_aabb(MultiMesh *multimesh, const float *p_data, int p_instances);
  408. void _update_dirty_multimeshes();
  409. /* PARTICLES */
  410. struct ParticleData {
  411. float xform[16];
  412. float velocity[3];
  413. uint32_t active;
  414. float color[4];
  415. float custom[3];
  416. float lifetime;
  417. };
  418. struct ParticlesFrameParams {
  419. enum {
  420. MAX_ATTRACTORS = 32,
  421. MAX_COLLIDERS = 32,
  422. MAX_3D_TEXTURES = 7
  423. };
  424. enum AttractorType {
  425. ATTRACTOR_TYPE_SPHERE,
  426. ATTRACTOR_TYPE_BOX,
  427. ATTRACTOR_TYPE_VECTOR_FIELD,
  428. };
  429. struct Attractor {
  430. float transform[16];
  431. float extents[3]; //exents or radius
  432. uint32_t type;
  433. uint32_t texture_index; //texture index for vector field
  434. float strength;
  435. float attenuation;
  436. float directionality;
  437. };
  438. enum CollisionType {
  439. COLLISION_TYPE_SPHERE,
  440. COLLISION_TYPE_BOX,
  441. COLLISION_TYPE_SDF,
  442. COLLISION_TYPE_HEIGHT_FIELD,
  443. COLLISION_TYPE_2D_SDF,
  444. };
  445. struct Collider {
  446. float transform[16];
  447. float extents[3]; //exents or radius
  448. uint32_t type;
  449. uint32_t texture_index; //texture index for vector field
  450. real_t scale;
  451. uint32_t pad[2];
  452. };
  453. uint32_t emitting;
  454. float system_phase;
  455. float prev_system_phase;
  456. uint32_t cycle;
  457. real_t explosiveness;
  458. real_t randomness;
  459. float time;
  460. float delta;
  461. uint32_t frame;
  462. uint32_t pad0;
  463. uint32_t pad1;
  464. uint32_t pad2;
  465. uint32_t random_seed;
  466. uint32_t attractor_count;
  467. uint32_t collider_count;
  468. float particle_size;
  469. float emission_transform[16];
  470. Attractor attractors[MAX_ATTRACTORS];
  471. Collider colliders[MAX_COLLIDERS];
  472. };
  473. struct ParticleEmissionBufferData {
  474. };
  475. struct ParticleEmissionBuffer {
  476. struct Data {
  477. float xform[16];
  478. float velocity[3];
  479. uint32_t flags;
  480. float color[4];
  481. float custom[4];
  482. };
  483. int32_t particle_count;
  484. int32_t particle_max;
  485. uint32_t pad1;
  486. uint32_t pad2;
  487. Data data[1]; //its 2020 and empty arrays are still non standard in C++
  488. };
  489. struct Particles {
  490. RS::ParticlesMode mode = RS::PARTICLES_MODE_3D;
  491. bool inactive = true;
  492. double inactive_time = 0.0;
  493. bool emitting = false;
  494. bool one_shot = false;
  495. int amount = 0;
  496. double lifetime = 1.0;
  497. double pre_process_time = 0.0;
  498. real_t explosiveness = 0.0;
  499. real_t randomness = 0.0;
  500. bool restart_request = false;
  501. AABB custom_aabb = AABB(Vector3(-4, -4, -4), Vector3(8, 8, 8));
  502. bool use_local_coords = true;
  503. bool has_collision_cache = false;
  504. bool has_sdf_collision = false;
  505. Transform2D sdf_collision_transform;
  506. Rect2 sdf_collision_to_screen;
  507. RID sdf_collision_texture;
  508. RID process_material;
  509. uint32_t frame_counter = 0;
  510. RS::ParticlesTransformAlign transform_align = RS::PARTICLES_TRANSFORM_ALIGN_DISABLED;
  511. RS::ParticlesDrawOrder draw_order = RS::PARTICLES_DRAW_ORDER_INDEX;
  512. Vector<RID> draw_passes;
  513. Vector<Transform3D> trail_bind_poses;
  514. bool trail_bind_poses_dirty = false;
  515. RID trail_bind_pose_buffer;
  516. RID trail_bind_pose_uniform_set;
  517. RID particle_buffer;
  518. RID particle_instance_buffer;
  519. RID frame_params_buffer;
  520. uint32_t userdata_count = 0;
  521. RID particles_material_uniform_set;
  522. RID particles_copy_uniform_set;
  523. RID particles_transforms_buffer_uniform_set;
  524. RID collision_textures_uniform_set;
  525. RID collision_3d_textures[ParticlesFrameParams::MAX_3D_TEXTURES];
  526. uint32_t collision_3d_textures_used = 0;
  527. RID collision_heightmap_texture;
  528. RID particles_sort_buffer;
  529. RID particles_sort_uniform_set;
  530. bool dirty = false;
  531. Particles *update_list = nullptr;
  532. RID sub_emitter;
  533. double phase = 0.0;
  534. double prev_phase = 0.0;
  535. uint64_t prev_ticks = 0;
  536. uint32_t random_seed = 0;
  537. uint32_t cycle_number = 0;
  538. double speed_scale = 1.0;
  539. int fixed_fps = 30;
  540. bool interpolate = true;
  541. bool fractional_delta = false;
  542. double frame_remainder = 0;
  543. real_t collision_base_size = 0.01;
  544. bool clear = true;
  545. bool force_sub_emit = false;
  546. Transform3D emission_transform;
  547. Vector<uint8_t> emission_buffer_data;
  548. ParticleEmissionBuffer *emission_buffer = nullptr;
  549. RID emission_storage_buffer;
  550. Set<RID> collisions;
  551. Dependency dependency;
  552. double trail_length = 1.0;
  553. bool trails_enabled = false;
  554. LocalVector<ParticlesFrameParams> frame_history;
  555. LocalVector<ParticlesFrameParams> trail_params;
  556. Particles() {
  557. }
  558. };
  559. void _particles_process(Particles *p_particles, double p_delta);
  560. void _particles_allocate_emission_buffer(Particles *particles);
  561. void _particles_free_data(Particles *particles);
  562. void _particles_update_buffers(Particles *particles);
  563. struct ParticlesShader {
  564. struct PushConstant {
  565. float lifetime;
  566. uint32_t clear;
  567. uint32_t total_particles;
  568. uint32_t trail_size;
  569. uint32_t use_fractional_delta;
  570. uint32_t sub_emitter_mode;
  571. uint32_t can_emit;
  572. uint32_t trail_pass;
  573. };
  574. ParticlesShaderRD shader;
  575. ShaderCompiler compiler;
  576. RID default_shader;
  577. RID default_material;
  578. RID default_shader_rd;
  579. RID base_uniform_set;
  580. struct CopyPushConstant {
  581. float sort_direction[3];
  582. uint32_t total_particles;
  583. uint32_t trail_size;
  584. uint32_t trail_total;
  585. float frame_delta;
  586. float frame_remainder;
  587. float align_up[3];
  588. uint32_t align_mode;
  589. uint32_t order_by_lifetime;
  590. uint32_t lifetime_split;
  591. uint32_t lifetime_reverse;
  592. uint32_t copy_mode_2d;
  593. float inv_emission_transform[16];
  594. };
  595. enum {
  596. MAX_USERDATAS = 6
  597. };
  598. enum {
  599. COPY_MODE_FILL_INSTANCES,
  600. COPY_MODE_FILL_SORT_BUFFER,
  601. COPY_MODE_FILL_INSTANCES_WITH_SORT_BUFFER,
  602. COPY_MODE_MAX,
  603. };
  604. ParticlesCopyShaderRD copy_shader;
  605. RID copy_shader_version;
  606. RID copy_pipelines[COPY_MODE_MAX * (MAX_USERDATAS + 1)];
  607. LocalVector<float> pose_update_buffer;
  608. } particles_shader;
  609. Particles *particle_update_list = nullptr;
  610. struct ParticlesShaderData : public ShaderData {
  611. bool valid;
  612. RID version;
  613. bool uses_collision = false;
  614. //PipelineCacheRD pipelines[SKY_VERSION_MAX];
  615. Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
  616. Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms;
  617. Vector<uint32_t> ubo_offsets;
  618. uint32_t ubo_size;
  619. String path;
  620. String code;
  621. Map<StringName, Map<int, RID>> default_texture_params;
  622. RID pipeline;
  623. bool uses_time = false;
  624. bool userdatas_used[ParticlesShader::MAX_USERDATAS] = {};
  625. uint32_t userdata_count = 0;
  626. virtual void set_code(const String &p_Code);
  627. virtual void set_default_texture_param(const StringName &p_name, RID p_texture, int p_index);
  628. virtual void get_param_list(List<PropertyInfo> *p_param_list) const;
  629. virtual void get_instance_param_list(List<RendererStorage::InstanceShaderParam> *p_param_list) const;
  630. virtual bool is_param_texture(const StringName &p_param) const;
  631. virtual bool is_animated() const;
  632. virtual bool casts_shadows() const;
  633. virtual Variant get_default_parameter(const StringName &p_parameter) const;
  634. virtual RS::ShaderNativeSourceCode get_native_source_code() const;
  635. ParticlesShaderData();
  636. virtual ~ParticlesShaderData();
  637. };
  638. ShaderData *_create_particles_shader_func();
  639. static RendererStorageRD::ShaderData *_create_particles_shader_funcs() {
  640. return base_singleton->_create_particles_shader_func();
  641. }
  642. struct ParticlesMaterialData : public MaterialData {
  643. ParticlesShaderData *shader_data = nullptr;
  644. RID uniform_set;
  645. virtual void set_render_priority(int p_priority) {}
  646. virtual void set_next_pass(RID p_pass) {}
  647. virtual bool update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty);
  648. virtual ~ParticlesMaterialData();
  649. };
  650. MaterialData *_create_particles_material_func(ParticlesShaderData *p_shader);
  651. static RendererStorageRD::MaterialData *_create_particles_material_funcs(ShaderData *p_shader) {
  652. return base_singleton->_create_particles_material_func(static_cast<ParticlesShaderData *>(p_shader));
  653. }
  654. void update_particles();
  655. mutable RID_Owner<Particles, true> particles_owner;
  656. /* Particles Collision */
  657. struct ParticlesCollision {
  658. RS::ParticlesCollisionType type = RS::PARTICLES_COLLISION_TYPE_SPHERE_ATTRACT;
  659. uint32_t cull_mask = 0xFFFFFFFF;
  660. float radius = 1.0;
  661. Vector3 extents = Vector3(1, 1, 1);
  662. float attractor_strength = 1.0;
  663. float attractor_attenuation = 1.0;
  664. float attractor_directionality = 0.0;
  665. RID field_texture;
  666. RID heightfield_texture;
  667. RID heightfield_fb;
  668. Size2i heightfield_fb_size;
  669. RS::ParticlesCollisionHeightfieldResolution heightfield_resolution = RS::PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_1024;
  670. Dependency dependency;
  671. };
  672. mutable RID_Owner<ParticlesCollision, true> particles_collision_owner;
  673. struct ParticlesCollisionInstance {
  674. RID collision;
  675. Transform3D transform;
  676. bool active = false;
  677. };
  678. mutable RID_Owner<ParticlesCollisionInstance> particles_collision_instance_owner;
  679. /* FOG VOLUMES */
  680. struct FogVolume {
  681. RID material;
  682. Vector3 extents = Vector3(1, 1, 1);
  683. RS::FogVolumeShape shape = RS::FOG_VOLUME_SHAPE_BOX;
  684. Dependency dependency;
  685. };
  686. mutable RID_Owner<FogVolume, true> fog_volume_owner;
  687. /* visibility_notifier */
  688. struct VisibilityNotifier {
  689. AABB aabb;
  690. Callable enter_callback;
  691. Callable exit_callback;
  692. Dependency dependency;
  693. };
  694. mutable RID_Owner<VisibilityNotifier> visibility_notifier_owner;
  695. /* Skeleton */
  696. struct Skeleton {
  697. bool use_2d = false;
  698. int size = 0;
  699. Vector<float> data;
  700. RID buffer;
  701. bool dirty = false;
  702. Skeleton *dirty_list = nullptr;
  703. Transform2D base_transform_2d;
  704. RID uniform_set_3d;
  705. RID uniform_set_mi;
  706. uint64_t version = 1;
  707. Dependency dependency;
  708. };
  709. mutable RID_Owner<Skeleton, true> skeleton_owner;
  710. _FORCE_INLINE_ void _skeleton_make_dirty(Skeleton *skeleton);
  711. Skeleton *skeleton_dirty_list = nullptr;
  712. void _update_dirty_skeletons();
  713. /* LIGHT */
  714. struct Light {
  715. RS::LightType type;
  716. float param[RS::LIGHT_PARAM_MAX];
  717. Color color = Color(1, 1, 1, 1);
  718. RID projector;
  719. bool shadow = false;
  720. bool negative = false;
  721. bool reverse_cull = false;
  722. RS::LightBakeMode bake_mode = RS::LIGHT_BAKE_DYNAMIC;
  723. uint32_t max_sdfgi_cascade = 2;
  724. uint32_t cull_mask = 0xFFFFFFFF;
  725. bool distance_fade = false;
  726. real_t distance_fade_begin = 40.0;
  727. real_t distance_fade_shadow = 50.0;
  728. real_t distance_fade_length = 10.0;
  729. RS::LightOmniShadowMode omni_shadow_mode = RS::LIGHT_OMNI_SHADOW_DUAL_PARABOLOID;
  730. RS::LightDirectionalShadowMode directional_shadow_mode = RS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL;
  731. bool directional_blend_splits = false;
  732. RS::LightDirectionalSkyMode directional_sky_mode = RS::LIGHT_DIRECTIONAL_SKY_MODE_LIGHT_AND_SKY;
  733. uint64_t version = 0;
  734. Dependency dependency;
  735. };
  736. mutable RID_Owner<Light, true> light_owner;
  737. /* REFLECTION PROBE */
  738. struct ReflectionProbe {
  739. RS::ReflectionProbeUpdateMode update_mode = RS::REFLECTION_PROBE_UPDATE_ONCE;
  740. int resolution = 256;
  741. float intensity = 1.0;
  742. RS::ReflectionProbeAmbientMode ambient_mode = RS::REFLECTION_PROBE_AMBIENT_ENVIRONMENT;
  743. Color ambient_color;
  744. float ambient_color_energy = 1.0;
  745. float max_distance = 0;
  746. Vector3 extents = Vector3(1, 1, 1);
  747. Vector3 origin_offset;
  748. bool interior = false;
  749. bool box_projection = false;
  750. bool enable_shadows = false;
  751. uint32_t cull_mask = (1 << 20) - 1;
  752. float mesh_lod_threshold = 0.01;
  753. Dependency dependency;
  754. };
  755. mutable RID_Owner<ReflectionProbe, true> reflection_probe_owner;
  756. /* DECAL */
  757. struct Decal {
  758. Vector3 extents = Vector3(1, 1, 1);
  759. RID textures[RS::DECAL_TEXTURE_MAX];
  760. float emission_energy = 1.0;
  761. float albedo_mix = 1.0;
  762. Color modulate = Color(1, 1, 1, 1);
  763. uint32_t cull_mask = (1 << 20) - 1;
  764. float upper_fade = 0.3;
  765. float lower_fade = 0.3;
  766. bool distance_fade = false;
  767. float distance_fade_begin = 10;
  768. float distance_fade_length = 1;
  769. float normal_fade = 0.0;
  770. Dependency dependency;
  771. };
  772. mutable RID_Owner<Decal, true> decal_owner;
  773. /* VOXEL GI */
  774. struct VoxelGI {
  775. RID octree_buffer;
  776. RID data_buffer;
  777. RID sdf_texture;
  778. uint32_t octree_buffer_size = 0;
  779. uint32_t data_buffer_size = 0;
  780. Vector<int> level_counts;
  781. int cell_count = 0;
  782. Transform3D to_cell_xform;
  783. AABB bounds;
  784. Vector3i octree_size;
  785. float dynamic_range = 2.0;
  786. float energy = 1.0;
  787. float bias = 1.4;
  788. float normal_bias = 0.0;
  789. float propagation = 0.7;
  790. bool interior = false;
  791. bool use_two_bounces = false;
  792. float anisotropy_strength = 0.5;
  793. uint32_t version = 1;
  794. uint32_t data_version = 1;
  795. Dependency dependency;
  796. };
  797. mutable RID_Owner<VoxelGI, true> voxel_gi_owner;
  798. /* REFLECTION PROBE */
  799. struct Lightmap {
  800. RID light_texture;
  801. bool uses_spherical_harmonics = false;
  802. bool interior = false;
  803. AABB bounds = AABB(Vector3(), Vector3(1, 1, 1));
  804. int32_t array_index = -1; //unassigned
  805. PackedVector3Array points;
  806. PackedColorArray point_sh;
  807. PackedInt32Array tetrahedra;
  808. PackedInt32Array bsp_tree;
  809. struct BSP {
  810. static const int32_t EMPTY_LEAF = INT32_MIN;
  811. float plane[4];
  812. int32_t over = EMPTY_LEAF, under = EMPTY_LEAF;
  813. };
  814. Dependency dependency;
  815. };
  816. bool using_lightmap_array; //high end uses this
  817. /* for high end */
  818. Vector<RID> lightmap_textures;
  819. uint64_t lightmap_array_version = 0;
  820. mutable RID_Owner<Lightmap, true> lightmap_owner;
  821. float lightmap_probe_capture_update_speed = 4;
  822. /* RENDER TARGET */
  823. struct RenderTarget {
  824. Size2i size;
  825. uint32_t view_count;
  826. RID framebuffer;
  827. RID color;
  828. //used for retrieving from CPU
  829. RD::DataFormat color_format = RD::DATA_FORMAT_R4G4_UNORM_PACK8;
  830. RD::DataFormat color_format_srgb = RD::DATA_FORMAT_R4G4_UNORM_PACK8;
  831. Image::Format image_format = Image::FORMAT_L8;
  832. bool flags[RENDER_TARGET_FLAG_MAX];
  833. bool sdf_enabled = false;
  834. RID backbuffer; //used for effects
  835. RID backbuffer_fb;
  836. RID backbuffer_mipmap0;
  837. Vector<RID> backbuffer_mipmaps;
  838. RID framebuffer_uniform_set;
  839. RID backbuffer_uniform_set;
  840. RID sdf_buffer_write;
  841. RID sdf_buffer_write_fb;
  842. RID sdf_buffer_process[2];
  843. RID sdf_buffer_read;
  844. RID sdf_buffer_process_uniform_sets[2];
  845. RS::ViewportSDFOversize sdf_oversize = RS::VIEWPORT_SDF_OVERSIZE_120_PERCENT;
  846. RS::ViewportSDFScale sdf_scale = RS::VIEWPORT_SDF_SCALE_50_PERCENT;
  847. Size2i process_size;
  848. //texture generated for this owner (nor RD).
  849. RID texture;
  850. bool was_used;
  851. //clear request
  852. bool clear_requested;
  853. Color clear_color;
  854. };
  855. mutable RID_Owner<RenderTarget> render_target_owner;
  856. void _clear_render_target(RenderTarget *rt);
  857. void _update_render_target(RenderTarget *rt);
  858. void _create_render_target_backbuffer(RenderTarget *rt);
  859. void _render_target_allocate_sdf(RenderTarget *rt);
  860. void _render_target_clear_sdf(RenderTarget *rt);
  861. Rect2i _render_target_get_sdf_rect(const RenderTarget *rt) const;
  862. struct RenderTargetSDF {
  863. enum {
  864. SHADER_LOAD,
  865. SHADER_LOAD_SHRINK,
  866. SHADER_PROCESS,
  867. SHADER_PROCESS_OPTIMIZED,
  868. SHADER_STORE,
  869. SHADER_STORE_SHRINK,
  870. SHADER_MAX
  871. };
  872. struct PushConstant {
  873. int32_t size[2];
  874. int32_t stride;
  875. int32_t shift;
  876. int32_t base_size[2];
  877. int32_t pad[2];
  878. };
  879. CanvasSdfShaderRD shader;
  880. RID shader_version;
  881. RID pipelines[SHADER_MAX];
  882. } rt_sdf;
  883. /* GLOBAL SHADER VARIABLES */
  884. struct GlobalVariables {
  885. enum {
  886. BUFFER_DIRTY_REGION_SIZE = 1024
  887. };
  888. struct Variable {
  889. Set<RID> texture_materials; // materials using this
  890. RS::GlobalVariableType type;
  891. Variant value;
  892. Variant override;
  893. int32_t buffer_index; //for vectors
  894. int32_t buffer_elements; //for vectors
  895. };
  896. HashMap<StringName, Variable> variables;
  897. struct Value {
  898. float x;
  899. float y;
  900. float z;
  901. float w;
  902. };
  903. struct ValueInt {
  904. int32_t x;
  905. int32_t y;
  906. int32_t z;
  907. int32_t w;
  908. };
  909. struct ValueUInt {
  910. uint32_t x;
  911. uint32_t y;
  912. uint32_t z;
  913. uint32_t w;
  914. };
  915. struct ValueUsage {
  916. uint32_t elements = 0;
  917. };
  918. List<RID> materials_using_buffer;
  919. List<RID> materials_using_texture;
  920. RID buffer;
  921. Value *buffer_values;
  922. ValueUsage *buffer_usage;
  923. bool *buffer_dirty_regions;
  924. uint32_t buffer_dirty_region_count = 0;
  925. uint32_t buffer_size;
  926. bool must_update_texture_materials = false;
  927. bool must_update_buffer_materials = false;
  928. HashMap<RID, int32_t> instance_buffer_pos;
  929. } global_variables;
  930. int32_t _global_variable_allocate(uint32_t p_elements);
  931. void _global_variable_store_in_buffer(int32_t p_index, RS::GlobalVariableType p_type, const Variant &p_value);
  932. void _global_variable_mark_buffer_dirty(int32_t p_index, int32_t p_elements);
  933. void _update_global_variables();
  934. /* EFFECTS */
  935. EffectsRD *effects = nullptr;
  936. public:
  937. RID decal_atlas_get_texture() const;
  938. RID decal_atlas_get_texture_srgb() const;
  939. _FORCE_INLINE_ Rect2 decal_atlas_get_texture_rect(RID p_texture) {
  940. DecalAtlas::Texture *t = decal_atlas.textures.getptr(p_texture);
  941. if (!t) {
  942. return Rect2();
  943. }
  944. return t->uv_rect;
  945. }
  946. //internal usage
  947. _FORCE_INLINE_ RID sampler_rd_get_default(RS::CanvasItemTextureFilter p_filter, RS::CanvasItemTextureRepeat p_repeat) {
  948. return default_rd_samplers[p_filter][p_repeat];
  949. }
  950. _FORCE_INLINE_ RID sampler_rd_get_custom(RS::CanvasItemTextureFilter p_filter, RS::CanvasItemTextureRepeat p_repeat) {
  951. return custom_rd_samplers[p_filter][p_repeat];
  952. }
  953. void sampler_rd_configure_custom(float mipmap_bias);
  954. void sampler_rd_set_default(float p_mipmap_bias);
  955. /* SHADER API */
  956. RID shader_allocate();
  957. void shader_initialize(RID p_shader);
  958. void shader_set_code(RID p_shader, const String &p_code);
  959. String shader_get_code(RID p_shader) const;
  960. void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const;
  961. void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture, int p_index);
  962. RID shader_get_default_texture_param(RID p_shader, const StringName &p_name, int p_index) const;
  963. Variant shader_get_param_default(RID p_shader, const StringName &p_param) const;
  964. void shader_set_data_request_function(ShaderType p_shader_type, ShaderDataRequestFunction p_function);
  965. virtual RS::ShaderNativeSourceCode shader_get_native_source_code(RID p_shader) const;
  966. /* COMMON MATERIAL API */
  967. RID material_allocate();
  968. void material_initialize(RID p_material);
  969. void material_set_shader(RID p_material, RID p_shader);
  970. void material_set_param(RID p_material, const StringName &p_param, const Variant &p_value);
  971. Variant material_get_param(RID p_material, const StringName &p_param) const;
  972. void material_set_next_pass(RID p_material, RID p_next_material);
  973. void material_set_render_priority(RID p_material, int priority);
  974. bool material_is_animated(RID p_material);
  975. bool material_casts_shadows(RID p_material);
  976. void material_get_instance_shader_parameters(RID p_material, List<InstanceShaderParam> *r_parameters);
  977. void material_update_dependency(RID p_material, DependencyTracker *p_instance);
  978. void material_set_data_request_function(ShaderType p_shader_type, MaterialDataRequestFunction p_function);
  979. _FORCE_INLINE_ uint32_t material_get_shader_id(RID p_material) {
  980. Material *material = material_owner.get_or_null(p_material);
  981. return material->shader_id;
  982. }
  983. _FORCE_INLINE_ MaterialData *material_get_data(RID p_material, ShaderType p_shader_type) {
  984. Material *material = material_owner.get_or_null(p_material);
  985. if (!material || material->shader_type != p_shader_type) {
  986. return nullptr;
  987. } else {
  988. return material->data;
  989. }
  990. }
  991. /* MESH API */
  992. RID mesh_allocate();
  993. void mesh_initialize(RID p_mesh);
  994. virtual void mesh_set_blend_shape_count(RID p_mesh, int p_blend_shape_count);
  995. /// Return stride
  996. virtual void mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface);
  997. virtual int mesh_get_blend_shape_count(RID p_mesh) const;
  998. virtual void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode);
  999. virtual RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const;
  1000. virtual void mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data);
  1001. virtual void mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data);
  1002. virtual void mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data);
  1003. virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material);
  1004. virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const;
  1005. virtual RS::SurfaceData mesh_get_surface(RID p_mesh, int p_surface) const;
  1006. virtual int mesh_get_surface_count(RID p_mesh) const;
  1007. virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb);
  1008. virtual AABB mesh_get_custom_aabb(RID p_mesh) const;
  1009. virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID());
  1010. virtual void mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh);
  1011. virtual void mesh_clear(RID p_mesh);
  1012. virtual bool mesh_needs_instance(RID p_mesh, bool p_has_skeleton);
  1013. /* MESH INSTANCE */
  1014. virtual RID mesh_instance_create(RID p_base);
  1015. virtual void mesh_instance_set_skeleton(RID p_mesh_instance, RID p_skeleton);
  1016. virtual void mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int p_shape, float p_weight);
  1017. virtual void mesh_instance_check_for_update(RID p_mesh_instance);
  1018. virtual void update_mesh_instances();
  1019. _FORCE_INLINE_ const RID *mesh_get_surface_count_and_materials(RID p_mesh, uint32_t &r_surface_count) {
  1020. Mesh *mesh = mesh_owner.get_or_null(p_mesh);
  1021. ERR_FAIL_COND_V(!mesh, nullptr);
  1022. r_surface_count = mesh->surface_count;
  1023. if (r_surface_count == 0) {
  1024. return nullptr;
  1025. }
  1026. if (mesh->material_cache.is_empty()) {
  1027. mesh->material_cache.resize(mesh->surface_count);
  1028. for (uint32_t i = 0; i < r_surface_count; i++) {
  1029. mesh->material_cache.write[i] = mesh->surfaces[i]->material;
  1030. }
  1031. }
  1032. return mesh->material_cache.ptr();
  1033. }
  1034. _FORCE_INLINE_ void *mesh_get_surface(RID p_mesh, uint32_t p_surface_index) {
  1035. Mesh *mesh = mesh_owner.get_or_null(p_mesh);
  1036. ERR_FAIL_COND_V(!mesh, nullptr);
  1037. ERR_FAIL_UNSIGNED_INDEX_V(p_surface_index, mesh->surface_count, nullptr);
  1038. return mesh->surfaces[p_surface_index];
  1039. }
  1040. _FORCE_INLINE_ RID mesh_get_shadow_mesh(RID p_mesh) {
  1041. Mesh *mesh = mesh_owner.get_or_null(p_mesh);
  1042. ERR_FAIL_COND_V(!mesh, RID());
  1043. return mesh->shadow_mesh;
  1044. }
  1045. _FORCE_INLINE_ RS::PrimitiveType mesh_surface_get_primitive(void *p_surface) {
  1046. Mesh::Surface *surface = reinterpret_cast<Mesh::Surface *>(p_surface);
  1047. return surface->primitive;
  1048. }
  1049. _FORCE_INLINE_ bool mesh_surface_has_lod(void *p_surface) const {
  1050. Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
  1051. return s->lod_count > 0;
  1052. }
  1053. _FORCE_INLINE_ uint32_t mesh_surface_get_vertices_drawn_count(void *p_surface) const {
  1054. Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
  1055. return s->index_count ? s->index_count : s->vertex_count;
  1056. }
  1057. _FORCE_INLINE_ uint32_t mesh_surface_get_lod(void *p_surface, float p_model_scale, float p_distance_threshold, float p_mesh_lod_threshold, uint32_t *r_index_count = nullptr) const {
  1058. Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
  1059. int32_t current_lod = -1;
  1060. if (r_index_count) {
  1061. *r_index_count = s->index_count;
  1062. }
  1063. for (uint32_t i = 0; i < s->lod_count; i++) {
  1064. float screen_size = s->lods[i].edge_length * p_model_scale / p_distance_threshold;
  1065. if (screen_size > p_mesh_lod_threshold) {
  1066. break;
  1067. }
  1068. current_lod = i;
  1069. }
  1070. if (current_lod == -1) {
  1071. return 0;
  1072. } else {
  1073. if (r_index_count) {
  1074. *r_index_count = s->lods[current_lod].index_count;
  1075. }
  1076. return current_lod + 1;
  1077. }
  1078. }
  1079. _FORCE_INLINE_ RID mesh_surface_get_index_array(void *p_surface, uint32_t p_lod) const {
  1080. Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
  1081. if (p_lod == 0) {
  1082. return s->index_array;
  1083. } else {
  1084. return s->lods[p_lod - 1].index_array;
  1085. }
  1086. }
  1087. _FORCE_INLINE_ void mesh_surface_get_vertex_arrays_and_format(void *p_surface, uint32_t p_input_mask, RID &r_vertex_array_rd, RD::VertexFormatID &r_vertex_format) {
  1088. Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
  1089. s->version_lock.lock();
  1090. //there will never be more than, at much, 3 or 4 versions, so iterating is the fastest way
  1091. for (uint32_t i = 0; i < s->version_count; i++) {
  1092. if (s->versions[i].input_mask != p_input_mask) {
  1093. continue;
  1094. }
  1095. //we have this version, hooray
  1096. r_vertex_format = s->versions[i].vertex_format;
  1097. r_vertex_array_rd = s->versions[i].vertex_array;
  1098. s->version_lock.unlock();
  1099. return;
  1100. }
  1101. uint32_t version = s->version_count;
  1102. s->version_count++;
  1103. s->versions = (Mesh::Surface::Version *)memrealloc(s->versions, sizeof(Mesh::Surface::Version) * s->version_count);
  1104. _mesh_surface_generate_version_for_input_mask(s->versions[version], s, p_input_mask);
  1105. r_vertex_format = s->versions[version].vertex_format;
  1106. r_vertex_array_rd = s->versions[version].vertex_array;
  1107. s->version_lock.unlock();
  1108. }
  1109. _FORCE_INLINE_ void mesh_instance_surface_get_vertex_arrays_and_format(RID p_mesh_instance, uint32_t p_surface_index, uint32_t p_input_mask, RID &r_vertex_array_rd, RD::VertexFormatID &r_vertex_format) {
  1110. MeshInstance *mi = mesh_instance_owner.get_or_null(p_mesh_instance);
  1111. ERR_FAIL_COND(!mi);
  1112. Mesh *mesh = mi->mesh;
  1113. ERR_FAIL_UNSIGNED_INDEX(p_surface_index, mesh->surface_count);
  1114. MeshInstance::Surface *mis = &mi->surfaces[p_surface_index];
  1115. Mesh::Surface *s = mesh->surfaces[p_surface_index];
  1116. s->version_lock.lock();
  1117. //there will never be more than, at much, 3 or 4 versions, so iterating is the fastest way
  1118. for (uint32_t i = 0; i < mis->version_count; i++) {
  1119. if (mis->versions[i].input_mask != p_input_mask) {
  1120. continue;
  1121. }
  1122. //we have this version, hooray
  1123. r_vertex_format = mis->versions[i].vertex_format;
  1124. r_vertex_array_rd = mis->versions[i].vertex_array;
  1125. s->version_lock.unlock();
  1126. return;
  1127. }
  1128. uint32_t version = mis->version_count;
  1129. mis->version_count++;
  1130. mis->versions = (Mesh::Surface::Version *)memrealloc(mis->versions, sizeof(Mesh::Surface::Version) * mis->version_count);
  1131. _mesh_surface_generate_version_for_input_mask(mis->versions[version], s, p_input_mask, mis);
  1132. r_vertex_format = mis->versions[version].vertex_format;
  1133. r_vertex_array_rd = mis->versions[version].vertex_array;
  1134. s->version_lock.unlock();
  1135. }
  1136. _FORCE_INLINE_ RID mesh_get_default_rd_buffer(DefaultRDBuffer p_buffer) {
  1137. ERR_FAIL_INDEX_V(p_buffer, DEFAULT_RD_BUFFER_MAX, RID());
  1138. return mesh_default_rd_buffers[p_buffer];
  1139. }
  1140. _FORCE_INLINE_ uint32_t mesh_surface_get_render_pass_index(RID p_mesh, uint32_t p_surface_index, uint64_t p_render_pass, uint32_t *r_index) {
  1141. Mesh *mesh = mesh_owner.get_or_null(p_mesh);
  1142. Mesh::Surface *s = mesh->surfaces[p_surface_index];
  1143. if (s->render_pass != p_render_pass) {
  1144. (*r_index)++;
  1145. s->render_pass = p_render_pass;
  1146. s->render_index = *r_index;
  1147. }
  1148. return s->render_index;
  1149. }
  1150. _FORCE_INLINE_ uint32_t mesh_surface_get_multimesh_render_pass_index(RID p_mesh, uint32_t p_surface_index, uint64_t p_render_pass, uint32_t *r_index) {
  1151. Mesh *mesh = mesh_owner.get_or_null(p_mesh);
  1152. Mesh::Surface *s = mesh->surfaces[p_surface_index];
  1153. if (s->multimesh_render_pass != p_render_pass) {
  1154. (*r_index)++;
  1155. s->multimesh_render_pass = p_render_pass;
  1156. s->multimesh_render_index = *r_index;
  1157. }
  1158. return s->multimesh_render_index;
  1159. }
  1160. _FORCE_INLINE_ uint32_t mesh_surface_get_particles_render_pass_index(RID p_mesh, uint32_t p_surface_index, uint64_t p_render_pass, uint32_t *r_index) {
  1161. Mesh *mesh = mesh_owner.get_or_null(p_mesh);
  1162. Mesh::Surface *s = mesh->surfaces[p_surface_index];
  1163. if (s->particles_render_pass != p_render_pass) {
  1164. (*r_index)++;
  1165. s->particles_render_pass = p_render_pass;
  1166. s->particles_render_index = *r_index;
  1167. }
  1168. return s->particles_render_index;
  1169. }
  1170. /* MULTIMESH API */
  1171. RID multimesh_allocate();
  1172. void multimesh_initialize(RID p_multimesh);
  1173. void multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false);
  1174. int multimesh_get_instance_count(RID p_multimesh) const;
  1175. void multimesh_set_mesh(RID p_multimesh, RID p_mesh);
  1176. void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform);
  1177. void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform);
  1178. void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color);
  1179. void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color);
  1180. RID multimesh_get_mesh(RID p_multimesh) const;
  1181. Transform3D multimesh_instance_get_transform(RID p_multimesh, int p_index) const;
  1182. Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const;
  1183. Color multimesh_instance_get_color(RID p_multimesh, int p_index) const;
  1184. Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const;
  1185. void multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer);
  1186. Vector<float> multimesh_get_buffer(RID p_multimesh) const;
  1187. void multimesh_set_visible_instances(RID p_multimesh, int p_visible);
  1188. int multimesh_get_visible_instances(RID p_multimesh) const;
  1189. AABB multimesh_get_aabb(RID p_multimesh) const;
  1190. _FORCE_INLINE_ RS::MultimeshTransformFormat multimesh_get_transform_format(RID p_multimesh) const {
  1191. MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
  1192. return multimesh->xform_format;
  1193. }
  1194. _FORCE_INLINE_ bool multimesh_uses_colors(RID p_multimesh) const {
  1195. MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
  1196. return multimesh->uses_colors;
  1197. }
  1198. _FORCE_INLINE_ bool multimesh_uses_custom_data(RID p_multimesh) const {
  1199. MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
  1200. return multimesh->uses_custom_data;
  1201. }
  1202. _FORCE_INLINE_ uint32_t multimesh_get_instances_to_draw(RID p_multimesh) const {
  1203. MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
  1204. if (multimesh->visible_instances >= 0) {
  1205. return multimesh->visible_instances;
  1206. }
  1207. return multimesh->instances;
  1208. }
  1209. _FORCE_INLINE_ RID multimesh_get_3d_uniform_set(RID p_multimesh, RID p_shader, uint32_t p_set) const {
  1210. MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
  1211. if (!multimesh->uniform_set_3d.is_valid()) {
  1212. Vector<RD::Uniform> uniforms;
  1213. RD::Uniform u;
  1214. u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
  1215. u.binding = 0;
  1216. u.append_id(multimesh->buffer);
  1217. uniforms.push_back(u);
  1218. multimesh->uniform_set_3d = RD::get_singleton()->uniform_set_create(uniforms, p_shader, p_set);
  1219. }
  1220. return multimesh->uniform_set_3d;
  1221. }
  1222. _FORCE_INLINE_ RID multimesh_get_2d_uniform_set(RID p_multimesh, RID p_shader, uint32_t p_set) const {
  1223. MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
  1224. if (!multimesh->uniform_set_2d.is_valid()) {
  1225. Vector<RD::Uniform> uniforms;
  1226. RD::Uniform u;
  1227. u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
  1228. u.binding = 0;
  1229. u.append_id(multimesh->buffer);
  1230. uniforms.push_back(u);
  1231. multimesh->uniform_set_2d = RD::get_singleton()->uniform_set_create(uniforms, p_shader, p_set);
  1232. }
  1233. return multimesh->uniform_set_2d;
  1234. }
  1235. /* SKELETON API */
  1236. RID skeleton_allocate();
  1237. void skeleton_initialize(RID p_skeleton);
  1238. void skeleton_allocate_data(RID p_skeleton, int p_bones, bool p_2d_skeleton = false);
  1239. void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform);
  1240. void skeleton_set_world_transform(RID p_skeleton, bool p_enable, const Transform3D &p_world_transform);
  1241. int skeleton_get_bone_count(RID p_skeleton) const;
  1242. void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform3D &p_transform);
  1243. Transform3D skeleton_bone_get_transform(RID p_skeleton, int p_bone) const;
  1244. void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform);
  1245. Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const;
  1246. _FORCE_INLINE_ bool skeleton_is_valid(RID p_skeleton) {
  1247. return skeleton_owner.get_or_null(p_skeleton) != nullptr;
  1248. }
  1249. _FORCE_INLINE_ RID skeleton_get_3d_uniform_set(RID p_skeleton, RID p_shader, uint32_t p_set) const {
  1250. Skeleton *skeleton = skeleton_owner.get_or_null(p_skeleton);
  1251. ERR_FAIL_COND_V(!skeleton, RID());
  1252. ERR_FAIL_COND_V(skeleton->size == 0, RID());
  1253. if (skeleton->use_2d) {
  1254. return RID();
  1255. }
  1256. if (!skeleton->uniform_set_3d.is_valid()) {
  1257. Vector<RD::Uniform> uniforms;
  1258. RD::Uniform u;
  1259. u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
  1260. u.binding = 0;
  1261. u.append_id(skeleton->buffer);
  1262. uniforms.push_back(u);
  1263. skeleton->uniform_set_3d = RD::get_singleton()->uniform_set_create(uniforms, p_shader, p_set);
  1264. }
  1265. return skeleton->uniform_set_3d;
  1266. }
  1267. /* Light API */
  1268. void _light_initialize(RID p_rid, RS::LightType p_type);
  1269. RID directional_light_allocate();
  1270. void directional_light_initialize(RID p_light);
  1271. RID omni_light_allocate();
  1272. void omni_light_initialize(RID p_light);
  1273. RID spot_light_allocate();
  1274. void spot_light_initialize(RID p_light);
  1275. void light_set_color(RID p_light, const Color &p_color);
  1276. void light_set_param(RID p_light, RS::LightParam p_param, float p_value);
  1277. void light_set_shadow(RID p_light, bool p_enabled);
  1278. void light_set_projector(RID p_light, RID p_texture);
  1279. void light_set_negative(RID p_light, bool p_enable);
  1280. void light_set_cull_mask(RID p_light, uint32_t p_mask);
  1281. void light_set_distance_fade(RID p_light, bool p_enabled, float p_begin, float p_shadow, float p_length);
  1282. void light_set_reverse_cull_face_mode(RID p_light, bool p_enabled);
  1283. void light_set_bake_mode(RID p_light, RS::LightBakeMode p_bake_mode);
  1284. void light_set_max_sdfgi_cascade(RID p_light, uint32_t p_cascade);
  1285. void light_omni_set_shadow_mode(RID p_light, RS::LightOmniShadowMode p_mode);
  1286. void light_directional_set_shadow_mode(RID p_light, RS::LightDirectionalShadowMode p_mode);
  1287. void light_directional_set_blend_splits(RID p_light, bool p_enable);
  1288. bool light_directional_get_blend_splits(RID p_light) const;
  1289. void light_directional_set_sky_mode(RID p_light, RS::LightDirectionalSkyMode p_mode);
  1290. RS::LightDirectionalSkyMode light_directional_get_sky_mode(RID p_light) const;
  1291. RS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light);
  1292. RS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light);
  1293. _FORCE_INLINE_ RS::LightType light_get_type(RID p_light) const {
  1294. const Light *light = light_owner.get_or_null(p_light);
  1295. ERR_FAIL_COND_V(!light, RS::LIGHT_DIRECTIONAL);
  1296. return light->type;
  1297. }
  1298. AABB light_get_aabb(RID p_light) const;
  1299. _FORCE_INLINE_ float light_get_param(RID p_light, RS::LightParam p_param) {
  1300. const Light *light = light_owner.get_or_null(p_light);
  1301. ERR_FAIL_COND_V(!light, 0);
  1302. return light->param[p_param];
  1303. }
  1304. _FORCE_INLINE_ RID light_get_projector(RID p_light) {
  1305. const Light *light = light_owner.get_or_null(p_light);
  1306. ERR_FAIL_COND_V(!light, RID());
  1307. return light->projector;
  1308. }
  1309. _FORCE_INLINE_ Color light_get_color(RID p_light) {
  1310. const Light *light = light_owner.get_or_null(p_light);
  1311. ERR_FAIL_COND_V(!light, Color());
  1312. return light->color;
  1313. }
  1314. _FORCE_INLINE_ uint32_t light_get_cull_mask(RID p_light) {
  1315. const Light *light = light_owner.get_or_null(p_light);
  1316. ERR_FAIL_COND_V(!light, 0);
  1317. return light->cull_mask;
  1318. }
  1319. _FORCE_INLINE_ bool light_is_distance_fade_enabled(RID p_light) {
  1320. const Light *light = light_owner.get_or_null(p_light);
  1321. return light->distance_fade;
  1322. }
  1323. _FORCE_INLINE_ float light_get_distance_fade_begin(RID p_light) {
  1324. const Light *light = light_owner.get_or_null(p_light);
  1325. return light->distance_fade_begin;
  1326. }
  1327. _FORCE_INLINE_ float light_get_distance_fade_shadow(RID p_light) {
  1328. const Light *light = light_owner.get_or_null(p_light);
  1329. return light->distance_fade_shadow;
  1330. }
  1331. _FORCE_INLINE_ float light_get_distance_fade_length(RID p_light) {
  1332. const Light *light = light_owner.get_or_null(p_light);
  1333. return light->distance_fade_length;
  1334. }
  1335. _FORCE_INLINE_ bool light_has_shadow(RID p_light) const {
  1336. const Light *light = light_owner.get_or_null(p_light);
  1337. ERR_FAIL_COND_V(!light, RS::LIGHT_DIRECTIONAL);
  1338. return light->shadow;
  1339. }
  1340. _FORCE_INLINE_ bool light_has_projector(RID p_light) const {
  1341. const Light *light = light_owner.get_or_null(p_light);
  1342. ERR_FAIL_COND_V(!light, RS::LIGHT_DIRECTIONAL);
  1343. return light_owner.owns(light->projector);
  1344. }
  1345. _FORCE_INLINE_ bool light_is_negative(RID p_light) const {
  1346. const Light *light = light_owner.get_or_null(p_light);
  1347. ERR_FAIL_COND_V(!light, RS::LIGHT_DIRECTIONAL);
  1348. return light->negative;
  1349. }
  1350. _FORCE_INLINE_ float light_get_transmittance_bias(RID p_light) const {
  1351. const Light *light = light_owner.get_or_null(p_light);
  1352. ERR_FAIL_COND_V(!light, 0.0);
  1353. return light->param[RS::LIGHT_PARAM_TRANSMITTANCE_BIAS];
  1354. }
  1355. _FORCE_INLINE_ float light_get_shadow_volumetric_fog_fade(RID p_light) const {
  1356. const Light *light = light_owner.get_or_null(p_light);
  1357. ERR_FAIL_COND_V(!light, 0.0);
  1358. return light->param[RS::LIGHT_PARAM_SHADOW_VOLUMETRIC_FOG_FADE];
  1359. }
  1360. RS::LightBakeMode light_get_bake_mode(RID p_light);
  1361. uint32_t light_get_max_sdfgi_cascade(RID p_light);
  1362. uint64_t light_get_version(RID p_light) const;
  1363. /* PROBE API */
  1364. RID reflection_probe_allocate();
  1365. void reflection_probe_initialize(RID p_reflection_probe);
  1366. void reflection_probe_set_update_mode(RID p_probe, RS::ReflectionProbeUpdateMode p_mode);
  1367. void reflection_probe_set_intensity(RID p_probe, float p_intensity);
  1368. void reflection_probe_set_ambient_mode(RID p_probe, RS::ReflectionProbeAmbientMode p_mode);
  1369. void reflection_probe_set_ambient_color(RID p_probe, const Color &p_color);
  1370. void reflection_probe_set_ambient_energy(RID p_probe, float p_energy);
  1371. void reflection_probe_set_max_distance(RID p_probe, float p_distance);
  1372. void reflection_probe_set_extents(RID p_probe, const Vector3 &p_extents);
  1373. void reflection_probe_set_origin_offset(RID p_probe, const Vector3 &p_offset);
  1374. void reflection_probe_set_as_interior(RID p_probe, bool p_enable);
  1375. void reflection_probe_set_enable_box_projection(RID p_probe, bool p_enable);
  1376. void reflection_probe_set_enable_shadows(RID p_probe, bool p_enable);
  1377. void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers);
  1378. void reflection_probe_set_resolution(RID p_probe, int p_resolution);
  1379. void reflection_probe_set_mesh_lod_threshold(RID p_probe, float p_ratio);
  1380. AABB reflection_probe_get_aabb(RID p_probe) const;
  1381. RS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const;
  1382. uint32_t reflection_probe_get_cull_mask(RID p_probe) const;
  1383. Vector3 reflection_probe_get_extents(RID p_probe) const;
  1384. Vector3 reflection_probe_get_origin_offset(RID p_probe) const;
  1385. float reflection_probe_get_origin_max_distance(RID p_probe) const;
  1386. float reflection_probe_get_mesh_lod_threshold(RID p_probe) const;
  1387. int reflection_probe_get_resolution(RID p_probe) const;
  1388. bool reflection_probe_renders_shadows(RID p_probe) const;
  1389. float reflection_probe_get_intensity(RID p_probe) const;
  1390. bool reflection_probe_is_interior(RID p_probe) const;
  1391. bool reflection_probe_is_box_projection(RID p_probe) const;
  1392. RS::ReflectionProbeAmbientMode reflection_probe_get_ambient_mode(RID p_probe) const;
  1393. Color reflection_probe_get_ambient_color(RID p_probe) const;
  1394. float reflection_probe_get_ambient_color_energy(RID p_probe) const;
  1395. void base_update_dependency(RID p_base, DependencyTracker *p_instance);
  1396. void skeleton_update_dependency(RID p_skeleton, DependencyTracker *p_instance);
  1397. /* DECAL API */
  1398. RID decal_allocate();
  1399. void decal_initialize(RID p_decal);
  1400. virtual void decal_set_extents(RID p_decal, const Vector3 &p_extents);
  1401. virtual void decal_set_texture(RID p_decal, RS::DecalTexture p_type, RID p_texture);
  1402. virtual void decal_set_emission_energy(RID p_decal, float p_energy);
  1403. virtual void decal_set_albedo_mix(RID p_decal, float p_mix);
  1404. virtual void decal_set_modulate(RID p_decal, const Color &p_modulate);
  1405. virtual void decal_set_cull_mask(RID p_decal, uint32_t p_layers);
  1406. virtual void decal_set_distance_fade(RID p_decal, bool p_enabled, float p_begin, float p_length);
  1407. virtual void decal_set_fade(RID p_decal, float p_above, float p_below);
  1408. virtual void decal_set_normal_fade(RID p_decal, float p_fade);
  1409. void decal_atlas_mark_dirty_on_texture(RID p_texture);
  1410. void decal_atlas_remove_texture(RID p_texture);
  1411. virtual void texture_add_to_decal_atlas(RID p_texture, bool p_panorama_to_dp = false);
  1412. virtual void texture_remove_from_decal_atlas(RID p_texture, bool p_panorama_to_dp = false);
  1413. _FORCE_INLINE_ Vector3 decal_get_extents(RID p_decal) {
  1414. const Decal *decal = decal_owner.get_or_null(p_decal);
  1415. return decal->extents;
  1416. }
  1417. _FORCE_INLINE_ RID decal_get_texture(RID p_decal, RS::DecalTexture p_texture) {
  1418. const Decal *decal = decal_owner.get_or_null(p_decal);
  1419. return decal->textures[p_texture];
  1420. }
  1421. _FORCE_INLINE_ Color decal_get_modulate(RID p_decal) {
  1422. const Decal *decal = decal_owner.get_or_null(p_decal);
  1423. return decal->modulate;
  1424. }
  1425. _FORCE_INLINE_ float decal_get_emission_energy(RID p_decal) {
  1426. const Decal *decal = decal_owner.get_or_null(p_decal);
  1427. return decal->emission_energy;
  1428. }
  1429. _FORCE_INLINE_ float decal_get_albedo_mix(RID p_decal) {
  1430. const Decal *decal = decal_owner.get_or_null(p_decal);
  1431. return decal->albedo_mix;
  1432. }
  1433. _FORCE_INLINE_ uint32_t decal_get_cull_mask(RID p_decal) {
  1434. const Decal *decal = decal_owner.get_or_null(p_decal);
  1435. return decal->cull_mask;
  1436. }
  1437. _FORCE_INLINE_ float decal_get_upper_fade(RID p_decal) {
  1438. const Decal *decal = decal_owner.get_or_null(p_decal);
  1439. return decal->upper_fade;
  1440. }
  1441. _FORCE_INLINE_ float decal_get_lower_fade(RID p_decal) {
  1442. const Decal *decal = decal_owner.get_or_null(p_decal);
  1443. return decal->lower_fade;
  1444. }
  1445. _FORCE_INLINE_ float decal_get_normal_fade(RID p_decal) {
  1446. const Decal *decal = decal_owner.get_or_null(p_decal);
  1447. return decal->normal_fade;
  1448. }
  1449. _FORCE_INLINE_ bool decal_is_distance_fade_enabled(RID p_decal) {
  1450. const Decal *decal = decal_owner.get_or_null(p_decal);
  1451. return decal->distance_fade;
  1452. }
  1453. _FORCE_INLINE_ float decal_get_distance_fade_begin(RID p_decal) {
  1454. const Decal *decal = decal_owner.get_or_null(p_decal);
  1455. return decal->distance_fade_begin;
  1456. }
  1457. _FORCE_INLINE_ float decal_get_distance_fade_length(RID p_decal) {
  1458. const Decal *decal = decal_owner.get_or_null(p_decal);
  1459. return decal->distance_fade_length;
  1460. }
  1461. virtual AABB decal_get_aabb(RID p_decal) const;
  1462. /* VOXEL GI API */
  1463. RID voxel_gi_allocate();
  1464. void voxel_gi_initialize(RID p_voxel_gi);
  1465. void voxel_gi_allocate_data(RID p_voxel_gi, const Transform3D &p_to_cell_xform, const AABB &p_aabb, const Vector3i &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts);
  1466. AABB voxel_gi_get_bounds(RID p_voxel_gi) const;
  1467. Vector3i voxel_gi_get_octree_size(RID p_voxel_gi) const;
  1468. Vector<uint8_t> voxel_gi_get_octree_cells(RID p_voxel_gi) const;
  1469. Vector<uint8_t> voxel_gi_get_data_cells(RID p_voxel_gi) const;
  1470. Vector<uint8_t> voxel_gi_get_distance_field(RID p_voxel_gi) const;
  1471. Vector<int> voxel_gi_get_level_counts(RID p_voxel_gi) const;
  1472. Transform3D voxel_gi_get_to_cell_xform(RID p_voxel_gi) const;
  1473. void voxel_gi_set_dynamic_range(RID p_voxel_gi, float p_range);
  1474. float voxel_gi_get_dynamic_range(RID p_voxel_gi) const;
  1475. void voxel_gi_set_propagation(RID p_voxel_gi, float p_range);
  1476. float voxel_gi_get_propagation(RID p_voxel_gi) const;
  1477. void voxel_gi_set_energy(RID p_voxel_gi, float p_energy);
  1478. float voxel_gi_get_energy(RID p_voxel_gi) const;
  1479. void voxel_gi_set_bias(RID p_voxel_gi, float p_bias);
  1480. float voxel_gi_get_bias(RID p_voxel_gi) const;
  1481. void voxel_gi_set_normal_bias(RID p_voxel_gi, float p_range);
  1482. float voxel_gi_get_normal_bias(RID p_voxel_gi) const;
  1483. void voxel_gi_set_interior(RID p_voxel_gi, bool p_enable);
  1484. bool voxel_gi_is_interior(RID p_voxel_gi) const;
  1485. void voxel_gi_set_use_two_bounces(RID p_voxel_gi, bool p_enable);
  1486. bool voxel_gi_is_using_two_bounces(RID p_voxel_gi) const;
  1487. void voxel_gi_set_anisotropy_strength(RID p_voxel_gi, float p_strength);
  1488. float voxel_gi_get_anisotropy_strength(RID p_voxel_gi) const;
  1489. uint32_t voxel_gi_get_version(RID p_probe);
  1490. uint32_t voxel_gi_get_data_version(RID p_probe);
  1491. RID voxel_gi_get_octree_buffer(RID p_voxel_gi) const;
  1492. RID voxel_gi_get_data_buffer(RID p_voxel_gi) const;
  1493. RID voxel_gi_get_sdf_texture(RID p_voxel_gi);
  1494. /* LIGHTMAP CAPTURE */
  1495. RID lightmap_allocate();
  1496. void lightmap_initialize(RID p_lightmap);
  1497. virtual void lightmap_set_textures(RID p_lightmap, RID p_light, bool p_uses_spherical_haromics);
  1498. virtual void lightmap_set_probe_bounds(RID p_lightmap, const AABB &p_bounds);
  1499. virtual void lightmap_set_probe_interior(RID p_lightmap, bool p_interior);
  1500. virtual void lightmap_set_probe_capture_data(RID p_lightmap, const PackedVector3Array &p_points, const PackedColorArray &p_point_sh, const PackedInt32Array &p_tetrahedra, const PackedInt32Array &p_bsp_tree);
  1501. virtual PackedVector3Array lightmap_get_probe_capture_points(RID p_lightmap) const;
  1502. virtual PackedColorArray lightmap_get_probe_capture_sh(RID p_lightmap) const;
  1503. virtual PackedInt32Array lightmap_get_probe_capture_tetrahedra(RID p_lightmap) const;
  1504. virtual PackedInt32Array lightmap_get_probe_capture_bsp_tree(RID p_lightmap) const;
  1505. virtual AABB lightmap_get_aabb(RID p_lightmap) const;
  1506. virtual bool lightmap_is_interior(RID p_lightmap) const;
  1507. virtual void lightmap_tap_sh_light(RID p_lightmap, const Vector3 &p_point, Color *r_sh);
  1508. virtual void lightmap_set_probe_capture_update_speed(float p_speed);
  1509. _FORCE_INLINE_ float lightmap_get_probe_capture_update_speed() const {
  1510. return lightmap_probe_capture_update_speed;
  1511. }
  1512. _FORCE_INLINE_ RID lightmap_get_texture(RID p_lightmap) const {
  1513. const Lightmap *lm = lightmap_owner.get_or_null(p_lightmap);
  1514. ERR_FAIL_COND_V(!lm, RID());
  1515. return lm->light_texture;
  1516. }
  1517. _FORCE_INLINE_ int32_t lightmap_get_array_index(RID p_lightmap) const {
  1518. ERR_FAIL_COND_V(!using_lightmap_array, -1); //only for arrays
  1519. const Lightmap *lm = lightmap_owner.get_or_null(p_lightmap);
  1520. return lm->array_index;
  1521. }
  1522. _FORCE_INLINE_ bool lightmap_uses_spherical_harmonics(RID p_lightmap) const {
  1523. ERR_FAIL_COND_V(!using_lightmap_array, false); //only for arrays
  1524. const Lightmap *lm = lightmap_owner.get_or_null(p_lightmap);
  1525. return lm->uses_spherical_harmonics;
  1526. }
  1527. _FORCE_INLINE_ uint64_t lightmap_array_get_version() const {
  1528. ERR_FAIL_COND_V(!using_lightmap_array, 0); //only for arrays
  1529. return lightmap_array_version;
  1530. }
  1531. _FORCE_INLINE_ int lightmap_array_get_size() const {
  1532. ERR_FAIL_COND_V(!using_lightmap_array, 0); //only for arrays
  1533. return lightmap_textures.size();
  1534. }
  1535. _FORCE_INLINE_ const Vector<RID> &lightmap_array_get_textures() const {
  1536. ERR_FAIL_COND_V(!using_lightmap_array, lightmap_textures); //only for arrays
  1537. return lightmap_textures;
  1538. }
  1539. /* PARTICLES */
  1540. RID particles_allocate();
  1541. void particles_initialize(RID p_particles_collision);
  1542. void particles_set_mode(RID p_particles, RS::ParticlesMode p_mode);
  1543. void particles_set_emitting(RID p_particles, bool p_emitting);
  1544. void particles_set_amount(RID p_particles, int p_amount);
  1545. void particles_set_lifetime(RID p_particles, double p_lifetime);
  1546. void particles_set_one_shot(RID p_particles, bool p_one_shot);
  1547. void particles_set_pre_process_time(RID p_particles, double p_time);
  1548. void particles_set_explosiveness_ratio(RID p_particles, real_t p_ratio);
  1549. void particles_set_randomness_ratio(RID p_particles, real_t p_ratio);
  1550. void particles_set_custom_aabb(RID p_particles, const AABB &p_aabb);
  1551. void particles_set_speed_scale(RID p_particles, double p_scale);
  1552. void particles_set_use_local_coordinates(RID p_particles, bool p_enable);
  1553. void particles_set_process_material(RID p_particles, RID p_material);
  1554. RID particles_get_process_material(RID p_particles) const;
  1555. void particles_set_fixed_fps(RID p_particles, int p_fps);
  1556. void particles_set_interpolate(RID p_particles, bool p_enable);
  1557. void particles_set_fractional_delta(RID p_particles, bool p_enable);
  1558. void particles_set_collision_base_size(RID p_particles, real_t p_size);
  1559. void particles_set_transform_align(RID p_particles, RS::ParticlesTransformAlign p_transform_align);
  1560. void particles_set_trails(RID p_particles, bool p_enable, double p_length);
  1561. void particles_set_trail_bind_poses(RID p_particles, const Vector<Transform3D> &p_bind_poses);
  1562. void particles_restart(RID p_particles);
  1563. void particles_emit(RID p_particles, const Transform3D &p_transform, const Vector3 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags);
  1564. void particles_set_subemitter(RID p_particles, RID p_subemitter_particles);
  1565. void particles_set_draw_order(RID p_particles, RS::ParticlesDrawOrder p_order);
  1566. void particles_set_draw_passes(RID p_particles, int p_count);
  1567. void particles_set_draw_pass_mesh(RID p_particles, int p_pass, RID p_mesh);
  1568. void particles_request_process(RID p_particles);
  1569. AABB particles_get_current_aabb(RID p_particles);
  1570. AABB particles_get_aabb(RID p_particles) const;
  1571. void particles_set_emission_transform(RID p_particles, const Transform3D &p_transform);
  1572. bool particles_get_emitting(RID p_particles);
  1573. int particles_get_draw_passes(RID p_particles) const;
  1574. RID particles_get_draw_pass_mesh(RID p_particles, int p_pass) const;
  1575. void particles_set_view_axis(RID p_particles, const Vector3 &p_axis, const Vector3 &p_up_axis);
  1576. virtual bool particles_is_inactive(RID p_particles) const;
  1577. _FORCE_INLINE_ RS::ParticlesMode particles_get_mode(RID p_particles) {
  1578. Particles *particles = particles_owner.get_or_null(p_particles);
  1579. ERR_FAIL_COND_V(!particles, RS::PARTICLES_MODE_2D);
  1580. return particles->mode;
  1581. }
  1582. _FORCE_INLINE_ uint32_t particles_get_amount(RID p_particles, uint32_t &r_trail_divisor) {
  1583. Particles *particles = particles_owner.get_or_null(p_particles);
  1584. ERR_FAIL_COND_V(!particles, 0);
  1585. if (particles->trails_enabled && particles->trail_bind_poses.size() > 1) {
  1586. r_trail_divisor = particles->trail_bind_poses.size();
  1587. } else {
  1588. r_trail_divisor = 1;
  1589. }
  1590. return particles->amount * r_trail_divisor;
  1591. }
  1592. _FORCE_INLINE_ bool particles_has_collision(RID p_particles) {
  1593. Particles *particles = particles_owner.get_or_null(p_particles);
  1594. ERR_FAIL_COND_V(!particles, 0);
  1595. return particles->has_collision_cache;
  1596. }
  1597. _FORCE_INLINE_ uint32_t particles_is_using_local_coords(RID p_particles) {
  1598. Particles *particles = particles_owner.get_or_null(p_particles);
  1599. ERR_FAIL_COND_V(!particles, false);
  1600. return particles->use_local_coords;
  1601. }
  1602. _FORCE_INLINE_ RID particles_get_instance_buffer_uniform_set(RID p_particles, RID p_shader, uint32_t p_set) {
  1603. Particles *particles = particles_owner.get_or_null(p_particles);
  1604. ERR_FAIL_COND_V(!particles, RID());
  1605. if (particles->particles_transforms_buffer_uniform_set.is_null()) {
  1606. _particles_update_buffers(particles);
  1607. Vector<RD::Uniform> uniforms;
  1608. {
  1609. RD::Uniform u;
  1610. u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
  1611. u.binding = 0;
  1612. u.append_id(particles->particle_instance_buffer);
  1613. uniforms.push_back(u);
  1614. }
  1615. particles->particles_transforms_buffer_uniform_set = RD::get_singleton()->uniform_set_create(uniforms, p_shader, p_set);
  1616. }
  1617. return particles->particles_transforms_buffer_uniform_set;
  1618. }
  1619. virtual void particles_add_collision(RID p_particles, RID p_particles_collision_instance);
  1620. virtual void particles_remove_collision(RID p_particles, RID p_particles_collision_instance);
  1621. virtual void particles_set_canvas_sdf_collision(RID p_particles, bool p_enable, const Transform2D &p_xform, const Rect2 &p_to_screen, RID p_texture);
  1622. /* PARTICLES COLLISION */
  1623. RID particles_collision_allocate();
  1624. void particles_collision_initialize(RID p_particles_collision);
  1625. virtual void particles_collision_set_collision_type(RID p_particles_collision, RS::ParticlesCollisionType p_type);
  1626. virtual void particles_collision_set_cull_mask(RID p_particles_collision, uint32_t p_cull_mask);
  1627. virtual void particles_collision_set_sphere_radius(RID p_particles_collision, real_t p_radius); //for spheres
  1628. virtual void particles_collision_set_box_extents(RID p_particles_collision, const Vector3 &p_extents); //for non-spheres
  1629. virtual void particles_collision_set_attractor_strength(RID p_particles_collision, real_t p_strength);
  1630. virtual void particles_collision_set_attractor_directionality(RID p_particles_collision, real_t p_directionality);
  1631. virtual void particles_collision_set_attractor_attenuation(RID p_particles_collision, real_t p_curve);
  1632. virtual void particles_collision_set_field_texture(RID p_particles_collision, RID p_texture); //for SDF and vector field, heightfield is dynamic
  1633. virtual void particles_collision_height_field_update(RID p_particles_collision); //for SDF and vector field
  1634. virtual void particles_collision_set_height_field_resolution(RID p_particles_collision, RS::ParticlesCollisionHeightfieldResolution p_resolution); //for SDF and vector field
  1635. virtual AABB particles_collision_get_aabb(RID p_particles_collision) const;
  1636. virtual Vector3 particles_collision_get_extents(RID p_particles_collision) const;
  1637. virtual bool particles_collision_is_heightfield(RID p_particles_collision) const;
  1638. RID particles_collision_get_heightfield_framebuffer(RID p_particles_collision) const;
  1639. /* FOG VOLUMES */
  1640. virtual RID fog_volume_allocate();
  1641. virtual void fog_volume_initialize(RID p_rid);
  1642. virtual void fog_volume_set_shape(RID p_fog_volume, RS::FogVolumeShape p_shape);
  1643. virtual void fog_volume_set_extents(RID p_fog_volume, const Vector3 &p_extents);
  1644. virtual void fog_volume_set_material(RID p_fog_volume, RID p_material);
  1645. virtual RS::FogVolumeShape fog_volume_get_shape(RID p_fog_volume) const;
  1646. virtual RID fog_volume_get_material(RID p_fog_volume) const;
  1647. virtual AABB fog_volume_get_aabb(RID p_fog_volume) const;
  1648. virtual Vector3 fog_volume_get_extents(RID p_fog_volume) const;
  1649. /* VISIBILITY NOTIFIER */
  1650. virtual RID visibility_notifier_allocate();
  1651. virtual void visibility_notifier_initialize(RID p_notifier);
  1652. virtual void visibility_notifier_set_aabb(RID p_notifier, const AABB &p_aabb);
  1653. virtual void visibility_notifier_set_callbacks(RID p_notifier, const Callable &p_enter_callbable, const Callable &p_exit_callable);
  1654. virtual AABB visibility_notifier_get_aabb(RID p_notifier) const;
  1655. virtual void visibility_notifier_call(RID p_notifier, bool p_enter, bool p_deferred);
  1656. //used from 2D and 3D
  1657. virtual RID particles_collision_instance_create(RID p_collision);
  1658. virtual void particles_collision_instance_set_transform(RID p_collision_instance, const Transform3D &p_transform);
  1659. virtual void particles_collision_instance_set_active(RID p_collision_instance, bool p_active);
  1660. /* GLOBAL VARIABLES API */
  1661. virtual void global_variable_add(const StringName &p_name, RS::GlobalVariableType p_type, const Variant &p_value);
  1662. virtual void global_variable_remove(const StringName &p_name);
  1663. virtual Vector<StringName> global_variable_get_list() const;
  1664. virtual void global_variable_set(const StringName &p_name, const Variant &p_value);
  1665. virtual void global_variable_set_override(const StringName &p_name, const Variant &p_value);
  1666. virtual Variant global_variable_get(const StringName &p_name) const;
  1667. virtual RS::GlobalVariableType global_variable_get_type(const StringName &p_name) const;
  1668. RS::GlobalVariableType global_variable_get_type_internal(const StringName &p_name) const;
  1669. virtual void global_variables_load_settings(bool p_load_textures = true);
  1670. virtual void global_variables_clear();
  1671. virtual int32_t global_variables_instance_allocate(RID p_instance);
  1672. virtual void global_variables_instance_free(RID p_instance);
  1673. virtual void global_variables_instance_update(RID p_instance, int p_index, const Variant &p_value);
  1674. RID global_variables_get_storage_buffer() const;
  1675. /* RENDER TARGET API */
  1676. RID render_target_create();
  1677. void render_target_set_position(RID p_render_target, int p_x, int p_y);
  1678. void render_target_set_size(RID p_render_target, int p_width, int p_height, uint32_t p_view_count);
  1679. RID render_target_get_texture(RID p_render_target);
  1680. void render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id);
  1681. void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value);
  1682. bool render_target_was_used(RID p_render_target);
  1683. void render_target_set_as_unused(RID p_render_target);
  1684. void render_target_copy_to_back_buffer(RID p_render_target, const Rect2i &p_region, bool p_gen_mipmaps);
  1685. void render_target_clear_back_buffer(RID p_render_target, const Rect2i &p_region, const Color &p_color);
  1686. void render_target_gen_back_buffer_mipmaps(RID p_render_target, const Rect2i &p_region);
  1687. RID render_target_get_back_buffer_uniform_set(RID p_render_target, RID p_base_shader);
  1688. virtual void render_target_request_clear(RID p_render_target, const Color &p_clear_color);
  1689. virtual bool render_target_is_clear_requested(RID p_render_target);
  1690. virtual Color render_target_get_clear_request_color(RID p_render_target);
  1691. virtual void render_target_disable_clear_request(RID p_render_target);
  1692. virtual void render_target_do_clear_request(RID p_render_target);
  1693. virtual void render_target_set_sdf_size_and_scale(RID p_render_target, RS::ViewportSDFOversize p_size, RS::ViewportSDFScale p_scale);
  1694. RID render_target_get_sdf_texture(RID p_render_target);
  1695. RID render_target_get_sdf_framebuffer(RID p_render_target);
  1696. void render_target_sdf_process(RID p_render_target);
  1697. virtual Rect2i render_target_get_sdf_rect(RID p_render_target) const;
  1698. void render_target_mark_sdf_enabled(RID p_render_target, bool p_enabled);
  1699. bool render_target_is_sdf_enabled(RID p_render_target) const;
  1700. Size2 render_target_get_size(RID p_render_target);
  1701. RID render_target_get_rd_framebuffer(RID p_render_target);
  1702. RID render_target_get_rd_texture(RID p_render_target);
  1703. RID render_target_get_rd_backbuffer(RID p_render_target);
  1704. RID render_target_get_rd_backbuffer_framebuffer(RID p_render_target);
  1705. RID render_target_get_framebuffer_uniform_set(RID p_render_target);
  1706. RID render_target_get_backbuffer_uniform_set(RID p_render_target);
  1707. void render_target_set_framebuffer_uniform_set(RID p_render_target, RID p_uniform_set);
  1708. void render_target_set_backbuffer_uniform_set(RID p_render_target, RID p_uniform_set);
  1709. RS::InstanceType get_base_type(RID p_rid) const;
  1710. bool free(RID p_rid);
  1711. bool has_os_feature(const String &p_feature) const;
  1712. void update_dirty_resources();
  1713. void set_debug_generate_wireframes(bool p_generate) {}
  1714. //keep cached since it can be called form any thread
  1715. uint64_t texture_mem_cache = 0;
  1716. uint64_t buffer_mem_cache = 0;
  1717. uint64_t total_mem_cache = 0;
  1718. virtual void update_memory_info();
  1719. virtual uint64_t get_rendering_info(RS::RenderingInfo p_info);
  1720. String get_video_adapter_name() const;
  1721. String get_video_adapter_vendor() const;
  1722. RenderingDevice::DeviceType get_video_adapter_type() const;
  1723. virtual void capture_timestamps_begin();
  1724. virtual void capture_timestamp(const String &p_name);
  1725. virtual uint32_t get_captured_timestamps_count() const;
  1726. virtual uint64_t get_captured_timestamps_frame() const;
  1727. virtual uint64_t get_captured_timestamp_gpu_time(uint32_t p_index) const;
  1728. virtual uint64_t get_captured_timestamp_cpu_time(uint32_t p_index) const;
  1729. virtual String get_captured_timestamp_name(uint32_t p_index) const;
  1730. RID get_default_rd_storage_buffer() { return default_rd_storage_buffer; }
  1731. static RendererStorageRD *base_singleton;
  1732. void init_effects(bool p_prefer_raster_effects);
  1733. EffectsRD *get_effects();
  1734. RendererStorageRD();
  1735. ~RendererStorageRD();
  1736. };
  1737. #endif // RASTERIZER_STORAGE_RD_H