r3d.h 122 KB

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