r3d.h 115 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997
  1. /*
  2. * Copyright (c) 2025 Le Juez Victor
  3. *
  4. * This software is provided "as-is", without any express or implied warranty. In no event
  5. * will the authors be held liable for any damages arising from the use of this software.
  6. *
  7. * Permission is granted to anyone to use this software for any purpose, including commercial
  8. * applications, and to alter it and redistribute it freely, subject to the following restrictions:
  9. *
  10. * 1. The origin of this software must not be misrepresented; you must not claim that you
  11. * wrote the original software. If you use this software in a product, an acknowledgment
  12. * in the product documentation would be appreciated but is not required.
  13. *
  14. * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
  15. * as being the original software.
  16. *
  17. * 3. This notice may not be removed or altered from any source distribution.
  18. */
  19. #ifndef R3D_H
  20. #define R3D_H
  21. #include <raylib.h>
  22. // --------------------------------------------
  23. // DEFINES
  24. // --------------------------------------------
  25. #if defined(_WIN32)
  26. # if defined(__TINYC__)
  27. # define __declspec(x) __attribute__((x))
  28. # endif
  29. # if defined(R3D_BUILD_SHARED)
  30. # define R3DAPI __declspec(dllexport)
  31. # elif defined(R3D_USE_SHARED)
  32. # define R3DAPI __declspec(dllimport)
  33. # endif
  34. #else
  35. # if defined(R3D_BUILD_SHARED)
  36. # define R3DAPI __attribute__((visibility("default")))
  37. # endif
  38. #endif
  39. #ifndef R3DAPI
  40. # define R3DAPI extern
  41. #endif
  42. // --------------------------------------------
  43. // ENUMS
  44. // --------------------------------------------
  45. /**
  46. * @brief Flags to configure the rendering engine behavior.
  47. *
  48. * These flags control various aspects of the rendering pipeline.
  49. */
  50. typedef unsigned int R3D_Flags;
  51. #define R3D_FLAG_NONE 0 /**< No special rendering flags */
  52. #define R3D_FLAG_FXAA (1 << 0) /**< Enables Fast Approximate Anti-Aliasing (FXAA) */
  53. #define R3D_FLAG_BLIT_LINEAR (1 << 1) /**< Uses linear filtering when blitting the final image */
  54. #define R3D_FLAG_ASPECT_KEEP (1 << 2) /**< Maintains the aspect ratio of the internal resolution when blitting the final image */
  55. #define R3D_FLAG_STENCIL_TEST (1 << 3) /**< Performs a stencil test on each rendering pass affecting geometry */
  56. #define R3D_FLAG_DEPTH_PREPASS (1 << 4) /**< Performs a depth pre-pass before forward rendering, improving desktop GPU performance but unnecessary on mobile */
  57. #define R3D_FLAG_8_BIT_NORMALS (1 << 5) /**< Use 8-bit precision for the normals buffer (deferred); default is 16-bit float */
  58. #define R3D_FLAG_FORCE_FORWARD (1 << 6) /**< Used to force forward rendering for opaque objects, useful for tile-based devices. Be careful, this flag should not be set when rendering, or you may get incorrect sorting of draw calls. */
  59. #define R3D_FLAG_NO_FRUSTUM_CULLING (1 << 7) /**< Disables internal frustum culling. Manual culling is allowed, but may break shadow visibility if objects casting shadows are skipped. */
  60. #define R3D_FLAG_TRANSPARENT_SORTING (1 << 8) /**< Back-to-front sorting of transparent objects for correct blending of non-discarded fragments. Be careful, in 'force forward' mode this flag will also sort opaque objects in 'near-to-far' but in the same sorting pass. */
  61. #define R3D_FLAG_OPAQUE_SORTING (1 << 9) /**< Front-to-back sorting of opaque objects to optimize depth testing at the cost of additional sorting. Please note, in 'force forward' mode this flag has no effect, see transparent sorting. */
  62. #define R3D_FLAG_LOW_PRECISION_BUFFERS (1 << 10) /**< Use 32-bit HDR formats like R11G11B10F for intermediate color buffers instead of full 16-bit floats. Saves memory and bandwidth. */
  63. /**
  64. * @brief Blend modes for rendering.
  65. *
  66. * Defines common blending modes used in 3D rendering to combine source and destination colors.
  67. * @note The blend mode is applied only if you are in forward rendering mode or auto-detect mode.
  68. */
  69. typedef enum R3D_BlendMode {
  70. R3D_BLEND_OPAQUE, ///< No blending, the source color fully replaces the destination color.
  71. R3D_BLEND_ALPHA, ///< Alpha blending: source color is blended with the destination based on alpha value.
  72. R3D_BLEND_ADDITIVE, ///< Additive blending: source color is added to the destination, making bright effects.
  73. R3D_BLEND_MULTIPLY ///< Multiply blending: source color is multiplied with the destination, darkening the image.
  74. } R3D_BlendMode;
  75. typedef enum R3D_CullMode {
  76. R3D_CULL_NONE,
  77. R3D_CULL_BACK,
  78. R3D_CULL_FRONT
  79. } R3D_CullMode;
  80. /**
  81. * @brief Defines the shadow casting mode for objects in the scene.
  82. *
  83. * Determines how an object contributes to shadow mapping, which can affect
  84. * performance and visual accuracy depending on the rendering technique used.
  85. */
  86. typedef enum R3D_ShadowCastMode {
  87. R3D_SHADOW_CAST_DISABLED, ///< The object does not cast shadows.
  88. R3D_SHADOW_CAST_FRONT_FACES, ///< Only front-facing polygons cast shadows.
  89. R3D_SHADOW_CAST_BACK_FACES, ///< Only back-facing polygons cast shadows.
  90. R3D_SHADOW_CAST_ALL_FACES ///< Both front and back-facing polygons cast shadows.
  91. } R3D_ShadowCastMode;
  92. /**
  93. * @brief Defines billboard modes for 3D objects.
  94. *
  95. * This enumeration defines how a 3D object aligns itself relative to the camera.
  96. * It provides options to disable billboarding or to enable specific modes of alignment.
  97. */
  98. typedef enum R3D_BillboardMode {
  99. R3D_BILLBOARD_DISABLED, ///< Billboarding is disabled; the object retains its original orientation.
  100. R3D_BILLBOARD_FRONT, ///< Full billboarding; the object fully faces the camera, rotating on all axes.
  101. R3D_BILLBOARD_Y_AXIS /**< Y-axis constrained billboarding; the object rotates only around the Y-axis,
  102. keeping its "up" orientation fixed. This is suitable for upright objects like characters or signs. */
  103. } R3D_BillboardMode;
  104. /**
  105. * @brief Types of lights supported by the rendering engine.
  106. *
  107. * Each light type has different behaviors and use cases.
  108. */
  109. typedef enum R3D_LightType {
  110. R3D_LIGHT_DIR, ///< Directional light, affects the entire scene with parallel rays.
  111. R3D_LIGHT_SPOT, ///< Spot light, emits light in a cone shape.
  112. R3D_LIGHT_OMNI ///< Omni light, emits light in all directions from a single point.
  113. } R3D_LightType;
  114. /**
  115. * @brief Modes for updating shadow maps.
  116. *
  117. * Determines how often the shadow maps are refreshed.
  118. */
  119. typedef enum R3D_ShadowUpdateMode {
  120. R3D_SHADOW_UPDATE_MANUAL, ///< Shadow maps update only when explicitly requested.
  121. R3D_SHADOW_UPDATE_INTERVAL, ///< Shadow maps update at defined time intervals.
  122. R3D_SHADOW_UPDATE_CONTINUOUS ///< Shadow maps update every frame for real-time accuracy.
  123. } R3D_ShadowUpdateMode;
  124. /**
  125. * @brief Bloom effect modes.
  126. *
  127. * Specifies different post-processing bloom techniques that can be applied
  128. * to the rendered scene. Bloom effects enhance the appearance of bright areas
  129. * by simulating light bleeding, contributing to a more cinematic and realistic look.
  130. */
  131. typedef enum R3D_Bloom {
  132. R3D_BLOOM_DISABLED, ///< Bloom effect is disabled. The scene is rendered without any glow enhancement.
  133. R3D_BLOOM_MIX, ///< Blends the bloom effect with the original scene using linear interpolation (Lerp).
  134. R3D_BLOOM_ADDITIVE, ///< Adds the bloom effect additively to the scene, intensifying bright regions.
  135. R3D_BLOOM_SCREEN ///< Combines the scene and bloom using screen blending, which brightens highlights
  136. } R3D_Bloom;
  137. /**
  138. * @brief Fog effect modes.
  139. *
  140. * Determines how fog is applied to the scene, affecting depth perception and atmosphere.
  141. */
  142. typedef enum R3D_Fog {
  143. R3D_FOG_DISABLED, ///< Fog effect is disabled.
  144. R3D_FOG_LINEAR, ///< Fog density increases linearly with distance from the camera.
  145. R3D_FOG_EXP2, ///< Exponential fog (exp2), where density increases exponentially with distance.
  146. R3D_FOG_EXP ///< Exponential fog, similar to EXP2 but with a different rate of increase.
  147. } R3D_Fog;
  148. /**
  149. * @brief Tone mapping modes.
  150. *
  151. * Controls how high dynamic range (HDR) colors are mapped to low dynamic range (LDR) for display.
  152. */
  153. typedef enum R3D_Tonemap {
  154. R3D_TONEMAP_LINEAR, ///< Simple linear mapping of HDR values.
  155. R3D_TONEMAP_REINHARD, ///< Reinhard tone mapping, a balanced method for compressing HDR values.
  156. R3D_TONEMAP_FILMIC, ///< Filmic tone mapping, mimicking the response of photographic film.
  157. R3D_TONEMAP_ACES, ///< ACES tone mapping, a high-quality cinematic rendering technique.
  158. R3D_TONEMAP_AGX, ///< AGX tone mapping, a modern technique designed to preserve both highlight and shadow details for HDR rendering.
  159. R3D_TONEMAP_COUNT ///< Number of tone mapping modes (used internally)
  160. } R3D_Tonemap;
  161. // --------------------------------------------
  162. // TYPES
  163. // --------------------------------------------
  164. /**
  165. * @brief Represents a vertex and all its attributes for a mesh.
  166. */
  167. typedef struct R3D_Vertex {
  168. Vector3 position; /**< The 3D position of the vertex in object space. */
  169. Vector2 texcoord; /**< The 2D texture coordinates (UV) for mapping textures. */
  170. Vector3 normal; /**< The normal vector used for lighting calculations. */
  171. Vector4 color; /**< Vertex color, typically RGBA. */
  172. Vector4 tangent; /**< The tangent vector, used in normal mapping (often with a handedness in w). */
  173. int boneIds[4]; /**< Indices of up to 4 bones that influence this vertex (for GPU skinning). */
  174. float weights[4]; /**< Corresponding bone weights (should sum to 1.0). Defines the influence of each bone. */
  175. } R3D_Vertex;
  176. /**
  177. * @brief Represents a mesh with its geometry data and GPU buffers.
  178. *
  179. * Contains vertex/index data, GPU buffer handles, and bounding volume.
  180. */
  181. typedef struct R3D_Mesh {
  182. R3D_Vertex* vertices; /**< Pointer to the array of vertices. */
  183. unsigned int* indices; /**< Pointer to the array of indices. */
  184. int vertexCount; /**< Number of vertices. */
  185. int indexCount; /**< Number of indices. */
  186. unsigned int vbo; /**< Vertex Buffer Object (GPU handle). */
  187. unsigned int ebo; /**< Element Buffer Object (GPU handle). */
  188. unsigned int vao; /**< Vertex Array Object (GPU handle). */
  189. Matrix* boneMatrices; /**< Cached animation matrices for all passes. */
  190. BoundingBox aabb; /**< Axis-Aligned Bounding Box in local space. */
  191. } R3D_Mesh;
  192. /**
  193. * @brief Represents a material with textures, parameters, and rendering modes.
  194. *
  195. * Combines multiple texture maps and settings used during shading.
  196. */
  197. typedef struct R3D_Material {
  198. struct R3D_MapAlbedo {
  199. Texture2D texture; /**< Albedo (base color) texture. */
  200. Color color; /**< Albedo color multiplier. */
  201. } albedo;
  202. struct R3D_MapEmission {
  203. Texture2D texture; /**< Emission texture. */
  204. Color color; /**< Emission color. */
  205. float energy; /**< Emission energy multiplier. */
  206. } emission;
  207. struct R3D_MapNormal {
  208. Texture2D texture; /**< Normal map texture. */
  209. float scale; /**< Normal scale. */
  210. } normal;
  211. struct R3D_MapORM {
  212. Texture2D texture; /**< Combined Occlusion-Roughness-Metalness texture. */
  213. float occlusion; /**< Occlusion multiplier. */
  214. float roughness; /**< Roughness multiplier. */
  215. float metalness; /**< Metalness multiplier. */
  216. } orm;
  217. R3D_BlendMode blendMode; /**< Blend mode used for rendering the material. */
  218. R3D_CullMode cullMode; /**< Face culling mode used for the material. */
  219. R3D_ShadowCastMode shadowCastMode; /**< Shadow casting mode for the object. */
  220. R3D_BillboardMode billboardMode; /**< Billboard mode applied to the object. */
  221. float alphaCutoff; /**< Alpha threshold below which fragments are discarded. */
  222. } R3D_Material;
  223. /**
  224. * @brief Represents a skeletal animation for a model.
  225. *
  226. * This structure holds the animation data for a skinned model,
  227. * including per-frame bone transformation poses.
  228. */
  229. typedef struct R3D_ModelAnimation {
  230. int boneCount; /**< Number of bones in the skeleton affected by this animation. */
  231. int frameCount; /**< Total number of frames in the animation sequence. */
  232. BoneInfo* bones; /**< Array of bone metadata (name, parent index, etc.) that defines the skeleton hierarchy. */
  233. Matrix** framePoses; /**< 2D array of transformation matrices: [frame][bone].
  234. Each matrix represents the pose of a bone in a specific frame, typically in local space. */
  235. char name[32]; /**< Name identifier for the animation (e.g., "Walk", "Jump", etc.). */
  236. } R3D_ModelAnimation;
  237. /**
  238. * @brief Represents a complete 3D model with meshes and materials.
  239. *
  240. * Contains multiple meshes and their associated materials, along with bounding information.
  241. */
  242. typedef struct R3D_Model {
  243. R3D_Mesh* meshes; /**< Array of meshes composing the model. */
  244. R3D_Material* materials; /**< Array of materials used by the model. */
  245. int* meshMaterials; /**< Array of material indices, one per mesh. */
  246. int meshCount; /**< Number of meshes. */
  247. int materialCount; /**< Number of materials. */
  248. BoundingBox aabb; /**< Axis-Aligned Bounding Box encompassing the whole model. */
  249. Matrix* boneOffsets; /**< Array of offset (inverse bind) matrices, one per bone.
  250. Transforms mesh-space vertices to bone space. Used in skinning. */
  251. BoneInfo* bones; /**< Bones information (skeleton). Defines the hierarchy and names of bones. */
  252. int boneCount; /**< Number of bones. */
  253. const R3D_ModelAnimation* anim; /**< Pointer to the currently assigned animation for this model (optional). */
  254. int animFrame; /**< Current animation frame index. Used for sampling bone poses from the animation. */
  255. } R3D_Model;
  256. /**
  257. * @brief Represents a unique identifier for a light in R3D.
  258. *
  259. * This ID is used to reference a specific light when calling R3D lighting functions.
  260. */
  261. typedef unsigned int R3D_Light;
  262. /**
  263. * @brief Structure representing a skybox and its related textures for lighting.
  264. *
  265. * This structure contains textures used for rendering a skybox, as well as
  266. * precomputed lighting textures used for image-based lighting (IBL).
  267. */
  268. typedef struct R3D_Skybox {
  269. TextureCubemap cubemap; ///< The skybox cubemap texture for the background and reflections.
  270. Texture2D irradiance; ///< The irradiance cubemap for diffuse ambient lighting.
  271. Texture2D prefilter; ///< The prefiltered cubemap for specular reflections with mipmaps.
  272. } R3D_Skybox;
  273. /**
  274. * @brief Represents a 3D sprite with billboard rendering and animation support.
  275. *
  276. * This structure defines a 3D sprite, which by default is rendered as a billboard around the Y-axis.
  277. * The sprite supports frame-based animations and can be configured to use various billboard modes.
  278. *
  279. * @warning The shadow mode does not handle transparency. If shadows are enabled, the entire quad will be rendered in the shadow map,
  280. * potentially causing undesired visual artifacts for semi-transparent sprites.
  281. */
  282. typedef struct R3D_Sprite {
  283. R3D_Material material; ///< The material used for rendering the sprite, including its texture and shading properties.
  284. float currentFrame; ///< The current animation frame, represented as a floating-point value to allow smooth interpolation.
  285. Vector2 frameSize; ///< The size of a single animation frame, in texture coordinates (width and height).
  286. int xFrameCount; ///< The number of frames along the horizontal (X) axis of the texture.
  287. int yFrameCount; ///< The number of frames along the vertical (Y) axis of the texture.
  288. } R3D_Sprite;
  289. /**
  290. * @brief Represents a keyframe in an interpolation curve.
  291. *
  292. * A keyframe contains two values: the time at which the keyframe occurs and the value of the interpolation at that time.
  293. * The time is normalized between 0.0 and 1.0, where 0.0 represents the start of the curve and 1.0 represents the end.
  294. */
  295. typedef struct R3D_Keyframe {
  296. float time; ///< Normalized time of the keyframe, ranging from 0.0 to 1.0.
  297. float value; ///< The value of the interpolation at this keyframe.
  298. } R3D_Keyframe;
  299. /**
  300. * @brief Represents an interpolation curve composed of keyframes.
  301. *
  302. * This structure contains an array of keyframes and metadata about the array, such as the current number of keyframes
  303. * and the allocated capacity. The keyframes define a curve that can be used for smooth interpolation between values
  304. * over a normalized time range (0.0 to 1.0).
  305. */
  306. typedef struct R3D_InterpolationCurve {
  307. R3D_Keyframe* keyframes; ///< Dynamic array of keyframes defining the interpolation curve.
  308. unsigned int capacity; ///< Allocated size of the keyframes array.
  309. unsigned int count; ///< Current number of keyframes in the array.
  310. } R3D_InterpolationCurve;
  311. /**
  312. * @struct R3D_Particle
  313. * @brief Represents a particle in a 3D particle system, with properties
  314. * such as position, velocity, rotation, and color modulation.
  315. */
  316. typedef struct R3D_Particle {
  317. float lifetime; ///< Duration of the particle's existence in seconds.
  318. Matrix transform; ///< The particle's current transformation matrix in 3D space.
  319. Vector3 position; ///< The current position of the particle in 3D space.
  320. Vector3 rotation; ///< The current rotation of the particle in 3D space (Euler angles).
  321. Vector3 scale; ///< The current scale of the particle in 3D space.
  322. Color color; ///< The current color of the particle, representing its color modulation.
  323. Vector3 velocity; ///< The current velocity of the particle in 3D space.
  324. Vector3 angularVelocity; ///< The current angular velocity of the particle in radians (Euler angles).
  325. Vector3 baseScale; ///< The initial scale of the particle in 3D space.
  326. Vector3 baseVelocity; ///< The initial velocity of the particle in 3D space.
  327. Vector3 baseAngularVelocity; ///< The initial angular velocity of the particle in radians (Euler angles).
  328. unsigned char baseOpacity; ///< The initial opacity of the particle, ranging from 0 (fully transparent) to 255 (fully opaque).
  329. } R3D_Particle;
  330. /**
  331. * @brief Represents a CPU-based particle system with various properties and settings.
  332. *
  333. * This structure contains configuration data for a particle system, such as mesh information, initial properties,
  334. * curves for controlling properties over time, and settings for shadow casting, emission rate, and more.
  335. */
  336. typedef struct R3D_ParticleSystem {
  337. R3D_Particle* particles; ///< Pointer to the array of particles in the system.
  338. int capacity; ///< The maximum number of particles the system can manage.
  339. int count; ///< The current number of active particles in the system.
  340. Vector3 position; ///< The initial position of the particle system. Default: (0, 0, 0).
  341. Vector3 gravity; ///< The gravity applied to the particles. Default: (0, -9.81, 0).
  342. Vector3 initialScale; ///< The initial scale of the particles. Default: (1, 1, 1).
  343. float scaleVariance; ///< The variance in particle scale. Default: 0.0f.
  344. Vector3 initialRotation; ///< The initial rotation of the particles in Euler angles (degrees). Default: (0, 0, 0).
  345. Vector3 rotationVariance; ///< The variance in particle rotation in Euler angles (degrees). Default: (0, 0, 0).
  346. Color initialColor; ///< The initial color of the particles. Default: WHITE.
  347. Color colorVariance; ///< The variance in particle color. Default: BLANK.
  348. Vector3 initialVelocity; ///< The initial velocity of the particles. Default: (0, 0, 0).
  349. Vector3 velocityVariance; ///< The variance in particle velocity. Default: (0, 0, 0).
  350. Vector3 initialAngularVelocity; ///< The initial angular velocity of the particles in Euler angles (degrees). Default: (0, 0, 0).
  351. Vector3 angularVelocityVariance; ///< The variance in angular velocity. Default: (0, 0, 0).
  352. float lifetime; ///< The lifetime of the particles in seconds. Default: 1.0f.
  353. float lifetimeVariance; ///< The variance in lifetime in seconds. Default: 0.0f.
  354. float emissionTimer; ///< Use to control automatic emission, should not be modified manually.
  355. float emissionRate; ///< The rate of particle emission in particles per second. Default: 10.0f.
  356. float spreadAngle; ///< The angle of propagation of the particles in a cone (degrees). Default: 0.0f.
  357. R3D_InterpolationCurve* scaleOverLifetime; ///< Curve controlling the scale evolution of the particles over their lifetime. Default: NULL.
  358. R3D_InterpolationCurve* speedOverLifetime; ///< Curve controlling the speed evolution of the particles over their lifetime. Default: NULL.
  359. R3D_InterpolationCurve* opacityOverLifetime; ///< Curve controlling the opacity evolution of the particles over their lifetime. Default: NULL.
  360. R3D_InterpolationCurve* angularVelocityOverLifetime; ///< Curve controlling the angular velocity evolution of the particles over their lifetime. Default: NULL.
  361. BoundingBox aabb; ///< For frustum culling. Defaults to a large AABB; compute manually via `R3D_CalculateParticleSystemBoundingBox` after setup.
  362. bool autoEmission; /**< Indicates whether particle emission is automatic when calling `R3D_UpdateParticleSystem`.
  363. * If false, emission is manual using `R3D_EmitParticle`. Default: true.
  364. */
  365. } R3D_ParticleSystem;
  366. /* === Extern C guard === */
  367. #ifdef __cplusplus
  368. extern "C" {
  369. #endif // __cplusplus
  370. // --------------------------------------------
  371. // CORE: Init And Config Functions
  372. // --------------------------------------------
  373. /**
  374. * @brief Initializes the rendering engine.
  375. *
  376. * This function sets up the internal rendering system with the provided resolution
  377. * and state flags, which define the internal behavior. These flags can be modified
  378. * later via R3D_SetState.
  379. *
  380. * @param resWidth Width of the internal resolution.
  381. * @param resHeight Height of the internal resolution.
  382. * @param flags Flags indicating internal behavior (modifiable via R3D_SetState).
  383. */
  384. R3DAPI void R3D_Init(int resWidth, int resHeight, unsigned int flags);
  385. /**
  386. * @brief Closes the rendering engine and deallocates all resources.
  387. *
  388. * This function shuts down the rendering system and frees all allocated memory,
  389. * including the resources associated with the created lights.
  390. */
  391. R3DAPI void R3D_Close(void);
  392. /**
  393. * @brief Checks if a specific internal state flag is set.
  394. *
  395. * @param flag The state flag to check.
  396. * @return True if the flag is set, false otherwise.
  397. */
  398. R3DAPI bool R3D_HasState(unsigned int flag);
  399. /**
  400. * @brief Sets internal state flags for the rendering engine.
  401. *
  402. * This function modifies the behavior of the rendering engine by setting one or more
  403. * state flags. Flags can be later cleared with R3D_ClearState.
  404. *
  405. * @param flags The flags to set.
  406. */
  407. R3DAPI void R3D_SetState(unsigned int flags);
  408. /**
  409. * @brief Clears specific internal state flags.
  410. *
  411. * This function clears one or more previously set state flags, modifying the
  412. * behavior of the rendering engine accordingly.
  413. *
  414. * @param flags The flags to clear.
  415. */
  416. R3DAPI void R3D_ClearState(unsigned int flags);
  417. /**
  418. * @brief Gets the current internal resolution.
  419. *
  420. * This function retrieves the current internal resolution being used by the
  421. * rendering engine.
  422. *
  423. * @param width Pointer to store the width of the internal resolution.
  424. * @param height Pointer to store the height of the internal resolution.
  425. */
  426. R3DAPI void R3D_GetResolution(int* width, int* height);
  427. /**
  428. * @brief Updates the internal resolution.
  429. *
  430. * This function changes the internal resolution of the rendering engine. Note that
  431. * this process destroys and recreates all framebuffers, which may be a slow operation.
  432. *
  433. * @param width The new width for the internal resolution.
  434. * @param height The new height for the internal resolution.
  435. *
  436. * @warning This function may be slow due to the destruction and recreation of framebuffers.
  437. */
  438. R3DAPI void R3D_UpdateResolution(int width, int height);
  439. /**
  440. * @brief Sets a custom render target.
  441. *
  442. * This function allows rendering to a custom framebuffer instead of the main one.
  443. * Passing `NULL` will revert back to rendering to the main framebuffer.
  444. *
  445. * @param target The custom render target (can be NULL to revert to the default framebuffer).
  446. */
  447. R3DAPI void R3D_SetRenderTarget(const RenderTexture* target);
  448. /**
  449. * @brief Defines the bounds of the scene for directional light calculations.
  450. *
  451. * This function sets the scene bounds used to determine which areas should be illuminated
  452. * by directional lights. It is the user's responsibility to calculate and provide the
  453. * correct bounds.
  454. *
  455. * @param sceneBounds The bounding box defining the scene's dimensions.
  456. */
  457. R3DAPI void R3D_SetSceneBounds(BoundingBox sceneBounds);
  458. /**
  459. * @brief Sets the default texture filtering mode.
  460. *
  461. * This function defines the default texture filter that will be applied to all subsequently
  462. * loaded textures, including those used in materials, sprites, and other resources.
  463. *
  464. * If a trilinear or anisotropic filter is selected, mipmaps will be automatically generated
  465. * for the textures, but they will not be generated when using nearest or bilinear filtering.
  466. *
  467. * The default texture filter mode is `TEXTURE_FILTER_TRILINEAR`.
  468. *
  469. * @param filter The texture filtering mode to be applied by default.
  470. */
  471. R3DAPI void R3D_SetTextureFilter(TextureFilter filter);
  472. // --------------------------------------------
  473. // CORE: Drawing Functions
  474. // --------------------------------------------
  475. /**
  476. * @brief Begins a rendering session for a 3D camera.
  477. *
  478. * This function starts a rendering session, preparing the engine to handle subsequent
  479. * draw calls using the provided camera settings.
  480. *
  481. * @param camera The camera to use for rendering the scene.
  482. */
  483. R3DAPI void R3D_Begin(Camera3D camera);
  484. /**
  485. * @brief Ends the current rendering session.
  486. *
  487. * This function signals the end of a rendering session, at which point the engine
  488. * will process all necessary render passes and output the final result to the main
  489. * or custom framebuffer.
  490. */
  491. R3DAPI void R3D_End(void);
  492. /**
  493. * @brief Draws a mesh with a specified material and transformation.
  494. *
  495. * This function renders a mesh with the provided material and transformation matrix.
  496. *
  497. * @param mesh A pointer to the mesh to render. Cannot be NULL.
  498. * @param material A pointer to the material to apply to the mesh. Can be NULL, default material will be used.
  499. * @param transform The transformation matrix to apply to the mesh.
  500. */
  501. R3DAPI void R3D_DrawMesh(const R3D_Mesh* mesh, const R3D_Material* material, Matrix transform);
  502. /**
  503. * @brief Draws a mesh with instancing support.
  504. *
  505. * This function renders a mesh multiple times with different transformation matrices
  506. * for each instance.
  507. *
  508. * @param mesh A pointer to the mesh to render. Cannot be NULL.
  509. * @param material A pointer to the material to apply to the mesh. Can be NULL, default material will be used.
  510. * @param instanceTransforms Array of transformation matrices for each instance. Cannot be NULL.
  511. * @param instanceCount The number of instances to render. Must be greater than 0.
  512. */
  513. R3DAPI void R3D_DrawMeshInstanced(const R3D_Mesh* mesh, const R3D_Material* material, const Matrix* instanceTransforms, int instanceCount);
  514. /**
  515. * @brief Draws a mesh with instancing support and different colors per instance.
  516. *
  517. * This function renders a mesh multiple times with different transformation matrices
  518. * and different colors for each instance.
  519. *
  520. * @param mesh A pointer to the mesh to render. Cannot be NULL.
  521. * @param material A pointer to the material to apply to the mesh. Can be NULL, default material will be used.
  522. * @param instanceTransforms Array of transformation matrices for each instance. Cannot be NULL.
  523. * @param instanceColors Array of colors for each instance. Can be NULL if no per-instance colors are needed.
  524. * @param instanceCount The number of instances to render. Must be greater than 0.
  525. */
  526. R3DAPI void R3D_DrawMeshInstancedEx(const R3D_Mesh* mesh, const R3D_Material* material, const Matrix* instanceTransforms, const Color* instanceColors, int instanceCount);
  527. /**
  528. * @brief Draws a mesh with instancing support, a global transformation, and different colors per instance.
  529. *
  530. * This function renders a mesh multiple times using instancing, with a global transformation
  531. * applied to all instances, and individual transformation matrices and colors for each instance.
  532. * Each instance can have its own position, rotation, scale, and color while sharing the same mesh
  533. * and material.
  534. *
  535. * @param mesh A pointer to the mesh to render. Cannot be NULL.
  536. * @param material A pointer to the material to apply to the mesh. Can be NULL, default material will be used.
  537. * @param globalAabb Optional bounding box encompassing all instances, in local space. Used for frustum culling.
  538. * Can be NULL to disable culling. Will be transformed by the global matrix if necessary.
  539. * @param globalTransform The global transformation matrix applied to all instances.
  540. * @param instanceTransforms Pointer to an array of transformation matrices for each instance, allowing unique transformations. Cannot be NULL.
  541. * @param transformsStride The stride (in bytes) between consecutive transformation matrices in the array.
  542. * Set to 0 if the matrices are tightly packed (stride equals sizeof(Matrix)).
  543. * If matrices are embedded in a struct, set to the size of the struct or the actual byte offset between elements.
  544. * @param instanceColors Pointer to an array of colors for each instance, allowing unique colors. Can be NULL if no per-instance colors are needed.
  545. * @param colorsStride The stride (in bytes) between consecutive colors in the array.
  546. * Set to 0 if the colors are tightly packed (stride equals sizeof(Color)).
  547. * If colors are embedded in a struct, set to the size of the struct or the actual byte offset between elements.
  548. * @param instanceCount The number of instances to render. Must be greater than 0.
  549. */
  550. void R3D_DrawMeshInstancedPro(const R3D_Mesh* mesh, const R3D_Material* material,
  551. const BoundingBox* globalAabb, Matrix globalTransform,
  552. const Matrix* instanceTransforms, int transformsStride,
  553. const Color* instanceColors, int colorsStride,
  554. int instanceCount);
  555. /**
  556. * @brief Draws a model at a specified position and scale.
  557. *
  558. * This function renders a model at the given position with the specified scale factor.
  559. *
  560. * @param model A pointer to the model to render.
  561. * @param position The position to place the model at.
  562. * @param scale The scale factor to apply to the model.
  563. */
  564. R3DAPI void R3D_DrawModel(const R3D_Model* model, Vector3 position, float scale);
  565. /**
  566. * @brief Draws a model with advanced transformation options.
  567. *
  568. * This function renders a model with a specified position, rotation axis, rotation
  569. * angle, and scale. It provides more control over how the model is transformed before
  570. * rendering.
  571. *
  572. * @param model A pointer to the model to render.
  573. * @param position The position to place the model at.
  574. * @param rotationAxis The axis of rotation for the model.
  575. * @param rotationAngle The angle to rotate the model.
  576. * @param scale The scale factor to apply to the model.
  577. */
  578. R3DAPI void R3D_DrawModelEx(const R3D_Model* model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale);
  579. /**
  580. * @brief Draws a model using a transformation matrix.
  581. *
  582. * This function renders a model using a custom transformation matrix, allowing full control
  583. * over the model's position, rotation, scale, and skew. It is intended for advanced rendering
  584. * scenarios where a single matrix defines the complete transformation.
  585. *
  586. * @param model A pointer to the model to render.
  587. * @param transform A transformation matrix that defines how to position, rotate, and scale the model.
  588. */
  589. R3DAPI void R3D_DrawModelPro(const R3D_Model* model, Matrix transform);
  590. /**
  591. * @brief Draws a sprite at a specified position.
  592. *
  593. * This function renders a sprite in 3D space at the given position.
  594. * It supports negative scaling to flip the sprite.
  595. *
  596. * @param sprite A pointer to the sprite to render.
  597. * @param position The position to place the sprite at.
  598. */
  599. R3DAPI void R3D_DrawSprite(const R3D_Sprite* sprite, Vector3 position);
  600. /**
  601. * @brief Draws a sprite with size and rotation options.
  602. *
  603. * This function allows rendering a sprite with a specified size and rotation.
  604. * It supports negative size values for flipping the sprite.
  605. *
  606. * @param sprite A pointer to the sprite to render.
  607. * @param position The position to place the sprite at.
  608. * @param size The size of the sprite (negative values flip the sprite).
  609. * @param rotation The rotation angle in degrees.
  610. */
  611. R3DAPI void R3D_DrawSpriteEx(const R3D_Sprite* sprite, Vector3 position, Vector2 size, float rotation);
  612. /**
  613. * @brief Draws a sprite with full transformation control.
  614. *
  615. * This function provides advanced transformation options, allowing
  616. * customization of size, rotation axis, and rotation angle.
  617. * It supports all billboard modes, or can be drawn without billboarding.
  618. *
  619. * @param sprite A pointer to the sprite to render.
  620. * @param position The position to place the sprite at.
  621. * @param size The size of the sprite (negative values flip the sprite).
  622. * @param rotationAxis The axis around which the sprite rotates.
  623. * @param rotationAngle The angle to rotate the sprite around the given axis.
  624. */
  625. R3DAPI void R3D_DrawSpritePro(const R3D_Sprite* sprite, Vector3 position, Vector2 size, Vector3 rotationAxis, float rotationAngle);
  626. /**
  627. * @brief Draws a 3D sprite with instancing support.
  628. *
  629. * This function renders a 3D sprite multiple times with different transformation matrices
  630. * for each instance.
  631. *
  632. * @param sprite A pointer to the sprite to render. Cannot be NULL.
  633. * @param instanceTransforms Array of transformation matrices for each instance. Cannot be NULL.
  634. * @param instanceCount The number of instances to render. Must be greater than 0.
  635. */
  636. R3DAPI void R3D_DrawSpriteInstanced(const R3D_Sprite* sprite, const Matrix* instanceTransforms, int instanceCount);
  637. /**
  638. * @brief Draws a 3D sprite with instancing support and different colors per instance.
  639. *
  640. * This function renders a 3D sprite multiple times with different transformation matrices
  641. * and different colors for each instance.
  642. *
  643. * @param sprite A pointer to the sprite to render. Cannot be NULL.
  644. * @param instanceTransforms Array of transformation matrices for each instance. Cannot be NULL.
  645. * @param instanceColors Array of colors for each instance. Can be NULL if no per-instance colors are needed.
  646. * @param instanceCount The number of instances to render. Must be greater than 0.
  647. */
  648. R3DAPI void R3D_DrawSpriteInstancedEx(const R3D_Sprite* sprite, const Matrix* instanceTransforms, const Color* instanceColors, int instanceCount);
  649. /**
  650. * @brief Draws a 3D sprite with instancing support, a global transformation, and different colors per instance.
  651. *
  652. * This function renders a 3D sprite multiple times using instancing, with a global transformation
  653. * applied to all instances, and individual transformation matrices and colors for each instance.
  654. * Each instance can have its own position, rotation, scale, and color while sharing the same sprite.
  655. *
  656. * @param sprite A pointer to the sprite to render. Cannot be NULL.
  657. * @param globalAabb Optional bounding box encompassing all instances, in local space. Used for frustum culling.
  658. * Can be NULL to disable culling. Will be transformed by the global matrix if provided.
  659. * @param globalTransform The global transformation matrix applied to all instances.
  660. * @param instanceTransforms Pointer to an array of transformation matrices for each instance, allowing unique transformations. Cannot be NULL.
  661. * @param transformsStride The stride (in bytes) between consecutive transformation matrices in the array.
  662. * Set to 0 if the matrices are tightly packed (stride equals sizeof(Matrix)).
  663. * If matrices are embedded in a struct, set to the size of the struct or the actual byte offset between elements.
  664. * @param instanceColors Pointer to an array of colors for each instance, allowing unique colors. Can be NULL if no per-instance colors are needed.
  665. * @param colorsStride The stride (in bytes) between consecutive colors in the array.
  666. * Set to 0 if the colors are tightly packed (stride equals sizeof(Color)).
  667. * If colors are embedded in a struct, set to the size of the struct or the actual byte offset between elements.
  668. * @param instanceCount The number of instances to render. Must be greater than 0.
  669. */
  670. R3DAPI void R3D_DrawSpriteInstancedPro(const R3D_Sprite* sprite, const BoundingBox* globalAabb, Matrix globalTransform,
  671. const Matrix* instanceTransforms, int transformsStride,
  672. const Color* instanceColors, int colorsStride,
  673. int instanceCount);
  674. /**
  675. * @brief Renders the current state of a CPU-based particle system.
  676. *
  677. * This function draws the particles of a CPU-simulated particle system
  678. * in their current state. It does not modify the simulation or update
  679. * particle properties such as position, velocity, or lifetime.
  680. *
  681. * @param system A pointer to the `R3D_ParticleSystem` to be rendered.
  682. * The particle system must be properly initialized and updated
  683. * to the desired state before calling this function.
  684. * @param mesh A pointer to the mesh used to represent each particle. Cannot be NULL.
  685. * @param material A pointer to the material applied to the particle mesh. Can be NULL, default material will be used.
  686. */
  687. R3DAPI void R3D_DrawParticleSystem(const R3D_ParticleSystem* system, const R3D_Mesh* mesh, const R3D_Material* material);
  688. /**
  689. * @brief Renders the current state of a CPU-based particle system with a global transformation.
  690. *
  691. * This function is similar to `R3D_DrawParticleSystem`, but it applies an additional
  692. * global transformation to all particles. This is useful for rendering particle effects
  693. * in a transformed space (e.g., attached to a moving object).
  694. *
  695. * @param system A pointer to the `R3D_ParticleSystem` to be rendered.
  696. * The particle system must be properly initialized and updated
  697. * to the desired state before calling this function.
  698. * @param mesh A pointer to the mesh used to represent each particle. Cannot be NULL.
  699. * @param material A pointer to the material applied to the particle mesh. Can be NULL, default material will be used.
  700. * @param transform A transformation matrix applied to all particles.
  701. */
  702. R3DAPI void R3D_DrawParticleSystemEx(const R3D_ParticleSystem* system, const R3D_Mesh* mesh, const R3D_Material* material, Matrix transform);
  703. // --------------------------------------------
  704. // MODEL: Mesh Functions
  705. // --------------------------------------------
  706. /**
  707. * @brief Generate a polygon mesh with specified number of sides.
  708. *
  709. * Creates a regular polygon mesh centered at the origin in the XY plane.
  710. * The polygon is generated with vertices evenly distributed around a circle.
  711. *
  712. * @param sides Number of sides for the polygon (minimum 3).
  713. * @param radius Radius of the circumscribed circle.
  714. * @param upload If true, automatically uploads the mesh to GPU memory.
  715. *
  716. * @return Generated polygon mesh structure.
  717. */
  718. R3DAPI R3D_Mesh R3D_GenMeshPoly(int sides, float radius, bool upload);
  719. /**
  720. * @brief Generate a plane mesh with specified dimensions and resolution.
  721. *
  722. * Creates a flat plane mesh in the XZ plane, centered at the origin.
  723. * The mesh can be subdivided for higher resolution or displacement mapping.
  724. *
  725. * @param width Width of the plane along the X axis.
  726. * @param length Length of the plane along the Z axis.
  727. * @param resX Number of subdivisions along the X axis.
  728. * @param resZ Number of subdivisions along the Z axis.
  729. * @param upload If true, automatically uploads the mesh to GPU memory.
  730. *
  731. * @return Generated plane mesh structure.
  732. */
  733. R3DAPI R3D_Mesh R3D_GenMeshPlane(float width, float length, int resX, int resZ, bool upload);
  734. /**
  735. * @brief Generate a cube mesh with specified dimensions.
  736. *
  737. * Creates a cube mesh centered at the origin with the specified width, height, and length.
  738. * Each face consists of two triangles with proper normals and texture coordinates.
  739. *
  740. * @param width Width of the cube along the X axis.
  741. * @param height Height of the cube along the Y axis.
  742. * @param length Length of the cube along the Z axis.
  743. * @param upload If true, automatically uploads the mesh to GPU memory.
  744. *
  745. * @return Generated cube mesh structure.
  746. */
  747. R3DAPI R3D_Mesh R3D_GenMeshCube(float width, float height, float length, bool upload);
  748. /**
  749. * @brief Generate a sphere mesh with specified parameters.
  750. *
  751. * Creates a UV sphere mesh centered at the origin using latitude-longitude subdivision.
  752. * Higher ring and slice counts produce smoother spheres but with more vertices.
  753. *
  754. * @param radius Radius of the sphere.
  755. * @param rings Number of horizontal rings (latitude divisions).
  756. * @param slices Number of vertical slices (longitude divisions).
  757. * @param upload If true, automatically uploads the mesh to GPU memory.
  758. *
  759. * @return Generated sphere mesh structure.
  760. */
  761. R3DAPI R3D_Mesh R3D_GenMeshSphere(float radius, int rings, int slices, bool upload);
  762. /**
  763. * @brief Generate a hemisphere mesh with specified parameters.
  764. *
  765. * Creates a half-sphere mesh (dome) centered at the origin, extending upward in the Y axis.
  766. * Uses the same UV sphere generation technique as R3D_GenMeshSphere but only the upper half.
  767. *
  768. * @param radius Radius of the hemisphere.
  769. * @param rings Number of horizontal rings (latitude divisions).
  770. * @param slices Number of vertical slices (longitude divisions).
  771. * @param upload If true, automatically uploads the mesh to GPU memory.
  772. *
  773. * @return Generated hemisphere mesh structure.
  774. */
  775. R3DAPI R3D_Mesh R3D_GenMeshHemiSphere(float radius, int rings, int slices, bool upload);
  776. /**
  777. * @brief Generate a cylinder mesh with specified parameters.
  778. *
  779. * Creates a cylinder mesh centered at the origin, extending along the Y axis.
  780. * The cylinder includes both top and bottom caps and smooth side surfaces.
  781. *
  782. * @param radius Radius of the cylinder base.
  783. * @param height Height of the cylinder along the Y axis.
  784. * @param slices Number of radial subdivisions around the cylinder.
  785. * @param upload If true, automatically uploads the mesh to GPU memory.
  786. *
  787. * @return Generated cylinder mesh structure.
  788. */
  789. R3DAPI R3D_Mesh R3D_GenMeshCylinder(float radius, float height, int slices, bool upload);
  790. /**
  791. * @brief Generate a cone mesh with specified parameters.
  792. *
  793. * Creates a cone mesh with its base centered at the origin and apex pointing upward along the Y axis.
  794. * The cone includes a circular base and smooth tapered sides.
  795. *
  796. * @param radius Radius of the cone base.
  797. * @param height Height of the cone along the Y axis.
  798. * @param slices Number of radial subdivisions around the cone base.
  799. * @param upload If true, automatically uploads the mesh to GPU memory.
  800. *
  801. * @return Generated cone mesh structure.
  802. */
  803. R3DAPI R3D_Mesh R3D_GenMeshCone(float radius, float height, int slices, bool upload);
  804. /**
  805. * @brief Generate a torus mesh with specified parameters.
  806. *
  807. * Creates a torus (donut shape) mesh centered at the origin in the XZ plane.
  808. * The torus is defined by a major radius (distance from center to tube center)
  809. * and a minor radius (tube thickness).
  810. *
  811. * @param radius Major radius of the torus (distance from center to tube center).
  812. * @param size Minor radius of the torus (tube thickness/radius).
  813. * @param radSeg Number of segments around the major radius.
  814. * @param sides Number of sides around the tube cross-section.
  815. * @param upload If true, automatically uploads the mesh to GPU memory.
  816. *
  817. * @return Generated torus mesh structure.
  818. */
  819. R3DAPI R3D_Mesh R3D_GenMeshTorus(float radius, float size, int radSeg, int sides, bool upload);
  820. /**
  821. * @brief Generate a trefoil knot mesh with specified parameters.
  822. *
  823. * Creates a trefoil knot mesh, which is a mathematical knot shape.
  824. * Similar to a torus but with a twisted, knotted topology.
  825. *
  826. * @param radius Major radius of the knot.
  827. * @param size Minor radius (tube thickness) of the knot.
  828. * @param radSeg Number of segments around the major radius.
  829. * @param sides Number of sides around the tube cross-section.
  830. * @param upload If true, automatically uploads the mesh to GPU memory.
  831. *
  832. * @return Generated trefoil knot mesh structure.
  833. */
  834. R3DAPI R3D_Mesh R3D_GenMeshKnot(float radius, float size, int radSeg, int sides, bool upload);
  835. /**
  836. * @brief Generate a terrain mesh from a heightmap image.
  837. *
  838. * Creates a terrain mesh by interpreting the brightness values of a heightmap image
  839. * as height values. The resulting mesh represents a 3D terrain surface.
  840. *
  841. * @param heightmap Image containing height data (grayscale values represent elevation).
  842. * @param size 3D vector defining the terrain dimensions (width, max height, depth).
  843. * @param upload If true, automatically uploads the mesh to GPU memory.
  844. *
  845. * @return Generated heightmap terrain mesh structure.
  846. */
  847. R3DAPI R3D_Mesh R3D_GenMeshHeightmap(Image heightmap, Vector3 size, bool upload);
  848. /**
  849. * @brief Generate a voxel-style mesh from a cubicmap image.
  850. *
  851. * Creates a mesh composed of cubes based on a cubicmap image, where each pixel
  852. * represents the presence or absence of a cube at that position. Useful for
  853. * creating voxel-based or block-based geometry.
  854. *
  855. * @param cubicmap Image where pixel values determine cube placement.
  856. * @param cubeSize 3D vector defining the size of each individual cube.
  857. * @param upload If true, automatically uploads the mesh to GPU memory.
  858. *
  859. * @return Generated cubicmap mesh structure.
  860. */
  861. R3DAPI R3D_Mesh R3D_GenMeshCubicmap(Image cubicmap, Vector3 cubeSize, bool upload);
  862. /**
  863. * @brief Free mesh data from both RAM and VRAM.
  864. *
  865. * Releases all memory associated with a mesh, including vertex data in RAM
  866. * and GPU buffers (VAO, VBO, EBO) if the mesh was uploaded to VRAM.
  867. * After calling this function, the mesh should not be used.
  868. *
  869. * @param mesh Pointer to the mesh structure to be freed.
  870. */
  871. R3DAPI void R3D_UnloadMesh(const R3D_Mesh* mesh);
  872. /**
  873. * @brief Upload a mesh to GPU memory.
  874. *
  875. * This function uploads a mesh's vertex and (optional) index data to the GPU.
  876. * It creates and configures a VAO, VBO, and optionally an EBO if indices are provided.
  877. * All vertex attributes are interleaved in a single VBO.
  878. *
  879. * This function must only be called once per mesh. For updates, use R3D_UpdateMesh().
  880. *
  881. * @param mesh Pointer to the mesh structure containing vertex and index data.
  882. * @param dynamic If true, allocates buffers with GL_DYNAMIC_DRAW for later updates.
  883. * If false, uses GL_STATIC_DRAW for optimized static meshes.
  884. *
  885. * @return true if upload succeeded, false on error (e.g. invalid input or already uploaded).
  886. */
  887. R3DAPI bool R3D_UploadMesh(R3D_Mesh* mesh, bool dynamic);
  888. /**
  889. * @brief Update an already uploaded mesh on the GPU.
  890. *
  891. * This function updates the GPU-side data of a mesh previously uploaded with R3D_UploadMesh().
  892. * It replaces the vertex buffer contents using glBufferSubData.
  893. * If index data is present, it also updates or creates the index buffer (EBO).
  894. *
  895. * This function assumes the mesh was uploaded with the `dynamic` flag set to true.
  896. *
  897. * @param mesh Pointer to the mesh structure with updated vertex and/or index data.
  898. *
  899. * @return true if update succeeded, false on error (e.g. mesh not uploaded or invalid data).
  900. */
  901. R3DAPI bool R3D_UpdateMesh(R3D_Mesh* mesh);
  902. /**
  903. * @brief Recalculate the bounding box of a mesh.
  904. *
  905. * Computes and updates the axis-aligned bounding box (AABB) of the mesh
  906. * by examining all vertex positions. This is useful after mesh deformation
  907. * or when the bounding box needs to be refreshed.
  908. *
  909. * @param mesh Pointer to the mesh structure whose bounding box will be updated.
  910. */
  911. R3DAPI void R3D_UpdateMeshBoundingBox(R3D_Mesh* mesh);
  912. /**
  913. * @brief Generate a polygon mesh with specified number of sides.
  914. *
  915. * Creates a regular polygon mesh centered at the origin in the XY plane.
  916. * The polygon is generated with vertices evenly distributed around a circle.
  917. *
  918. * @param sides Number of sides for the polygon (minimum 3).
  919. * @param radius Radius of the circumscribed circle.
  920. * @param upload If true, automatically uploads the mesh to GPU memory.
  921. *
  922. * @return Generated polygon mesh structure.
  923. */
  924. R3DAPI R3D_Mesh R3D_GenMeshPoly(int sides, float radius, bool upload);
  925. /**
  926. * @brief Generate a plane mesh with specified dimensions and resolution.
  927. *
  928. * Creates a flat plane mesh in the XZ plane, centered at the origin.
  929. * The mesh can be subdivided for higher resolution or displacement mapping.
  930. *
  931. * @param width Width of the plane along the X axis.
  932. * @param length Length of the plane along the Z axis.
  933. * @param resX Number of subdivisions along the X axis.
  934. * @param resZ Number of subdivisions along the Z axis.
  935. * @param upload If true, automatically uploads the mesh to GPU memory.
  936. *
  937. * @return Generated plane mesh structure.
  938. */
  939. R3DAPI R3D_Mesh R3D_GenMeshPlane(float width, float length, int resX, int resZ, bool upload);
  940. /**
  941. * @brief Generate a cube mesh with specified dimensions.
  942. *
  943. * Creates a cube mesh centered at the origin with the specified width, height, and length.
  944. * Each face consists of two triangles with proper normals and texture coordinates.
  945. *
  946. * @param width Width of the cube along the X axis.
  947. * @param height Height of the cube along the Y axis.
  948. * @param length Length of the cube along the Z axis.
  949. * @param upload If true, automatically uploads the mesh to GPU memory.
  950. *
  951. * @return Generated cube mesh structure.
  952. */
  953. R3DAPI R3D_Mesh R3D_GenMeshCube(float width, float height, float length, bool upload);
  954. /**
  955. * @brief Generate a sphere mesh with specified parameters.
  956. *
  957. * Creates a UV sphere mesh centered at the origin using latitude-longitude subdivision.
  958. * Higher ring and slice counts produce smoother spheres but with more vertices.
  959. *
  960. * @param radius Radius of the sphere.
  961. * @param rings Number of horizontal rings (latitude divisions).
  962. * @param slices Number of vertical slices (longitude divisions).
  963. * @param upload If true, automatically uploads the mesh to GPU memory.
  964. *
  965. * @return Generated sphere mesh structure.
  966. */
  967. R3DAPI R3D_Mesh R3D_GenMeshSphere(float radius, int rings, int slices, bool upload);
  968. /**
  969. * @brief Generate a hemisphere mesh with specified parameters.
  970. *
  971. * Creates a half-sphere mesh (dome) centered at the origin, extending upward in the Y axis.
  972. * Uses the same UV sphere generation technique as R3D_GenMeshSphere but only the upper half.
  973. *
  974. * @param radius Radius of the hemisphere.
  975. * @param rings Number of horizontal rings (latitude divisions).
  976. * @param slices Number of vertical slices (longitude divisions).
  977. * @param upload If true, automatically uploads the mesh to GPU memory.
  978. *
  979. * @return Generated hemisphere mesh structure.
  980. */
  981. R3DAPI R3D_Mesh R3D_GenMeshHemiSphere(float radius, int rings, int slices, bool upload);
  982. /**
  983. * @brief Generate a cylinder mesh with specified parameters.
  984. *
  985. * Creates a cylinder mesh centered at the origin, extending along the Y axis.
  986. * The cylinder includes both top and bottom caps and smooth side surfaces.
  987. *
  988. * @param radius Radius of the cylinder base.
  989. * @param height Height of the cylinder along the Y axis.
  990. * @param slices Number of radial subdivisions around the cylinder.
  991. * @param upload If true, automatically uploads the mesh to GPU memory.
  992. *
  993. * @return Generated cylinder mesh structure.
  994. */
  995. R3DAPI R3D_Mesh R3D_GenMeshCylinder(float radius, float height, int slices, bool upload);
  996. /**
  997. * @brief Generate a cone mesh with specified parameters.
  998. *
  999. * Creates a cone mesh with its base centered at the origin and apex pointing upward along the Y axis.
  1000. * The cone includes a circular base and smooth tapered sides.
  1001. *
  1002. * @param radius Radius of the cone base.
  1003. * @param height Height of the cone along the Y axis.
  1004. * @param slices Number of radial subdivisions around the cone base.
  1005. * @param upload If true, automatically uploads the mesh to GPU memory.
  1006. *
  1007. * @return Generated cone mesh structure.
  1008. */
  1009. R3DAPI R3D_Mesh R3D_GenMeshCone(float radius, float height, int slices, bool upload);
  1010. /**
  1011. * @brief Generate a torus mesh with specified parameters.
  1012. *
  1013. * Creates a torus (donut shape) mesh centered at the origin in the XZ plane.
  1014. * The torus is defined by a major radius (distance from center to tube center)
  1015. * and a minor radius (tube thickness).
  1016. *
  1017. * @param radius Major radius of the torus (distance from center to tube center).
  1018. * @param size Minor radius of the torus (tube thickness/radius).
  1019. * @param radSeg Number of segments around the major radius.
  1020. * @param sides Number of sides around the tube cross-section.
  1021. * @param upload If true, automatically uploads the mesh to GPU memory.
  1022. *
  1023. * @return Generated torus mesh structure.
  1024. */
  1025. R3DAPI R3D_Mesh R3D_GenMeshTorus(float radius, float size, int radSeg, int sides, bool upload);
  1026. /**
  1027. * @brief Generate a trefoil knot mesh with specified parameters.
  1028. *
  1029. * Creates a trefoil knot mesh, which is a mathematical knot shape.
  1030. * Similar to a torus but with a twisted, knotted topology.
  1031. *
  1032. * @param radius Major radius of the knot.
  1033. * @param size Minor radius (tube thickness) of the knot.
  1034. * @param radSeg Number of segments around the major radius.
  1035. * @param sides Number of sides around the tube cross-section.
  1036. * @param upload If true, automatically uploads the mesh to GPU memory.
  1037. *
  1038. * @return Generated trefoil knot mesh structure.
  1039. */
  1040. R3DAPI R3D_Mesh R3D_GenMeshKnot(float radius, float size, int radSeg, int sides, bool upload);
  1041. /**
  1042. * @brief Generate a terrain mesh from a heightmap image.
  1043. *
  1044. * Creates a terrain mesh by interpreting the brightness values of a heightmap image
  1045. * as height values. The resulting mesh represents a 3D terrain surface.
  1046. *
  1047. * @param heightmap Image containing height data (grayscale values represent elevation).
  1048. * @param size 3D vector defining the terrain dimensions (width, max height, depth).
  1049. * @param upload If true, automatically uploads the mesh to GPU memory.
  1050. *
  1051. * @return Generated heightmap terrain mesh structure.
  1052. */
  1053. R3DAPI R3D_Mesh R3D_GenMeshHeightmap(Image heightmap, Vector3 size, bool upload);
  1054. /**
  1055. * @brief Generate a voxel-style mesh from a cubicmap image.
  1056. *
  1057. * Creates a mesh composed of cubes based on a cubicmap image, where each pixel
  1058. * represents the presence or absence of a cube at that position. Useful for
  1059. * creating voxel-based or block-based geometry.
  1060. *
  1061. * @param cubicmap Image where pixel values determine cube placement.
  1062. * @param cubeSize 3D vector defining the size of each individual cube.
  1063. * @param upload If true, automatically uploads the mesh to GPU memory.
  1064. *
  1065. * @return Generated cubicmap mesh structure.
  1066. */
  1067. R3DAPI R3D_Mesh R3D_GenMeshCubicmap(Image cubicmap, Vector3 cubeSize, bool upload);
  1068. /**
  1069. * @brief Free mesh data from both RAM and VRAM.
  1070. *
  1071. * Releases all memory associated with a mesh, including vertex data in RAM
  1072. * and GPU buffers (VAO, VBO, EBO) if the mesh was uploaded to VRAM.
  1073. * After calling this function, the mesh should not be used.
  1074. *
  1075. * @param mesh Pointer to the mesh structure to be freed.
  1076. */
  1077. R3DAPI void R3D_UnloadMesh(const R3D_Mesh* mesh);
  1078. /**
  1079. * @brief Upload a mesh to GPU memory.
  1080. *
  1081. * This function uploads a mesh's vertex and (optional) index data to the GPU.
  1082. * It creates and configures a VAO, VBO, and optionally an EBO if indices are provided.
  1083. * All vertex attributes are interleaved in a single VBO.
  1084. *
  1085. * This function must only be called once per mesh. For updates, use R3D_UpdateMesh().
  1086. *
  1087. * @param mesh Pointer to the mesh structure containing vertex and index data.
  1088. * @param dynamic If true, allocates buffers with GL_DYNAMIC_DRAW for later updates.
  1089. * If false, uses GL_STATIC_DRAW for optimized static meshes.
  1090. *
  1091. * @return true if upload succeeded, false on error (e.g. invalid input or already uploaded).
  1092. */
  1093. R3DAPI bool R3D_UploadMesh(R3D_Mesh* mesh, bool dynamic);
  1094. /**
  1095. * @brief Update an already uploaded mesh on the GPU.
  1096. *
  1097. * This function updates the GPU-side data of a mesh previously uploaded with R3D_UploadMesh().
  1098. * It replaces the vertex buffer contents using glBufferSubData.
  1099. * If index data is present, it also updates or creates the index buffer (EBO).
  1100. *
  1101. * This function assumes the mesh was uploaded with the `dynamic` flag set to true.
  1102. *
  1103. * @param mesh Pointer to the mesh structure with updated vertex and/or index data.
  1104. *
  1105. * @return true if update succeeded, false on error (e.g. mesh not uploaded or invalid data).
  1106. */
  1107. R3DAPI bool R3D_UpdateMesh(R3D_Mesh* mesh);
  1108. /**
  1109. * @brief Recalculate the bounding box of a mesh.
  1110. *
  1111. * Computes and updates the axis-aligned bounding box (AABB) of the mesh
  1112. * by examining all vertex positions. This is useful after mesh deformation
  1113. * or when the bounding box needs to be refreshed.
  1114. *
  1115. * @param mesh Pointer to the mesh structure whose bounding box will be updated.
  1116. */
  1117. R3DAPI void R3D_UpdateMeshBoundingBox(R3D_Mesh* mesh);
  1118. // --------------------------------------------
  1119. // MODEL: Material Functions
  1120. // --------------------------------------------
  1121. /**
  1122. * @brief Get the default material configuration.
  1123. *
  1124. * Returns a default material with standard properties and default textures.
  1125. * This material can be used as a fallback or starting point for custom materials.
  1126. *
  1127. * @return Default material structure with standard properties.
  1128. */
  1129. R3DAPI R3D_Material R3D_GetDefaultMaterial(void);
  1130. /**
  1131. * @brief Unload a material and its associated textures.
  1132. *
  1133. * Frees all memory associated with a material, including its textures.
  1134. * This function will unload all textures that are not default textures.
  1135. *
  1136. * @warning Only call this function if you are certain that the textures
  1137. * are not shared with other materials or objects, as this will permanently
  1138. * free the texture data.
  1139. *
  1140. * @param material Pointer to the material structure to be unloaded.
  1141. */
  1142. R3DAPI void R3D_UnloadMaterial(const R3D_Material* material);
  1143. // --------------------------------------------
  1144. // MODEL: Model Functions
  1145. // --------------------------------------------
  1146. /**
  1147. * @brief Load a 3D model from a file.
  1148. *
  1149. * Loads a 3D model from the specified file path. Supports various 3D file formats
  1150. * and automatically parses meshes, materials, and texture references.
  1151. *
  1152. * @param filePath Path to the 3D model file to load.
  1153. *
  1154. * @return Loaded model structure containing meshes and materials.
  1155. */
  1156. R3DAPI R3D_Model R3D_LoadModel(const char* filePath);
  1157. /**
  1158. * @brief Load a 3D model from memory buffer.
  1159. *
  1160. * Loads a 3D model from a memory buffer containing the file data.
  1161. * Useful for loading models from embedded resources or network streams.
  1162. *
  1163. * @param fileType String indicating the file format (e.g., "obj", "fbx", "gltf").
  1164. * @param data Pointer to the memory buffer containing the model data.
  1165. * @param size Size of the data buffer in bytes.
  1166. *
  1167. * @return Loaded model structure containing meshes and materials.
  1168. *
  1169. * @note External dependencies (e.g., textures or linked resources) are not supported.
  1170. * The model data must be fully self-contained. Use embedded formats like .glb to ensure compatibility.
  1171. */
  1172. R3DAPI R3D_Model R3D_LoadModelFromMemory(const char* fileType, const void* data, unsigned int size);
  1173. /**
  1174. * @brief Create a model from a single mesh.
  1175. *
  1176. * Creates a model structure containing a single mesh with a default material.
  1177. * This is useful for procedurally generated meshes or simple geometry.
  1178. *
  1179. * @warning The model's bounding box calculation assumes that the mesh's
  1180. * bounding box has already been computed. Call R3D_UpdateMeshBoundingBox()
  1181. * on the mesh before using this function if needed.
  1182. *
  1183. * @param mesh Pointer to the mesh to be wrapped in a model structure.
  1184. *
  1185. * @return Model structure containing the specified mesh.
  1186. */
  1187. R3DAPI R3D_Model R3D_LoadModelFromMesh(const R3D_Mesh* mesh);
  1188. /**
  1189. * @brief Unload a model and optionally its materials.
  1190. *
  1191. * Frees all memory associated with a model, including its meshes.
  1192. * Materials can be optionally unloaded as well.
  1193. *
  1194. * @param model Pointer to the model structure to be unloaded.
  1195. * @param unloadMaterials If true, also unloads all materials associated with the model.
  1196. * Set to false if textures are still being used elsewhere to avoid freeing shared resources.
  1197. */
  1198. R3DAPI void R3D_UnloadModel(const R3D_Model* model, bool unloadMaterials);
  1199. /**
  1200. * @brief Update the bounding box of a model.
  1201. *
  1202. * Recalculates the axis-aligned bounding box (AABB) of the entire model
  1203. * by examining all meshes within the model. Optionally updates individual
  1204. * mesh bounding boxes as well.
  1205. *
  1206. * @param model Pointer to the model structure whose bounding box will be updated.
  1207. * @param updateMeshBoundingBoxes If true, also updates the bounding box of each
  1208. * individual mesh within the model before calculating the model's overall bounding box.
  1209. */
  1210. R3DAPI void R3D_UpdateModelBoundingBox(R3D_Model* model, bool updateMeshBoundingBoxes);
  1211. /**
  1212. * @brief Loads model animations from a supported file format (e.g., GLTF, IQM).
  1213. *
  1214. * This function parses animation data from the given model file and returns an array
  1215. * of R3D_ModelAnimation structs. The caller is responsible for freeing the returned data
  1216. * using R3D_UnloadModelAnimations().
  1217. *
  1218. * @param fileName Path to the model file containing animation(s).
  1219. * @param animCount Pointer to an integer that will receive the number of animations loaded.
  1220. * @param targetFrameRate Desired frame rate (FPS) to sample the animation at. For example, 30 or 60.
  1221. * @return Pointer to a dynamically allocated array of R3D_ModelAnimation. NULL on failure.
  1222. */
  1223. R3DAPI R3D_ModelAnimation* R3D_LoadModelAnimations(const char* fileName, int* animCount, int targetFrameRate);
  1224. /**
  1225. * @brief Frees memory allocated for model animations.
  1226. *
  1227. * This should be called after you're done using animations loaded via R3D_LoadModelAnimations().
  1228. *
  1229. * @param animations Pointer to the animation array to free.
  1230. * @param animCount Number of animations in the array.
  1231. */
  1232. R3DAPI void R3D_UnloadModelAnimations(R3D_ModelAnimation* animations, int animCount);
  1233. /**
  1234. * @brief Finds and returns a pointer to a named animation within the array.
  1235. *
  1236. * Searches the given array of animations for one that matches the specified name.
  1237. *
  1238. * @param animations Array of animations to search.
  1239. * @param animCount Number of animations in the array.
  1240. * @param name Name of the animation to find (case-sensitive).
  1241. * @return Pointer to the matching animation, or NULL if not found.
  1242. */
  1243. R3DAPI R3D_ModelAnimation* R3D_GetModelAnimation(R3D_ModelAnimation* animations, int animCount, const char* name);
  1244. /**
  1245. * @brief Logs the names of all animations in the array (for debugging or inspection).
  1246. *
  1247. * Prints the animation names (and possibly other info) to the standard output or debug console.
  1248. *
  1249. * @param animations Array of animations to list.
  1250. * @param animCount Number of animations in the array.
  1251. */
  1252. R3DAPI void R3D_ListModelAnimations(R3D_ModelAnimation* animations, int animCount);
  1253. /**
  1254. * @brief Sets the scaling factor applied to models on loading.
  1255. *
  1256. * The functions sets the scaling factor to be used when loading models. This value
  1257. * is only applied to models loaded after this value is set.
  1258. *
  1259. * @param value Scaling factor to be used (i.e. 0.01 for meters to centimeters).
  1260. */
  1261. R3DAPI void R3D_SetModelImportScale(float value);
  1262. // --------------------------------------------
  1263. // LIGHTING: Lights Config Functions
  1264. // --------------------------------------------
  1265. /**
  1266. * @brief Creates a new light of the specified type.
  1267. *
  1268. * This function creates a light of the given type. The light must be destroyed
  1269. * manually when no longer needed by calling `R3D_DestroyLight`.
  1270. *
  1271. * @param type The type of light to create (directional, spot or omni-directional).
  1272. * @return The ID of the created light.
  1273. */
  1274. R3DAPI R3D_Light R3D_CreateLight(R3D_LightType type);
  1275. /**
  1276. * @brief Destroys the specified light.
  1277. *
  1278. * This function deallocates the resources associated with the light and makes
  1279. * the light ID invalid. It must be called after the light is no longer needed.
  1280. *
  1281. * @param id The ID of the light to destroy.
  1282. */
  1283. R3DAPI void R3D_DestroyLight(R3D_Light id);
  1284. /**
  1285. * @brief Checks if a light exists.
  1286. *
  1287. * This function checks if the specified light ID is valid and if the light exists.
  1288. *
  1289. * @param id The ID of the light to check.
  1290. * @return True if the light exists, false otherwise.
  1291. */
  1292. R3DAPI bool R3D_IsLightExist(R3D_Light id);
  1293. /**
  1294. * @brief Gets the type of a light.
  1295. *
  1296. * This function returns the type of the specified light (directional, spot or omni-directional).
  1297. *
  1298. * @param id The ID of the light.
  1299. * @return The type of the light.
  1300. */
  1301. R3DAPI R3D_LightType R3D_GetLightType(R3D_Light id);
  1302. /**
  1303. * @brief Checks if a light is active.
  1304. *
  1305. * This function checks whether the specified light is currently active (enabled or disabled).
  1306. *
  1307. * @param id The ID of the light to check.
  1308. * @return True if the light is active, false otherwise.
  1309. */
  1310. R3DAPI bool R3D_IsLightActive(R3D_Light id);
  1311. /**
  1312. * @brief Toggles the state of a light (active or inactive).
  1313. *
  1314. * This function toggles the state of the specified light, turning it on if it is off,
  1315. * or off if it is on.
  1316. *
  1317. * @param id The ID of the light to toggle.
  1318. */
  1319. R3DAPI void R3D_ToggleLight(R3D_Light id);
  1320. /**
  1321. * @brief Sets the active state of a light.
  1322. *
  1323. * This function allows manually turning a light on or off by specifying its active state.
  1324. *
  1325. * @param id The ID of the light to set the active state for.
  1326. * @param active True to activate the light, false to deactivate it.
  1327. */
  1328. R3DAPI void R3D_SetLightActive(R3D_Light id, bool active);
  1329. /**
  1330. * @brief Gets the color of a light.
  1331. *
  1332. * This function retrieves the color of the specified light as a `Color` structure.
  1333. *
  1334. * @param id The ID of the light.
  1335. * @return The color of the light as a `Color` structure.
  1336. */
  1337. R3DAPI Color R3D_GetLightColor(R3D_Light id);
  1338. /**
  1339. * @brief Gets the color of a light as a `Vector3`.
  1340. *
  1341. * This function retrieves the color of the specified light as a `Vector3`, where each
  1342. * component (x, y, z) represents the RGB values of the light.
  1343. *
  1344. * @param id The ID of the light.
  1345. * @return The color of the light as a `Vector3`.
  1346. */
  1347. R3DAPI Vector3 R3D_GetLightColorV(R3D_Light id);
  1348. /**
  1349. * @brief Sets the color of a light.
  1350. *
  1351. * This function sets the color of the specified light using a `Color` structure.
  1352. *
  1353. * @param id The ID of the light.
  1354. * @param color The new color to set for the light.
  1355. */
  1356. R3DAPI void R3D_SetLightColor(R3D_Light id, Color color);
  1357. /**
  1358. * @brief Sets the color of a light using a `Vector3`.
  1359. *
  1360. * This function sets the color of the specified light using a `Vector3`, where each
  1361. * component (x, y, z) represents the RGB values of the light.
  1362. *
  1363. * @param id The ID of the light.
  1364. * @param color The new color to set for the light as a `Vector3`.
  1365. */
  1366. R3DAPI void R3D_SetLightColorV(R3D_Light id, Vector3 color);
  1367. /**
  1368. * @brief Gets the position of a light.
  1369. *
  1370. * This function retrieves the position of the specified light.
  1371. * Only applicable to spot lights or omni-lights.
  1372. *
  1373. * @param id The ID of the light.
  1374. * @return The position of the light as a `Vector3`.
  1375. */
  1376. R3DAPI Vector3 R3D_GetLightPosition(R3D_Light id);
  1377. /**
  1378. * @brief Sets the position of a light.
  1379. *
  1380. * This function sets the position of the specified light.
  1381. * Only applicable to spot lights or omni-lights.
  1382. *
  1383. * @note Has no effect for directional lights.
  1384. * If called on a directional light,
  1385. * a warning will be logged.
  1386. *
  1387. * @param id The ID of the light.
  1388. * @param position The new position to set for the light.
  1389. */
  1390. R3DAPI void R3D_SetLightPosition(R3D_Light id, Vector3 position);
  1391. /**
  1392. * @brief Gets the direction of a light.
  1393. *
  1394. * This function retrieves the direction of the specified light.
  1395. * Only applicable to directional lights or spot lights.
  1396. *
  1397. * @param id The ID of the light.
  1398. * @return The direction of the light as a `Vector3`.
  1399. */
  1400. R3DAPI Vector3 R3D_GetLightDirection(R3D_Light id);
  1401. /**
  1402. * @brief Sets the direction of a light.
  1403. *
  1404. * This function sets the direction of the specified light.
  1405. * Only applicable to directional lights or spot lights.
  1406. *
  1407. * @note Has no effect for omni-directional lights.
  1408. * If called on an omni-directional light,
  1409. * a warning will be logged.
  1410. *
  1411. * @param id The ID of the light.
  1412. * @param direction The new direction to set for the light.
  1413. * The vector is automatically normalized.
  1414. */
  1415. R3DAPI void R3D_SetLightDirection(R3D_Light id, Vector3 direction);
  1416. /**
  1417. * @brief Sets the position and direction of a light to look at a target point.
  1418. *
  1419. * This function sets both the position and the direction of the specified light,
  1420. * causing it to "look at" a given target point.
  1421. *
  1422. * @note - For directional lights, only the direction is updated (position is ignored).
  1423. * - For omni-directional lights, only the position is updated (direction is not calculated).
  1424. * - For spot lights, both position and direction are set accordingly.
  1425. * - This function does **not** emit any warning or log message.
  1426. *
  1427. * @param id The ID of the light.
  1428. * @param position The position to set for the light.
  1429. * @param target The point the light should look at.
  1430. */
  1431. R3DAPI void R3D_LightLookAt(R3D_Light id, Vector3 position, Vector3 target);
  1432. /**
  1433. * @brief Gets the energy level of a light.
  1434. *
  1435. * This function retrieves the energy level (intensity) of the specified light.
  1436. * Energy typically affects the brightness of the light.
  1437. *
  1438. * @param id The ID of the light.
  1439. * @return The energy level of the light.
  1440. */
  1441. R3DAPI float R3D_GetLightEnergy(R3D_Light id);
  1442. /**
  1443. * @brief Sets the energy level of a light.
  1444. *
  1445. * This function sets the energy (intensity) of the specified light.
  1446. * A higher energy value will result in a brighter light.
  1447. *
  1448. * @param id The ID of the light.
  1449. * @param energy The new energy value to set for the light.
  1450. */
  1451. R3DAPI void R3D_SetLightEnergy(R3D_Light id, float energy);
  1452. /**
  1453. * @brief Gets the specular intensity of a light.
  1454. *
  1455. * This function retrieves the current specular intensity of the specified light.
  1456. * Specular intensity affects how shiny surfaces appear when reflecting the light.
  1457. *
  1458. * @param id The ID of the light.
  1459. * @return The current specular intensity of the light.
  1460. */
  1461. R3DAPI float R3D_GetLightSpecular(R3D_Light id);
  1462. /**
  1463. * @brief Sets the specular intensity of a light.
  1464. *
  1465. * This function sets the specular intensity of the specified light.
  1466. * Higher specular values result in stronger and sharper highlights on reflective surfaces.
  1467. *
  1468. * @param id The ID of the light.
  1469. * @param specular The new specular intensity value to set for the light.
  1470. */
  1471. R3DAPI void R3D_SetLightSpecular(R3D_Light id, float specular);
  1472. /**
  1473. * @brief Gets the range of a light.
  1474. *
  1475. * This function retrieves the range of the specified light, which determines how far the light can affect.
  1476. * Only applicable to spot lights or omni-lights.
  1477. *
  1478. * @param id The ID of the light.
  1479. * @return The range of the light.
  1480. */
  1481. R3DAPI float R3D_GetLightRange(R3D_Light id);
  1482. /**
  1483. * @brief Sets the range of a light.
  1484. *
  1485. * This function sets the range of the specified light.
  1486. * The range determines how far the light can illuminate the scene before it fades out.
  1487. * Only applicable to spot lights or omni-lights.
  1488. *
  1489. * @param id The ID of the light.
  1490. * @param range The new range to set for the light.
  1491. */
  1492. R3DAPI void R3D_SetLightRange(R3D_Light id, float range);
  1493. /**
  1494. * @brief Gets the attenuation factor of a light.
  1495. *
  1496. * This function retrieves the attenuation factor of the specified light.
  1497. * Attenuation controls how the intensity of a light decreases with distance.
  1498. * Only applicable to spot lights or omni-lights.
  1499. *
  1500. * @param id The ID of the light.
  1501. * @return The attenuation factor of the light.
  1502. */
  1503. R3DAPI float R3D_GetLightAttenuation(R3D_Light id);
  1504. /**
  1505. * @brief Sets the attenuation factor of a light.
  1506. *
  1507. * This function sets the attenuation factor of the specified light.
  1508. * A higher attenuation value causes the light to lose intensity more quickly as the distance increases.
  1509. * For a realistic effect, an attenuation factor of 2.0f is typically used.
  1510. * Only applicable to spot lights or omni-lights.
  1511. *
  1512. * @param id The ID of the light.
  1513. * @param attenuation The new attenuation factor to set for the light.
  1514. */
  1515. R3DAPI void R3D_SetLightAttenuation(R3D_Light id, float attenuation);
  1516. /**
  1517. * @brief Gets the inner cutoff angle of a spotlight.
  1518. *
  1519. * This function retrieves the inner cutoff angle of a spotlight.
  1520. * The inner cutoff defines the cone of light where the light is at full intensity.
  1521. *
  1522. * @param id The ID of the light.
  1523. * @return The inner cutoff angle in degrees of the spotlight.
  1524. */
  1525. R3DAPI float R3D_GetLightInnerCutOff(R3D_Light id);
  1526. /**
  1527. * @brief Sets the inner cutoff angle of a spotlight.
  1528. *
  1529. * This function sets the inner cutoff angle of a spotlight.
  1530. * The inner cutoff angle defines the cone where the light is at full intensity.
  1531. * Anything outside this cone starts to fade.
  1532. *
  1533. * @param id The ID of the light.
  1534. * @param degrees The new inner cutoff angle in degrees.
  1535. */
  1536. R3DAPI void R3D_SetLightInnerCutOff(R3D_Light id, float degrees);
  1537. /**
  1538. * @brief Gets the outer cutoff angle of a spotlight.
  1539. *
  1540. * This function retrieves the outer cutoff angle of a spotlight.
  1541. * The outer cutoff defines the outer boundary of the light's cone, where the light starts to fade.
  1542. *
  1543. * @param id The ID of the light.
  1544. * @return The outer cutoff angle in degrees of the spotlight.
  1545. */
  1546. R3DAPI float R3D_GetLightOuterCutOff(R3D_Light id);
  1547. /**
  1548. * @brief Sets the outer cutoff angle of a spotlight.
  1549. *
  1550. * This function sets the outer cutoff angle of a spotlight.
  1551. * The outer cutoff defines the boundary of the light's cone where the light intensity starts to gradually decrease.
  1552. *
  1553. * @param id The ID of the light.
  1554. * @param degrees The new outer cutoff angle in degrees.
  1555. */
  1556. R3DAPI void R3D_SetLightOuterCutOff(R3D_Light id, float degrees);
  1557. // --------------------------------------------
  1558. // LIGHTING: Shadow Config Functions
  1559. // --------------------------------------------
  1560. /**
  1561. * @brief Enables shadow casting for a light and sets the resolution of its shadow map.
  1562. *
  1563. * This function enables shadow casting for a specified light and allocates a shadow map with the specified resolution.
  1564. * Shadows can be rendered from the light based on this shadow map.
  1565. *
  1566. * @param id The ID of the light for which shadows should be enabled.
  1567. * @param resolution The resolution of the shadow map to be used by the light.
  1568. */
  1569. R3DAPI void R3D_EnableShadow(R3D_Light id, int resolution);
  1570. /**
  1571. * @brief Disables shadow casting for a light and optionally destroys its shadow map.
  1572. *
  1573. * This function disables shadow casting for the specified light and optionally frees the memory
  1574. * used by its shadow map. If `destroyMap` is true, the shadow map will be destroyed, otherwise,
  1575. * the map will be retained but the light will no longer cast shadows.
  1576. *
  1577. * @param id The ID of the light for which shadows should be disabled.
  1578. * @param destroyMap Whether or not to destroy the shadow map associated with the light.
  1579. */
  1580. R3DAPI void R3D_DisableShadow(R3D_Light id, bool destroyMap);
  1581. /**
  1582. * @brief Checks if shadow casting is enabled for a light.
  1583. *
  1584. * This function checks if shadow casting is currently enabled for the specified light.
  1585. *
  1586. * @param id The ID of the light.
  1587. * @return True if shadow casting is enabled, false otherwise.
  1588. */
  1589. R3DAPI bool R3D_IsShadowEnabled(R3D_Light id);
  1590. /**
  1591. * @brief Checks if a light has an associated shadow map.
  1592. *
  1593. * This function checks if the specified light has a shadow map allocated for it.
  1594. *
  1595. * @param id The ID of the light.
  1596. * @return True if the light has a shadow map, false otherwise.
  1597. */
  1598. R3DAPI bool R3D_HasShadowMap(R3D_Light id);
  1599. /**
  1600. * @brief Gets the shadow map update mode of a light.
  1601. *
  1602. * This function retrieves the current mode for updating the shadow map of a light. The mode can be:
  1603. * - Interval: Updates the shadow map at a fixed interval.
  1604. * - Continuous: Updates the shadow map continuously.
  1605. * - Manual: Updates the shadow map manually (via explicit function calls).
  1606. *
  1607. * @param id The ID of the light.
  1608. * @return The shadow map update mode.
  1609. */
  1610. R3DAPI R3D_ShadowUpdateMode R3D_GetShadowUpdateMode(R3D_Light id);
  1611. /**
  1612. * @brief Sets the shadow map update mode of a light.
  1613. *
  1614. * This function sets the mode for updating the shadow map of the specified light.
  1615. * The update mode controls when and how often the shadow map is refreshed.
  1616. *
  1617. * @param id The ID of the light.
  1618. * @param mode The update mode to set for the shadow map (Interval, Continuous, or Manual).
  1619. */
  1620. R3DAPI void R3D_SetShadowUpdateMode(R3D_Light id, R3D_ShadowUpdateMode mode);
  1621. /**
  1622. * @brief Gets the frequency of shadow map updates for the interval update mode.
  1623. *
  1624. * This function retrieves the frequency (in milliseconds) at which the shadow map should be updated when
  1625. * the interval update mode is enabled. This function is only relevant if the shadow map update mode is set
  1626. * to "Interval".
  1627. *
  1628. * @param id The ID of the light.
  1629. * @return The frequency in milliseconds at which the shadow map is updated.
  1630. */
  1631. R3DAPI int R3D_GetShadowUpdateFrequency(R3D_Light id);
  1632. /**
  1633. * @brief Sets the frequency of shadow map updates for the interval update mode.
  1634. *
  1635. * This function sets the frequency (in milliseconds) at which the shadow map should be updated when
  1636. * the interval update mode is enabled. This function is only relevant if the shadow map update mode is set
  1637. * to "Interval".
  1638. *
  1639. * @param id The ID of the light.
  1640. * @param msec The frequency in milliseconds at which to update the shadow map.
  1641. */
  1642. R3DAPI void R3D_SetShadowUpdateFrequency(R3D_Light id, int msec);
  1643. /**
  1644. * @brief Forces an immediate update of the shadow map during the next rendering pass.
  1645. *
  1646. * This function forces the shadow map of the specified light to be updated during the next call to `R3D_End`.
  1647. * This is primarily used for the manual update mode, but may also work for the interval mode.
  1648. *
  1649. * @param id The ID of the light.
  1650. */
  1651. R3DAPI void R3D_UpdateShadowMap(R3D_Light id);
  1652. /**
  1653. * @brief Retrieves the softness factor used to simulate penumbra in shadows.
  1654. *
  1655. * This function returns the current softness factor for the specified light's shadow map.
  1656. * A higher softness value will produce softer shadow edges, simulating a broader penumbra,
  1657. * while a lower value results in sharper shadows.
  1658. *
  1659. * @param id The ID of the light.
  1660. * @return The softness factor currently set for the shadow (typically in the range [0.0, 1.0]).
  1661. */
  1662. R3DAPI float R3D_GetShadowSoftness(R3D_Light id);
  1663. /**
  1664. * @brief Sets the softness factor used to simulate penumbra in shadows.
  1665. *
  1666. * This function adjusts the softness of the shadow edges for the specified light.
  1667. * Increasing the softness value creates more diffuse, penumbra-like shadows.
  1668. *
  1669. * @param id The ID of the light.
  1670. * @param softness The softness factor to apply (typically in the range [0.0, 1.0]).
  1671. */
  1672. R3DAPI void R3D_SetShadowSoftness(R3D_Light id, float softness);
  1673. /**
  1674. * @brief Gets the shadow bias of a light.
  1675. *
  1676. * This function retrieves the shadow bias value for the specified light. The shadow bias helps prevent shadow artifacts,
  1677. * such as shadow acne, by slightly offsetting the depth comparisons used in shadow mapping.
  1678. *
  1679. * @param id The ID of the light.
  1680. * @return The shadow bias value.
  1681. */
  1682. R3DAPI float R3D_GetShadowBias(R3D_Light id);
  1683. /**
  1684. * @brief Sets the shadow bias of a light.
  1685. *
  1686. * This function sets the shadow bias value for the specified light. Adjusting the shadow bias can help avoid shadow
  1687. * artifacts such as shadow acne by modifying the depth comparisons used in shadow mapping.
  1688. *
  1689. * @param id The ID of the light.
  1690. * @param value The shadow bias value to set.
  1691. */
  1692. R3DAPI void R3D_SetShadowBias(R3D_Light id, float value);
  1693. // --------------------------------------------
  1694. // LIGHTING: Light Helper Functions
  1695. // --------------------------------------------
  1696. /**
  1697. * @brief Returns the bounding box encompassing the light's area of influence.
  1698. *
  1699. * This function computes the axis-aligned bounding box (AABB) that encloses the
  1700. * volume affected by the specified light, based on its type:
  1701. *
  1702. * - For spotlights, the bounding box encloses the light cone.
  1703. * - For omni-directional lights, it encloses a sphere representing the light's range.
  1704. * - For directional lights, it returns an infinite bounding box to represent global influence.
  1705. *
  1706. * This bounding box is primarily useful for spatial partitioning, culling, or visual debugging.
  1707. *
  1708. * @param light The light for which to compute the bounding box.
  1709. *
  1710. * @return A BoundingBox struct that encloses the light's influence volume.
  1711. */
  1712. R3DAPI BoundingBox R3D_GetLightBoundingBox(R3D_Light light);
  1713. /**
  1714. * @brief Draws the area of influence of the light in 3D space.
  1715. *
  1716. * This function visualizes the area affected by a light in 3D space.
  1717. * It draws the light's influence, such as the cone for spotlights or the volume for omni-lights.
  1718. * This function is only relevant for spotlights and omni-lights.
  1719. *
  1720. * @note This function should be called while using the default 3D rendering mode of raylib,
  1721. * not with R3D's rendering mode. It uses raylib's 3D drawing functions to render the light's shape.
  1722. *
  1723. * @param id The ID of the light.
  1724. */
  1725. R3DAPI void R3D_DrawLightShape(R3D_Light id);
  1726. // --------------------------------------------
  1727. // PARTICLES: Particle System Functions
  1728. // --------------------------------------------
  1729. /**
  1730. * @brief Loads a particle emitter system for the CPU.
  1731. *
  1732. * This function initializes a particle emitter system on the CPU with a specified maximum
  1733. * number of particles. It prepares the necessary data structures and allocates memory
  1734. * for managing the particles.
  1735. *
  1736. * @param maxParticles The maximum number of particles the system can handle at once.
  1737. * This value determines the memory allocation and performance constraints.
  1738. * @return A newly initialized `R3D_ParticleSystem` structure.
  1739. * The caller is responsible for properly managing and freeing the system when no longer needed.
  1740. */
  1741. R3DAPI R3D_ParticleSystem R3D_LoadParticleSystem(int maxParticles);
  1742. /**
  1743. * @brief Unloads the particle emitter system and frees allocated memory.
  1744. *
  1745. * This function deallocates the memory used by the particle emitter system and clears the associated resources.
  1746. * It should be called when the particle system is no longer needed to prevent memory leaks.
  1747. *
  1748. * @param system A pointer to the `R3D_ParticleSystem` to be unloaded.
  1749. */
  1750. R3DAPI void R3D_UnloadParticleSystem(R3D_ParticleSystem* system);
  1751. /**
  1752. * @brief Emits a particle in the particle system.
  1753. *
  1754. * This function triggers the emission of a new particle in the particle system. It handles the logic of adding a new
  1755. * particle to the system and initializing its properties based on the current state of the system.
  1756. *
  1757. * @param system A pointer to the `R3D_ParticleSystemCPU` where the particle will be emitted.
  1758. * @return `true` if the particle was successfully emitted, `false` if the system is at full capacity and cannot emit more particles.
  1759. */
  1760. R3DAPI bool R3D_EmitParticle(R3D_ParticleSystem* system);
  1761. /**
  1762. * @brief Updates the particle emitter system by advancing particle positions.
  1763. *
  1764. * This function updates the positions and properties of particles in the system based on the elapsed time. It handles
  1765. * simulation of particle movement, gravity, and other physics-based calculations.
  1766. *
  1767. * @param system A pointer to the `R3D_ParticleSystem` to be updated.
  1768. * @param deltaTime The time elapsed since the last update (in seconds).
  1769. */
  1770. R3DAPI void R3D_UpdateParticleSystem(R3D_ParticleSystem* system, float deltaTime);
  1771. /**
  1772. * @brief Computes and updates the AABB (Axis-Aligned Bounding Box) of a particle system.
  1773. *
  1774. * This function simulates the particle system to estimate the region of space it occupies.
  1775. * It considers particle positions at mid-life and end-of-life to approximate the AABB,
  1776. * which is then stored in the system's `aabb` field. This is useful for enabling frustum culling,
  1777. * especially when the bounds are not known beforehand.
  1778. *
  1779. * @param system Pointer to the `R3D_ParticleSystem` to update.
  1780. */
  1781. R3DAPI void R3D_CalculateParticleSystemBoundingBox(R3D_ParticleSystem* system);
  1782. // --------------------------------------------
  1783. // CURVES: Interpolation Curves Functions
  1784. // --------------------------------------------
  1785. /**
  1786. * @brief Load a sprite from a texture.
  1787. *
  1788. * This function creates a `R3D_Sprite` using the provided texture.
  1789. * The texture will be used as the albedo of the sprite's material.
  1790. * The default billboard mode applied to the material is `R3D_BILLBOARD_Y_AXIS`.
  1791. *
  1792. * @warning The lifetime of the provided texture is managed by the caller.
  1793. *
  1794. * @param texture The `Texture2D` to be used for the sprite.
  1795. * @param xFrameCount The number of frames in the horizontal direction.
  1796. * @param yFrameCount The number of frames in the vertical direction.
  1797. *
  1798. * @return A `R3D_Sprite` object initialized with the given texture and frame configuration.
  1799. */
  1800. R3DAPI R3D_Sprite R3D_LoadSprite(Texture2D texture, int xFrameCount, int yFrameCount);
  1801. /**
  1802. * @brief Unload a sprite and free associated resources.
  1803. *
  1804. * This function releases the resources allocated for a `R3D_Sprite`.
  1805. * It should be called when the sprite is no longer needed.
  1806. *
  1807. * @warning This function only unloads non-default textures from the sprite's material,
  1808. * so make sure these textures are not shared with other material instances elsewhere.
  1809. *
  1810. * @param sprite A pointer to the `R3D_Sprite` to be unloaded.
  1811. */
  1812. R3DAPI void R3D_UnloadSprite(const R3D_Sprite* sprite);
  1813. /**
  1814. * @brief Updates the animation of a sprite.
  1815. *
  1816. * This function updates the current frame of the sprite's animation based on the provided speed. The animation frames are read from
  1817. * right to left, advancing the cursor to the next row after completing a line.
  1818. *
  1819. * @note The `speed` parameter can be calculated as the number of frames per second multiplied by `GetFrameTime()`.
  1820. *
  1821. * @param sprite A pointer to the `R3D_Sprite` to update.
  1822. * @param speed The speed at which the animation progresses, in frames per second.
  1823. */
  1824. R3DAPI void R3D_UpdateSprite(R3D_Sprite* sprite, float speed);
  1825. /**
  1826. * @brief Updates the animation of a sprite with specified frame boundaries.
  1827. *
  1828. * This function updates the current frame of the sprite's animation while restricting it between `firstFrame` and `lastFrame`.
  1829. * This is useful for spritesheets containing multiple animations.
  1830. *
  1831. * @note The frames are read from right to left, and the cursor moves to the next row after completing a line.
  1832. * @note The `speed` parameter can be calculated as the number of frames per second multiplied by `GetFrameTime()`.
  1833. *
  1834. * @param sprite A pointer to the `R3D_Sprite` to update.
  1835. * @param firstFrame The first frame of the animation loop.
  1836. * @param lastFrame The last frame of the animation loop.
  1837. * @param speed The speed at which the animation progresses, in frames per second.
  1838. */
  1839. R3DAPI void R3D_UpdateSpriteEx(R3D_Sprite* sprite, int firstFrame, int lastFrame, float speed);
  1840. // --------------------------------------------
  1841. // CURVES: Interpolation Curves Functions
  1842. // --------------------------------------------
  1843. /**
  1844. * @brief Loads an interpolation curve with a specified initial capacity.
  1845. *
  1846. * This function initializes an interpolation curve with the given capacity. The capacity represents the initial size of
  1847. * the memory allocated for the curve. You can add keyframes to the curve using `R3D_AddKeyframe`. If adding a keyframe
  1848. * exceeds the initial capacity, the system will automatically reallocate memory and double the initial capacity.
  1849. *
  1850. * @param capacity The initial capacity (size) of the interpolation curve. This is the number of keyframes that can be added
  1851. * before a reallocation occurs.
  1852. * @return An initialized interpolation curve with the specified capacity.
  1853. */
  1854. R3DAPI R3D_InterpolationCurve R3D_LoadInterpolationCurve(int capacity);
  1855. /**
  1856. * @brief Unloads the interpolation curve and frees the allocated memory.
  1857. *
  1858. * This function deallocates the memory associated with the interpolation curve and clears any keyframes stored in it.
  1859. * It should be called when the curve is no longer needed to avoid memory leaks.
  1860. *
  1861. * @param curve The interpolation curve to be unloaded.
  1862. */
  1863. R3DAPI void R3D_UnloadInterpolationCurve(R3D_InterpolationCurve curve);
  1864. /**
  1865. * @brief Adds a keyframe to the interpolation curve.
  1866. *
  1867. * This function adds a keyframe to the given interpolation curve at a specific time and value. If the addition of the
  1868. * keyframe requires reallocating memory and the reallocation fails, the previously allocated memory and keyframes are
  1869. * preserved, but the new keyframe is not added.
  1870. *
  1871. * @param curve A pointer to the interpolation curve to which the keyframe will be added.
  1872. * @param time The time at which the keyframe will be added.
  1873. * @param value The value associated with the keyframe.
  1874. * @return `true` if the keyframe was successfully added, or `false` if the reallocation failed.
  1875. */
  1876. R3DAPI bool R3D_AddKeyframe(R3D_InterpolationCurve* curve, float time, float value);
  1877. /**
  1878. * @brief Evaluates the interpolation curve at a specific time.
  1879. *
  1880. * This function evaluates the value of the interpolation curve at a given time. The curve will interpolate between
  1881. * keyframes based on the time provided.
  1882. *
  1883. * @param curve The interpolation curve to be evaluated.
  1884. * @param time The time at which to evaluate the curve.
  1885. * @return The value of the curve at the specified time.
  1886. */
  1887. R3DAPI float R3D_EvaluateCurve(R3D_InterpolationCurve curve, float time);
  1888. // --------------------------------------------
  1889. // ENVIRONMENT: Background And Ambient
  1890. // --------------------------------------------
  1891. /**
  1892. * @brief Sets the background color when no skybox is enabled.
  1893. *
  1894. * This function defines the background color to be used when no skybox is active.
  1895. * The color will be used for the clear color of the scene.
  1896. *
  1897. * @param color The color to set as the background color.
  1898. */
  1899. R3DAPI void R3D_SetBackgroundColor(Color color);
  1900. /**
  1901. * @brief Sets the ambient light color when no skybox is enabled.
  1902. *
  1903. * This function defines the ambient light color to be used when no skybox is active.
  1904. * It affects the overall lighting of the scene when no skybox is present.
  1905. *
  1906. * @param color The color to set for ambient light.
  1907. */
  1908. R3DAPI void R3D_SetAmbientColor(Color color);
  1909. /**
  1910. * @brief Enables a skybox for the scene.
  1911. *
  1912. * This function enables a skybox in the scene, replacing the default background with
  1913. * a 3D environment. The skybox is defined by the specified skybox asset.
  1914. *
  1915. * @param skybox The skybox to enable.
  1916. */
  1917. R3DAPI void R3D_EnableSkybox(R3D_Skybox skybox);
  1918. /**
  1919. * @brief Disables the skybox in the scene.
  1920. *
  1921. * This function disables the skybox, reverting back to the default background
  1922. * color (or no background if none is set). It should be called to remove the skybox
  1923. * from the scene.
  1924. */
  1925. R3DAPI void R3D_DisableSkybox(void);
  1926. /**
  1927. * @brief Sets the rotation of the skybox.
  1928. *
  1929. * This function allows you to specify the rotation of the skybox along the
  1930. * pitch, yaw, and roll axes, which allows the skybox to be rotated in the scene.
  1931. *
  1932. * @param pitch The rotation angle around the X-axis (in degrees).
  1933. * @param yaw The rotation angle around the Y-axis (in degrees).
  1934. * @param roll The rotation angle around the Z-axis (in degrees).
  1935. */
  1936. R3DAPI void R3D_SetSkyboxRotation(float pitch, float yaw, float roll);
  1937. /**
  1938. * @brief Gets the current rotation of the skybox.
  1939. *
  1940. * This function returns the current rotation of the skybox as a vector containing
  1941. * the pitch, yaw, and roll values in degrees.
  1942. *
  1943. * @return A vector containing the current pitch, yaw, and roll of the skybox.
  1944. */
  1945. R3DAPI Vector3 R3D_GetSkyboxRotation(void);
  1946. // --------------------------------------------
  1947. // ENVIRONMENT: SSAO Config Functions
  1948. // --------------------------------------------
  1949. /**
  1950. * @brief Enables or disables Screen Space Ambient Occlusion (SSAO).
  1951. *
  1952. * This function toggles the SSAO effect. When enabled, SSAO enhances the realism
  1953. * of the scene by simulating ambient occlusion, darkening areas where objects
  1954. * are close together or in corners.
  1955. *
  1956. * @param enabled Whether to enable or disable SSAO.
  1957. */
  1958. R3DAPI void R3D_SetSSAO(bool enabled);
  1959. /**
  1960. * @brief Gets the current state of SSAO.
  1961. *
  1962. * This function checks if SSAO is currently enabled or disabled.
  1963. *
  1964. * @return True if SSAO is enabled, false otherwise.
  1965. */
  1966. R3DAPI bool R3D_GetSSAO(void);
  1967. /**
  1968. * @brief Sets the radius for SSAO effect.
  1969. *
  1970. * This function sets the radius used by the SSAO effect to calculate occlusion.
  1971. * A higher value will affect a larger area around each pixel, while a smaller value
  1972. * will create sharper and more localized occlusion.
  1973. *
  1974. * @param value The radius value to set for SSAO.
  1975. */
  1976. R3DAPI void R3D_SetSSAORadius(float value);
  1977. /**
  1978. * @brief Gets the current SSAO radius.
  1979. *
  1980. * This function retrieves the current radius value used by the SSAO effect.
  1981. *
  1982. * @return The radius value for SSAO.
  1983. */
  1984. R3DAPI float R3D_GetSSAORadius(void);
  1985. /**
  1986. * @brief Sets the bias for SSAO effect.
  1987. *
  1988. * This function sets the bias used by the SSAO effect to adjust how much occlusion
  1989. * is applied to the scene. A higher value can reduce artifacts, but may also
  1990. * result in less pronounced ambient occlusion.
  1991. *
  1992. * @param value The bias value for SSAO.
  1993. */
  1994. R3DAPI void R3D_SetSSAOBias(float value);
  1995. /**
  1996. * @brief Gets the current SSAO bias.
  1997. *
  1998. * This function retrieves the current bias value used by the SSAO effect.
  1999. *
  2000. * @return The SSAO bias value.
  2001. */
  2002. R3DAPI float R3D_GetSSAOBias(void);
  2003. /**
  2004. * @brief Sets the number of iterations for SSAO effect.
  2005. *
  2006. * This function sets the number of iterations (or samples) used to calculate the
  2007. * SSAO effect. A higher value will result in a more accurate and smoother effect,
  2008. * but may also be more performance-intensive.
  2009. *
  2010. * @param value The number of iterations for SSAO.
  2011. */
  2012. R3DAPI void R3D_SetSSAOIterations(int value);
  2013. /**
  2014. * @brief Gets the current number of SSAO iterations.
  2015. *
  2016. * This function retrieves the current number of iterations (or samples) used to
  2017. * calculate the SSAO effect.
  2018. *
  2019. * @return The number of SSAO iterations.
  2020. */
  2021. R3DAPI int R3D_GetSSAOIterations(void);
  2022. // --------------------------------------------
  2023. // ENVIRONMENT: Bloom Config Functions
  2024. // --------------------------------------------
  2025. /**
  2026. * @brief Sets the bloom mode.
  2027. *
  2028. * This function configures the bloom effect mode, which determines how the bloom
  2029. * effect is applied to the rendered scene.
  2030. *
  2031. * @param mode The bloom mode to set.
  2032. */
  2033. R3DAPI void R3D_SetBloomMode(R3D_Bloom mode);
  2034. /**
  2035. * @brief Gets the current bloom mode.
  2036. *
  2037. * This function retrieves the bloom mode currently applied to the scene.
  2038. *
  2039. * @return The current bloom mode.
  2040. */
  2041. R3DAPI R3D_Bloom R3D_GetBloomMode(void);
  2042. /**
  2043. * @brief Sets the bloom intensity.
  2044. *
  2045. * This function controls the strength of the bloom effect. Higher values result
  2046. * in a more intense glow effect on bright areas of the scene.
  2047. *
  2048. * @param value The intensity value for bloom.
  2049. */
  2050. R3DAPI void R3D_SetBloomIntensity(float value);
  2051. /**
  2052. * @brief Gets the current bloom intensity.
  2053. *
  2054. * This function retrieves the intensity value of the bloom effect.
  2055. *
  2056. * @return The current bloom intensity.
  2057. */
  2058. R3DAPI float R3D_GetBloomIntensity(void);
  2059. /**
  2060. * @brief Sets the bloom filter radius.
  2061. *
  2062. * Controls the radius of the blur filter applied during the upscaling stage
  2063. * of the bloom effect. A larger radius results in a wider glow around bright
  2064. * objects, creating a softer and more diffuse bloom. A value of 0 disables
  2065. * the filtering effect, preserving sharp bloom highlights.
  2066. *
  2067. * @param value The radius of the bloom filter (in pixels or arbitrary units depending on implementation).
  2068. */
  2069. R3DAPI void R3D_SetBloomFilterRadius(int value);
  2070. /**
  2071. * @brief Gets the current bloom filter radius.
  2072. *
  2073. * Retrieves the current radius used for the bloom filter. This value determines
  2074. * how far the glow effect extends around bright areas in the scene.
  2075. *
  2076. * @return The current bloom filter radius.
  2077. */
  2078. R3DAPI int R3D_GetBloomFilterRadius(void);
  2079. /**
  2080. * @brief Sets the bloom brightness threshold.
  2081. *
  2082. * Controls the brightness cutoff used during the downsampling stage of the
  2083. * bloom effect. If the color channel with the brightest value is below the
  2084. * set threshold the pixel will not be included in the bloom effect.
  2085. *
  2086. * @param value The lowest value to be included the bloom effect (in color value depending on implementation).
  2087. */
  2088. R3DAPI void R3D_SetBloomThreshold(float value);
  2089. /**
  2090. * @brief Gets the bloom brightness threshold.
  2091. *
  2092. * Retrieves the current brightness cutoff used for the bloom effect. This value
  2093. * determines if a pixel will be included in the bloom effect based on it's brightness.
  2094. *
  2095. * @return The current bloom brightness cutoff threshold.
  2096. */
  2097. R3DAPI float R3D_GetBloomThreshold(void);
  2098. /**
  2099. * @brief Sets the bloom brightness threshold's softness.
  2100. *
  2101. * Controls the softness of the cutoff between being include or excluded in the
  2102. * bloom effect. A value of 0 will result in a hard transition between being
  2103. * included or excluded, while larger values will give an increasingly
  2104. * softer transition.
  2105. *
  2106. * @param value The value of of the bloom brightness threshold's softness.
  2107. */
  2108. R3DAPI void R3D_SetBloomSoftThreshold(float value);
  2109. /**
  2110. * @brief Gets the current bloom brightness threshold's softness.
  2111. *
  2112. * Retrieves the softness of the brightness cutoff for the bloom effect.
  2113. * This value determines the softness of the transition between being
  2114. * included or excluded in the bloom effect
  2115. *
  2116. * @return The current bloom brightness threshold's softness.
  2117. */
  2118. R3DAPI float R3D_GetBloomSoftThreshold(void);
  2119. // --------------------------------------------
  2120. // ENVIRONMENT: Fog Config Functions
  2121. // --------------------------------------------
  2122. /**
  2123. * @brief Sets the fog mode.
  2124. *
  2125. * This function defines the type of fog effect applied to the scene.
  2126. * Different modes may provide linear, exponential, or volumetric fog effects.
  2127. *
  2128. * @param mode The fog mode to set.
  2129. */
  2130. R3DAPI void R3D_SetFogMode(R3D_Fog mode);
  2131. /**
  2132. * @brief Gets the current fog mode.
  2133. *
  2134. * This function retrieves the fog mode currently applied to the scene.
  2135. *
  2136. * @return The current fog mode.
  2137. */
  2138. R3DAPI R3D_Fog R3D_GetFogMode(void);
  2139. /**
  2140. * @brief Sets the color of the fog.
  2141. *
  2142. * This function defines the color of the fog effect applied to the scene.
  2143. * The fog color blends with objects as they are affected by fog.
  2144. *
  2145. * @param color The color to set for the fog.
  2146. */
  2147. R3DAPI void R3D_SetFogColor(Color color);
  2148. /**
  2149. * @brief Gets the current fog color.
  2150. *
  2151. * This function retrieves the color currently used for the fog effect.
  2152. *
  2153. * @return The current fog color.
  2154. */
  2155. R3DAPI Color R3D_GetFogColor(void);
  2156. /**
  2157. * @brief Sets the start distance of the fog.
  2158. *
  2159. * This function defines the distance from the camera at which fog begins to appear.
  2160. * Objects closer than this distance will not be affected by fog.
  2161. *
  2162. * @param value The start distance for the fog effect.
  2163. */
  2164. R3DAPI void R3D_SetFogStart(float value);
  2165. /**
  2166. * @brief Gets the current fog start distance.
  2167. *
  2168. * This function retrieves the distance at which the fog begins to be applied.
  2169. *
  2170. * @return The current fog start distance.
  2171. */
  2172. R3DAPI float R3D_GetFogStart(void);
  2173. /**
  2174. * @brief Sets the end distance of the fog.
  2175. *
  2176. * This function defines the distance from the camera at which fog reaches full intensity.
  2177. * Objects beyond this distance will be completely covered by fog.
  2178. *
  2179. * @param value The end distance for the fog effect.
  2180. */
  2181. R3DAPI void R3D_SetFogEnd(float value);
  2182. /**
  2183. * @brief Gets the current fog end distance.
  2184. *
  2185. * This function retrieves the distance at which the fog is fully applied.
  2186. *
  2187. * @return The current fog end distance.
  2188. */
  2189. R3DAPI float R3D_GetFogEnd(void);
  2190. /**
  2191. * @brief Sets the density of the fog.
  2192. *
  2193. * This function controls how thick the fog appears. Higher values result in
  2194. * denser fog, making objects fade out more quickly.
  2195. *
  2196. * @param value The density of the fog (higher values increase fog thickness).
  2197. */
  2198. R3DAPI void R3D_SetFogDensity(float value);
  2199. /**
  2200. * @brief Gets the current fog density.
  2201. *
  2202. * This function retrieves the current density of the fog.
  2203. *
  2204. * @return The current fog density.
  2205. */
  2206. R3DAPI float R3D_GetFogDensity(void);
  2207. // --------------------------------------------
  2208. // ENVIRONMENT: Tonemap Config Functions
  2209. // --------------------------------------------
  2210. /**
  2211. * @brief Sets the tonemapping mode.
  2212. *
  2213. * This function defines the tonemapping algorithm applied to the final rendered image.
  2214. * Different tonemap modes affect color balance, brightness compression, and overall
  2215. * scene appearance.
  2216. *
  2217. * @param mode The tonemap mode to set.
  2218. */
  2219. R3DAPI void R3D_SetTonemapMode(R3D_Tonemap mode);
  2220. /**
  2221. * @brief Gets the current tonemapping mode.
  2222. *
  2223. * This function retrieves the tonemap mode currently applied to the scene.
  2224. *
  2225. * @return The current tonemap mode.
  2226. */
  2227. R3DAPI R3D_Tonemap R3D_GetTonemapMode(void);
  2228. /**
  2229. * @brief Sets the exposure level for tonemapping.
  2230. *
  2231. * This function adjusts the exposure level used in tonemapping, affecting
  2232. * the overall brightness of the rendered scene.
  2233. *
  2234. * @param value The exposure value (higher values make the scene brighter).
  2235. */
  2236. R3DAPI void R3D_SetTonemapExposure(float value);
  2237. /**
  2238. * @brief Gets the current tonemap exposure level.
  2239. *
  2240. * This function retrieves the current exposure setting used in tonemapping.
  2241. *
  2242. * @return The current tonemap exposure value.
  2243. */
  2244. R3DAPI float R3D_GetTonemapExposure(void);
  2245. /**
  2246. * @brief Sets the white point for tonemapping.
  2247. *
  2248. * This function defines the reference white level, which determines how bright
  2249. * areas of the scene are mapped to the final output.
  2250. *
  2251. * @param value The white point value.
  2252. */
  2253. R3DAPI void R3D_SetTonemapWhite(float value);
  2254. /**
  2255. * @brief Gets the current tonemap white point.
  2256. *
  2257. * This function retrieves the white point setting used in tonemapping.
  2258. *
  2259. * @return The current tonemap white value.
  2260. */
  2261. R3DAPI float R3D_GetTonemapWhite(void);
  2262. // --------------------------------------------
  2263. // ENVIRONMENT: Color Adjustment Functions
  2264. // --------------------------------------------
  2265. /**
  2266. * @brief Sets the global brightness adjustment.
  2267. *
  2268. * This function controls the brightness of the final rendered image.
  2269. * Higher values make the image brighter, while lower values darken it.
  2270. *
  2271. * @param value The brightness adjustment value.
  2272. */
  2273. R3DAPI void R3D_SetBrightness(float value);
  2274. /**
  2275. * @brief Gets the current brightness level.
  2276. *
  2277. * This function retrieves the brightness setting applied to the scene.
  2278. *
  2279. * @return The current brightness value.
  2280. */
  2281. R3DAPI float R3D_GetBrightness(void);
  2282. /**
  2283. * @brief Sets the global contrast adjustment.
  2284. *
  2285. * This function controls the contrast of the final rendered image.
  2286. * Higher values increase the difference between dark and bright areas.
  2287. *
  2288. * @param value The contrast adjustment value.
  2289. */
  2290. R3DAPI void R3D_SetContrast(float value);
  2291. /**
  2292. * @brief Gets the current contrast level.
  2293. *
  2294. * This function retrieves the contrast setting applied to the scene.
  2295. *
  2296. * @return The current contrast value.
  2297. */
  2298. R3DAPI float R3D_GetContrast(void);
  2299. /**
  2300. * @brief Sets the global saturation adjustment.
  2301. *
  2302. * This function controls the color intensity of the final rendered image.
  2303. * Higher values make colors more vibrant, while lower values desaturate them.
  2304. *
  2305. * @param value The saturation adjustment value.
  2306. */
  2307. R3DAPI void R3D_SetSaturation(float value);
  2308. /**
  2309. * @brief Gets the current saturation level.
  2310. *
  2311. * This function retrieves the saturation setting applied to the scene.
  2312. *
  2313. * @return The current saturation value.
  2314. */
  2315. R3DAPI float R3D_GetSaturation(void);
  2316. // --------------------------------------------
  2317. // SKYBOX: Skybox Loading Functions
  2318. // --------------------------------------------
  2319. /**
  2320. * @brief Loads a skybox from a texture file.
  2321. *
  2322. * This function loads a skybox from a texture file using a specified cubemap layout.
  2323. * The layout defines how the six faces of the cubemap are arranged within the texture.
  2324. *
  2325. * @param fileName The path to the texture file.
  2326. * @param layout The cubemap layout format.
  2327. * @return The loaded skybox object.
  2328. */
  2329. R3DAPI R3D_Skybox R3D_LoadSkybox(const char* fileName, CubemapLayout layout);
  2330. /**
  2331. * @brief Loads a skybox from a high dynamic range (HDR) image.
  2332. *
  2333. * This function loads a skybox from an HDR image and converts it into a cubemap.
  2334. * The size parameter determines the resolution of the generated cubemap.
  2335. *
  2336. * @param fileName The path to the HDR image file.
  2337. * @param size The resolution of the cubemap (e.g., 512, 1024).
  2338. * @return The loaded skybox object.
  2339. */
  2340. R3DAPI R3D_Skybox R3D_LoadSkyboxHDR(const char* fileName, int size);
  2341. /**
  2342. * @brief Unloads a skybox and frees its resources.
  2343. *
  2344. * This function removes a previously loaded skybox from memory.
  2345. * It should be called when the skybox is no longer needed to prevent memory leaks.
  2346. *
  2347. * @param sky The skybox to unload.
  2348. */
  2349. R3DAPI void R3D_UnloadSkybox(R3D_Skybox sky);
  2350. // --------------------------------------------
  2351. // CULLING: Frustum Test Functions
  2352. // --------------------------------------------
  2353. /**
  2354. * @brief Checks if a point is inside the view frustum.
  2355. *
  2356. * Tests whether a 3D point lies within the camera's frustum by checking against all six planes.
  2357. * Call this only between `R3D_Begin` and `R3D_End`.
  2358. *
  2359. * Useful when automatic frustum culling is disabled and you're using a custom spatial structure
  2360. * (e.g., octree, BVH, etc.).
  2361. *
  2362. * @param position The 3D point to test.
  2363. * @return `true` if inside the frustum, `false` otherwise.
  2364. *
  2365. * @note This performs an exact plane-point test. Slower than bounding box tests.
  2366. * @warning Frustum culling may incorrectly discard objects casting visible shadows.
  2367. * @todo Improve shadow-aware culling in future versions.
  2368. *
  2369. * @see R3D_IsPointInFrustumBoundingBox()
  2370. */
  2371. R3DAPI bool R3D_IsPointInFrustum(Vector3 position);
  2372. /**
  2373. * @brief Checks if a sphere is inside the view frustum.
  2374. *
  2375. * Tests whether a sphere intersects the camera's frustum using plane-sphere tests.
  2376. * Call this only between `R3D_Begin` and `R3D_End`.
  2377. *
  2378. * Useful when managing visibility manually.
  2379. *
  2380. * @param position The center of the sphere.
  2381. * @param radius The sphere's radius (must be positive).
  2382. * @return `true` if at least partially inside the frustum, `false` otherwise.
  2383. *
  2384. * @note More accurate but slower than bounding box approximations.
  2385. * @warning May cause visual issues with shadow casters being culled too early.
  2386. * @todo Add support for shadow-aware visibility.
  2387. *
  2388. * @see R3D_IsSphereInFrustumBoundingBox()
  2389. */
  2390. R3DAPI bool R3D_IsSphereInFrustum(Vector3 position, float radius);
  2391. /**
  2392. * @brief Checks if an AABB is inside the view frustum.
  2393. *
  2394. * Determines whether an axis-aligned bounding box intersects the frustum.
  2395. * Call between `R3D_Begin` and `R3D_End`.
  2396. *
  2397. * For use in custom culling strategies or spatial partitioning systems.
  2398. *
  2399. * @param aabb The bounding box to test.
  2400. * @return `true` if at least partially inside the frustum, `false` otherwise.
  2401. *
  2402. * @note Exact but more costly than AABB pre-tests.
  2403. * @warning May prematurely cull objects casting visible shadows.
  2404. * @todo Add support for light-aware visibility tests.
  2405. *
  2406. * @see R3D_IsAABBInFrustumBoundingBox()
  2407. */
  2408. R3DAPI bool R3D_IsAABBInFrustum(BoundingBox aabb);
  2409. /**
  2410. * @brief Checks if an OBB is inside the view frustum.
  2411. *
  2412. * Tests an oriented bounding box (transformed AABB) for frustum intersection.
  2413. * Must be called between `R3D_Begin` and `R3D_End`.
  2414. *
  2415. * Use this for objects with transformations when doing manual culling.
  2416. *
  2417. * @param aabb Local-space bounding box.
  2418. * @param transform World-space transform matrix.
  2419. * @return `true` if the transformed box intersects the frustum, `false` otherwise.
  2420. *
  2421. * @note More expensive than AABB checks due to matrix operations.
  2422. * @warning May incorrectly cull shadow casters.
  2423. * @todo Consider shadow-aware culling improvements.
  2424. *
  2425. * @see R3D_IsAABBInFrustum()
  2426. */
  2427. R3DAPI bool R3D_IsOBBInFrustum(BoundingBox aabb, Matrix transform);
  2428. /**
  2429. * @brief Fast pre-filtering test for point inside frustum bounding box.
  2430. *
  2431. * Performs an AABB check using the frustum's bounding volume.
  2432. * Useful for quick rejection before precise tests.
  2433. *
  2434. * @param position The 3D point to test.
  2435. * @return `true` if inside the frustum AABB, `false` otherwise.
  2436. *
  2437. * @note May return false positives, never false negatives.
  2438. * @warning Only checks against a loose AABB, not actual frustum planes.
  2439. * @see R3D_IsPointInFrustum()
  2440. */
  2441. R3DAPI bool R3D_IsPointInFrustumBoundingBox(Vector3 position);
  2442. /**
  2443. * @brief Fast pre-filtering test for sphere inside frustum bounding box.
  2444. *
  2445. * Performs a quick check using the frustum's AABB to approximate intersection.
  2446. *
  2447. * @param position The center of the sphere.
  2448. * @param radius Radius of the sphere.
  2449. * @return `true` if possibly intersecting the frustum AABB, `false` otherwise.
  2450. *
  2451. * @note Faster but less accurate than full frustum testing.
  2452. * @warning May produce false positives.
  2453. * @see R3D_IsSphereInFrustum()
  2454. */
  2455. R3DAPI bool R3D_IsSphereInFrustumBoundingBox(Vector3 position, float radius);
  2456. /**
  2457. * @brief Fast pre-filtering test for AABB inside frustum bounding box.
  2458. *
  2459. * Performs a bounding box vs bounding box intersection to quickly eliminate non-visible objects.
  2460. * Useful as an initial coarse check before calling full frustum tests.
  2461. *
  2462. * @param aabb The bounding box to test.
  2463. * @return `true` if intersecting the frustum AABB, `false` otherwise.
  2464. *
  2465. * @note False positives possible, but never false negatives.
  2466. * @warning Does not use actual frustum planes.
  2467. * @note No OBB variant exists due to computational cost.
  2468. * @see R3D_IsAABBInFrustum()
  2469. */
  2470. R3DAPI bool R3D_IsAABBInFrustumBoundingBox(BoundingBox aabb);
  2471. // --------------------------------------------
  2472. // UTILS: Default Texture Retrieval Functions
  2473. // --------------------------------------------
  2474. /**
  2475. * @brief Retrieves a default white texture.
  2476. *
  2477. * This texture is fully white (1,1,1,1), useful for default material properties.
  2478. *
  2479. * @return A white texture.
  2480. */
  2481. R3DAPI Texture2D R3D_GetWhiteTexture(void);
  2482. /**
  2483. * @brief Retrieves a default black texture.
  2484. *
  2485. * This texture is fully black (0,0,0,1), useful for masking or default values.
  2486. *
  2487. * @return A black texture.
  2488. */
  2489. R3DAPI Texture2D R3D_GetBlackTexture(void);
  2490. /**
  2491. * @brief Retrieves a default normal map texture.
  2492. *
  2493. * This texture represents a neutral normal map (0.5, 0.5, 1.0), which applies no normal variation.
  2494. *
  2495. * @return A neutral normal texture.
  2496. */
  2497. R3DAPI Texture2D R3D_GetNormalTexture(void);
  2498. // --------------------------------------------
  2499. // UTILS: Render Texture Retrieval Functions
  2500. // --------------------------------------------
  2501. /**
  2502. * @brief Retrieves the final scene color buffer.
  2503. *
  2504. * This texture stores the final rendered scene as a 24-bit RGB buffer.
  2505. *
  2506. * @return The final color buffer texture.
  2507. */
  2508. R3DAPI Texture2D R3D_GetBufferColor(void);
  2509. /**
  2510. * @brief Retrieves the buffer containing the scene's normal data.
  2511. *
  2512. * This texture stores octahedral-compressed normals using two 16-bit per-channel RG components.
  2513. *
  2514. * @note You can find the decoding functions in the embedded shaders, such as 'screen/lighting.fs.glsl'.
  2515. *
  2516. * @return The normal buffer texture.
  2517. */
  2518. R3DAPI Texture2D R3D_GetBufferNormal(void);
  2519. /**
  2520. * @brief Retrieves the final depth buffer.
  2521. *
  2522. * This texture contains the depth stored in 24 bits and a stencil buffer where each value is 0 or 1, indicating the presence of geometry.
  2523. * It is useful for post-processing effects outside of R3D.
  2524. *
  2525. * @note If you modify the texture parameters to sample the stencil instead of the depth,
  2526. * make sure to reset the parameters afterward.
  2527. *
  2528. * @return The final depth buffer texture.
  2529. */
  2530. R3DAPI Texture2D R3D_GetBufferDepth(void);
  2531. // --------------------------------------------
  2532. // UTILS: Camera Matrices Retrieval Functions
  2533. // --------------------------------------------
  2534. /**
  2535. * @brief Retrieves the view matrix.
  2536. *
  2537. * This matrix represents the camera's transformation from world space to view space.
  2538. * It is updated at the last call to 'R3D_Begin'.
  2539. *
  2540. * @return The current view matrix.
  2541. */
  2542. R3DAPI Matrix R3D_GetMatrixView(void);
  2543. /**
  2544. * @brief Retrieves the inverse view matrix.
  2545. *
  2546. * This matrix transforms coordinates from view space back to world space.
  2547. * It is updated at the last call to 'R3D_Begin'.
  2548. *
  2549. * @return The current inverse view matrix.
  2550. */
  2551. R3DAPI Matrix R3D_GetMatrixInvView(void);
  2552. /**
  2553. * @brief Retrieves the projection matrix.
  2554. *
  2555. * This matrix defines the transformation from view space to clip space.
  2556. * It is updated at the last call to 'R3D_Begin'.
  2557. *
  2558. * @return The current projection matrix.
  2559. */
  2560. R3DAPI Matrix R3D_GetMatrixProjection(void);
  2561. /**
  2562. * @brief Retrieves the inverse projection matrix.
  2563. *
  2564. * This matrix transforms coordinates from clip space back to view space.
  2565. * It is updated at the last call to 'R3D_Begin'.
  2566. *
  2567. * @return The current inverse projection matrix.
  2568. */
  2569. R3DAPI Matrix R3D_GetMatrixInvProjection(void);
  2570. // --------------------------------------------
  2571. // UTILS: Debug Buffer Rendering Functions
  2572. // --------------------------------------------
  2573. /**
  2574. * @brief Renders the internal albedo buffer to the screen.
  2575. *
  2576. * This function displays the albedo (diffuse) buffer as a 2D texture.
  2577. * It must be called outside of `R3D_Begin` and `R3D_End`.
  2578. *
  2579. * @param x X position to draw the buffer.
  2580. * @param y Y position to draw the buffer.
  2581. * @param w Width of the drawn buffer.
  2582. * @param h Height of the drawn buffer.
  2583. */
  2584. R3DAPI void R3D_DrawBufferAlbedo(float x, float y, float w, float h);
  2585. /**
  2586. * @brief Renders the internal emission buffer to the screen.
  2587. *
  2588. * Displays the emission buffer, which contains emissive lighting data.
  2589. * Must be called outside of `R3D_Begin` and `R3D_End`.
  2590. *
  2591. * @param x X position to draw the buffer.
  2592. * @param y Y position to draw the buffer.
  2593. * @param w Width of the drawn buffer.
  2594. * @param h Height of the drawn buffer.
  2595. */
  2596. R3DAPI void R3D_DrawBufferEmission(float x, float y, float w, float h);
  2597. /**
  2598. * @brief Renders the internal normal buffer to the screen.
  2599. *
  2600. * Displays the normal buffer, showing world-space normal data as colors.
  2601. * Must be called outside of `R3D_Begin` and `R3D_End`.
  2602. *
  2603. * @param x X position to draw the buffer.
  2604. * @param y Y position to draw the buffer.
  2605. * @param w Width of the drawn buffer.
  2606. * @param h Height of the drawn buffer.
  2607. */
  2608. R3DAPI void R3D_DrawBufferNormal(float x, float y, float w, float h);
  2609. /**
  2610. * @brief Renders the ORM (Occlusion, Roughness, Metalness) buffer to the screen.
  2611. *
  2612. * Displays the ORM buffer, where each channel stores different material properties:
  2613. * - Red: Ambient occlusion
  2614. * - Green: Roughness
  2615. * - Blue: Metalness
  2616. *
  2617. * Must be called outside of `R3D_Begin` and `R3D_End`.
  2618. *
  2619. * @param x X position to draw the buffer.
  2620. * @param y Y position to draw the buffer.
  2621. * @param w Width of the drawn buffer.
  2622. * @param h Height of the drawn buffer.
  2623. */
  2624. R3DAPI void R3D_DrawBufferORM(float x, float y, float w, float h);
  2625. /**
  2626. * @brief Renders the SSAO (Screen Space Ambient Occlusion) buffer to the screen.
  2627. *
  2628. * Displays the SSAO buffer, showing ambient occlusion data in grayscale.
  2629. * Must be called outside of `R3D_Begin` and `R3D_End`.
  2630. *
  2631. * @param x X position to draw the buffer.
  2632. * @param y Y position to draw the buffer.
  2633. * @param w Width of the drawn buffer.
  2634. * @param h Height of the drawn buffer.
  2635. */
  2636. R3DAPI void R3D_DrawBufferSSAO(float x, float y, float w, float h);
  2637. /**
  2638. * @brief Renders the bloom buffer to the screen.
  2639. *
  2640. * Displays the bloom effect buffer, showing the extracted bright areas after blur processing.
  2641. * Must be called outside of `R3D_Begin` and `R3D_End`.
  2642. *
  2643. * @param x X position to draw the buffer.
  2644. * @param y Y position to draw the buffer.
  2645. * @param w Width of the drawn buffer.
  2646. * @param h Height of the drawn buffer.
  2647. */
  2648. R3DAPI void R3D_DrawBufferBloom(float x, float y, float w, float h);
  2649. #ifdef __cplusplus
  2650. }
  2651. #endif // __cplusplus
  2652. #endif // R3D_H