r3d.h 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207
  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 enum {
  51. R3D_FLAG_NONE = 0, ///< No special rendering flags.
  52. R3D_FLAG_FXAA = 1 << 0, ///< Enables Fast Approximate Anti-Aliasing (FXAA).
  53. R3D_FLAG_BLIT_LINEAR = 1 << 1, ///< Uses linear filtering when blitting the final image.
  54. R3D_FLAG_ASPECT_KEEP = 1 << 2, ///< Maintains the aspect ratio when rendering.
  55. R3D_FLAG_STENCIL_TEST = 1 << 3, ///< Performs a stencil test on each rendering pass affecting geometry, useful for outdoor scenes where the sky is dominant.
  56. R3D_FLAG_DEPTH_PREPASS = 1 << 4, ///< Performs a depth pre-pass before forward rendering, improving desktop GPU performance but unnecessary on mobile.
  57. } R3D_Flags;
  58. /**
  59. * @brief Defines the rendering mode used in the pipeline.
  60. *
  61. * Each mode has its own advantages depending on the hardware and rendering needs.
  62. */
  63. typedef enum {
  64. R3D_RENDER_AUTO_DETECT = 0, /**< Automatically determines the rendering mode based on the material,
  65. for example, by analyzing the albedo texture formats or the alpha
  66. value of albedo colors. This is the default mode. */
  67. R3D_RENDER_DEFERRED = 1, ///< Optimized for desktop GPUs, but does not support transparency.
  68. R3D_RENDER_FORWARD = 2, ///< Works well on tile-based renderers, supports transparency.
  69. } R3D_RenderMode;
  70. /**
  71. * @brief Blend modes for rendering.
  72. *
  73. * Defines common blending modes used in 3D rendering to combine source and destination colors.
  74. * @note The blend mode is applied only if you are in forward rendering mode or auto-detect mode.
  75. */
  76. typedef enum {
  77. R3D_BLEND_OPAQUE, ///< No blending, the source color fully replaces the destination color.
  78. R3D_BLEND_ALPHA, ///< Alpha blending: source color is blended with the destination based on alpha value.
  79. R3D_BLEND_ADDITIVE, ///< Additive blending: source color is added to the destination, making bright effects.
  80. R3D_BLEND_MULTIPLY ///< Multiply blending: source color is multiplied with the destination, darkening the image.
  81. } R3D_BlendMode;
  82. /**
  83. * @brief Defines the shadow casting mode for objects in the scene.
  84. *
  85. * Determines how an object contributes to shadow mapping, which can affect
  86. * performance and visual accuracy depending on the rendering technique used.
  87. */
  88. typedef enum {
  89. R3D_SHADOW_CAST_DISABLED, ///< The object does not cast shadows.
  90. R3D_SHADOW_CAST_FRONT_FACES, ///< Only front-facing polygons cast shadows.
  91. R3D_SHADOW_CAST_BACK_FACES, ///< Only back-facing polygons cast shadows.
  92. R3D_SHADOW_CAST_ALL_FACES ///< Both front and back-facing polygons cast shadows.
  93. } R3D_ShadowCastMode;
  94. /**
  95. * @brief Defines billboard modes for 3D objects.
  96. *
  97. * This enumeration defines how a 3D object aligns itself relative to the camera.
  98. * It provides options to disable billboarding or to enable specific modes of alignment.
  99. */
  100. typedef enum {
  101. R3D_BILLBOARD_DISABLED, ///< Billboarding is disabled; the object retains its original orientation.
  102. R3D_BILLBOARD_FRONT, ///< Full billboarding; the object fully faces the camera, rotating on all axes.
  103. R3D_BILLBOARD_Y_AXIS /**< Y-axis constrained billboarding; the object rotates only around the Y-axis,
  104. keeping its "up" orientation fixed. This is suitable for upright objects like characters or signs. */
  105. } R3D_BillboardMode;
  106. /**
  107. * @brief Types of lights supported by the rendering engine.
  108. *
  109. * Each light type has different behaviors and use cases.
  110. */
  111. typedef enum {
  112. R3D_LIGHT_DIR, ///< Directional light, affects the entire scene with parallel rays.
  113. R3D_LIGHT_SPOT, ///< Spot light, emits light in a cone shape.
  114. R3D_LIGHT_OMNI ///< Omni light, emits light in all directions from a single point.
  115. } R3D_LightType;
  116. /**
  117. * @brief Modes for updating shadow maps.
  118. *
  119. * Determines how often the shadow maps are refreshed.
  120. */
  121. typedef enum {
  122. R3D_SHADOW_UPDATE_MANUAL, ///< Shadow maps update only when explicitly requested.
  123. R3D_SHADOW_UPDATE_INTERVAL, ///< Shadow maps update at defined time intervals.
  124. R3D_SHADOW_UPDATE_CONTINUOUS ///< Shadow maps update every frame for real-time accuracy.
  125. } R3D_ShadowUpdateMode;
  126. /**
  127. * @brief Bloom effect modes.
  128. *
  129. * Defines different post-processing bloom effects applied to the rendered scene.
  130. */
  131. typedef enum {
  132. R3D_BLOOM_DISABLED, ///< Bloom effect is disabled.
  133. R3D_BLOOM_ADDITIVE, ///< Enhances bright areas by adding light to them (stronger glow effect).
  134. R3D_BLOOM_SOFT_LIGHT ///< Creates a softer, more diffused glow around bright areas.
  135. } R3D_Bloom;
  136. /**
  137. * @brief Fog effect modes.
  138. *
  139. * Determines how fog is applied to the scene, affecting depth perception and atmosphere.
  140. */
  141. typedef enum {
  142. R3D_FOG_DISABLED, ///< Fog effect is disabled.
  143. R3D_FOG_LINEAR, ///< Fog density increases linearly with distance from the camera.
  144. R3D_FOG_EXP2, ///< Exponential fog (exp2), where density increases exponentially with distance.
  145. R3D_FOG_EXP ///< Exponential fog, similar to EXP2 but with a different rate of increase.
  146. } R3D_Fog;
  147. /**
  148. * @brief Tone mapping modes.
  149. *
  150. * Controls how high dynamic range (HDR) colors are mapped to low dynamic range (LDR) for display.
  151. */
  152. typedef enum {
  153. R3D_TONEMAP_LINEAR, ///< Simple linear mapping of HDR values.
  154. R3D_TONEMAP_REINHARD, ///< Reinhard tone mapping, a balanced method for compressing HDR values.
  155. R3D_TONEMAP_FILMIC, ///< Filmic tone mapping, mimicking the response of photographic film.
  156. R3D_TONEMAP_ACES, ///< ACES tone mapping, a high-quality cinematic rendering technique.
  157. R3D_TONEMAP_AGX ///< AGX tone mapping, a modern technique designed to preserve both highlight and shadow details for HDR rendering.
  158. } R3D_Tonemap;
  159. // --------------------------------------------
  160. // TYPES
  161. // --------------------------------------------
  162. /**
  163. * @brief Represents a unique identifier for a light in R3D.
  164. *
  165. * This ID is used to reference a specific light when calling R3D lighting functions.
  166. */
  167. typedef unsigned int R3D_Light;
  168. /**
  169. * @brief Structure representing a skybox and its related textures for lighting.
  170. *
  171. * This structure contains textures used for rendering a skybox, as well as
  172. * precomputed lighting textures used for image-based lighting (IBL).
  173. */
  174. typedef struct {
  175. TextureCubemap cubemap; ///< The skybox cubemap texture for the background and reflections.
  176. Texture2D irradiance; ///< The irradiance cubemap for diffuse ambient lighting.
  177. Texture2D prefilter; ///< The prefiltered cubemap for specular reflections with mipmaps.
  178. } R3D_Skybox;
  179. /**
  180. * @brief Represents a 3D sprite with billboard rendering and animation support.
  181. *
  182. * This structure defines a 3D sprite, which by default is rendered as a billboard around the Y-axis.
  183. * The sprite supports frame-based animations and can be configured to use various billboard modes.
  184. *
  185. * @warning The shadow mode does not handle transparency. If shadows are enabled, the entire quad will be rendered in the shadow map,
  186. * potentially causing undesired visual artifacts for semi-transparent sprites.
  187. */
  188. typedef struct {
  189. Material material; ///< The material used for rendering the sprite, including its texture and shading properties.
  190. float currentFrame; ///< The current animation frame, represented as a floating-point value to allow smooth interpolation.
  191. Vector2 frameSize; ///< The size of a single animation frame, in texture coordinates (width and height).
  192. int xFrameCount; ///< The number of frames along the horizontal (X) axis of the texture.
  193. int yFrameCount; ///< The number of frames along the vertical (Y) axis of the texture.
  194. } R3D_Sprite;
  195. /**
  196. * @brief Represents a keyframe in an interpolation curve.
  197. *
  198. * A keyframe contains two values: the time at which the keyframe occurs and the value of the interpolation at that time.
  199. * 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.
  200. */
  201. typedef struct {
  202. float time; ///< Normalized time of the keyframe, ranging from 0.0 to 1.0.
  203. float value; ///< The value of the interpolation at this keyframe.
  204. } R3D_Keyframe;
  205. /**
  206. * @brief Represents an interpolation curve composed of keyframes.
  207. *
  208. * This structure contains an array of keyframes and metadata about the array, such as the current number of keyframes
  209. * and the allocated capacity. The keyframes define a curve that can be used for smooth interpolation between values
  210. * over a normalized time range (0.0 to 1.0).
  211. */
  212. typedef struct {
  213. R3D_Keyframe* keyframes; ///< Dynamic array of keyframes defining the interpolation curve.
  214. unsigned int capacity; ///< Allocated size of the keyframes array.
  215. unsigned int count; ///< Current number of keyframes in the array.
  216. } R3D_InterpolationCurve;
  217. /**
  218. * @struct R3D_Particle
  219. * @brief Represents a particle in a 3D particle system, with properties
  220. * such as position, velocity, rotation, and color modulation.
  221. */
  222. typedef struct {
  223. float lifetime; ///< Duration of the particle's existence in seconds.
  224. Matrix transform; ///< The particle's current transformation matrix in 3D space.
  225. Vector3 position; ///< The current position of the particle in 3D space.
  226. Vector3 rotation; ///< The current rotation of the particle in 3D space (Euler angles).
  227. Vector3 scale; ///< The current scale of the particle in 3D space.
  228. Color color; ///< The current color of the particle, representing its color modulation.
  229. Vector3 velocity; ///< The current velocity of the particle in 3D space.
  230. Vector3 angularVelocity; ///< The current angular velocity of the particle in radians (Euler angles).
  231. Vector3 baseScale; ///< The initial scale of the particle in 3D space.
  232. Vector3 baseVelocity; ///< The initial velocity of the particle in 3D space.
  233. Vector3 baseAngularVelocity; ///< The initial angular velocity of the particle in radians (Euler angles).
  234. unsigned char baseOpacity; ///< The initial opacity of the particle, ranging from 0 (fully transparent) to 255 (fully opaque).
  235. } R3D_Particle;
  236. /**
  237. * @brief Represents a CPU-based particle system with various properties and settings.
  238. *
  239. * This structure contains configuration data for a particle system, such as mesh information, initial properties,
  240. * curves for controlling properties over time, and settings for shadow casting, emission rate, and more.
  241. */
  242. typedef struct {
  243. R3D_Particle* particles; ///< Pointer to the array of particles in the system.
  244. int capacity; ///< The maximum number of particles the system can manage.
  245. int count; ///< The current number of active particles in the system.
  246. Vector3 position; ///< The initial position of the particle system. Default: (0, 0, 0).
  247. Vector3 gravity; ///< The gravity applied to the particles. Default: (0, -9.81, 0).
  248. Vector3 initialScale; ///< The initial scale of the particles. Default: (1, 1, 1).
  249. float scaleVariance; ///< The variance in particle scale. Default: 0.0f.
  250. Vector3 initialRotation; ///< The initial rotation of the particles in Euler angles (degrees). Default: (0, 0, 0).
  251. Vector3 rotationVariance; ///< The variance in particle rotation in Euler angles (degrees). Default: (0, 0, 0).
  252. Color initialColor; ///< The initial color of the particles. Default: WHITE.
  253. Color colorVariance; ///< The variance in particle color. Default: BLANK.
  254. Vector3 initialVelocity; ///< The initial velocity of the particles. Default: (0, 0, 0).
  255. Vector3 velocityVariance; ///< The variance in particle velocity. Default: (0, 0, 0).
  256. Vector3 initialAngularVelocity; ///< The initial angular velocity of the particles in Euler angles (degrees). Default: (0, 0, 0).
  257. Vector3 angularVelocityVariance; ///< The variance in angular velocity. Default: (0, 0, 0).
  258. float lifetime; ///< The lifetime of the particles in seconds. Default: 1.0f.
  259. float lifetimeVariance; ///< The variance in lifetime in seconds. Default: 0.0f.
  260. float emissionTimer; ///< Use to control automatic emission, should not be modified manually.
  261. float emissionRate; ///< The rate of particle emission in particles per second. Default: 10.0f.
  262. float spreadAngle; ///< The angle of propagation of the particles in a cone (degrees). Default: 0.0f.
  263. R3D_InterpolationCurve* scaleOverLifetime; ///< Curve controlling the scale evolution of the particles over their lifetime. Default: NULL.
  264. R3D_InterpolationCurve* speedOverLifetime; ///< Curve controlling the speed evolution of the particles over their lifetime. Default: NULL.
  265. R3D_InterpolationCurve* opacityOverLifetime; ///< Curve controlling the opacity evolution of the particles over their lifetime. Default: NULL.
  266. R3D_InterpolationCurve* angularVelocityOverLifetime; ///< Curve controlling the angular velocity evolution of the particles over their lifetime. Default: NULL.
  267. bool autoEmission; /**< Indicates whether particle emission is automatic when calling `R3D_UpdateParticleSystem`.
  268. * If false, emission is manual using `R3D_EmitParticle`. Default: true.
  269. */
  270. } R3D_ParticleSystem;
  271. /* === Extern C guard === */
  272. #ifdef __cplusplus
  273. extern "C" {
  274. #endif // __cplusplus
  275. // --------------------------------------------
  276. // CORE: Init And Config Functions
  277. // --------------------------------------------
  278. /**
  279. * @brief Initializes the rendering engine.
  280. *
  281. * This function sets up the internal rendering system with the provided resolution
  282. * and state flags, which define the internal behavior. These flags can be modified
  283. * later via R3D_SetState.
  284. *
  285. * @param resWidth Width of the internal resolution.
  286. * @param resHeight Height of the internal resolution.
  287. * @param flags Flags indicating internal behavior (modifiable via R3D_SetState).
  288. */
  289. R3DAPI void R3D_Init(int resWidth, int resHeight, unsigned int flags);
  290. /**
  291. * @brief Closes the rendering engine and deallocates all resources.
  292. *
  293. * This function shuts down the rendering system and frees all allocated memory,
  294. * including the resources associated with the created lights.
  295. */
  296. R3DAPI void R3D_Close(void);
  297. /**
  298. * @brief Checks if a specific internal state flag is set.
  299. *
  300. * @param flag The state flag to check.
  301. * @return True if the flag is set, false otherwise.
  302. */
  303. R3DAPI bool R3D_HasState(unsigned int flag);
  304. /**
  305. * @brief Sets internal state flags for the rendering engine.
  306. *
  307. * This function modifies the behavior of the rendering engine by setting one or more
  308. * state flags. Flags can be later cleared with R3D_ClearState.
  309. *
  310. * @param flags The flags to set.
  311. */
  312. R3DAPI void R3D_SetState(unsigned int flags);
  313. /**
  314. * @brief Clears specific internal state flags.
  315. *
  316. * This function clears one or more previously set state flags, modifying the
  317. * behavior of the rendering engine accordingly.
  318. *
  319. * @param flags The flags to clear.
  320. */
  321. R3DAPI void R3D_ClearState(unsigned int flags);
  322. /**
  323. * @brief Gets the current internal resolution.
  324. *
  325. * This function retrieves the current internal resolution being used by the
  326. * rendering engine.
  327. *
  328. * @param width Pointer to store the width of the internal resolution.
  329. * @param height Pointer to store the height of the internal resolution.
  330. */
  331. R3DAPI void R3D_GetResolution(int* width, int* height);
  332. /**
  333. * @brief Updates the internal resolution.
  334. *
  335. * This function changes the internal resolution of the rendering engine. Note that
  336. * this process destroys and recreates all framebuffers, which may be a slow operation.
  337. *
  338. * @param width The new width for the internal resolution.
  339. * @param height The new height for the internal resolution.
  340. *
  341. * @warning This function may be slow due to the destruction and recreation of framebuffers.
  342. */
  343. R3DAPI void R3D_UpdateResolution(int width, int height);
  344. /**
  345. * @brief Sets a custom render target.
  346. *
  347. * This function allows rendering to a custom framebuffer instead of the main one.
  348. * Passing `NULL` will revert back to rendering to the main framebuffer.
  349. *
  350. * @param target The custom render target (can be NULL to revert to the default framebuffer).
  351. */
  352. R3DAPI void R3D_SetRenderTarget(RenderTexture* target);
  353. /**
  354. * @brief Defines the bounds of the scene for directional light calculations.
  355. *
  356. * This function sets the scene bounds used to determine which areas should be illuminated
  357. * by directional lights. It is the user's responsibility to calculate and provide the
  358. * correct bounds.
  359. *
  360. * @param sceneBounds The bounding box defining the scene's dimensions.
  361. */
  362. R3DAPI void R3D_SetSceneBounds(BoundingBox sceneBounds);
  363. // --------------------------------------------
  364. // CORE: Rendering Config Functions
  365. // --------------------------------------------
  366. /**
  367. * @brief Applies a render mode (Deferred or Forward).
  368. *
  369. * This function sets the current render mode to either deferred or forward. It can
  370. * be called at any time, including between `R3D_Begin` and `R3D_End`. The set mode
  371. * will apply to all subsequent draw calls.
  372. *
  373. * @param mode The render mode to apply.
  374. */
  375. R3DAPI void R3D_ApplyRenderMode(R3D_RenderMode mode);
  376. /**
  377. * @brief Sets the active blend mode for rendering.
  378. *
  379. * This function sets the current blend mode, which determines how the colors of
  380. * the current object are blended with the colors of the background or other objects
  381. * in the scene. It can be called at any time, including between `R3D_Begin` and `R3D_End`.
  382. * The set blend mode will apply to all subsequent draw calls.
  383. *
  384. * @note The blend mode is applied only if you are in forward rendering mode or auto-detect mode.
  385. *
  386. * @param mode The blend mode to apply.
  387. */
  388. R3DAPI void R3D_ApplyBlendMode(R3D_BlendMode mode);
  389. /**
  390. * @brief Sets the shadow casting mode for meshes.
  391. *
  392. * This function controls how meshes cast shadows in the scene. It can be
  393. * called at any time, including between `R3D_Begin` and `R3D_End`. The selected mode
  394. * will apply to all subsequent draw calls.
  395. *
  396. * @param mode The shadow casting mode to apply.
  397. */
  398. R3DAPI void R3D_ApplyShadowCastMode(R3D_ShadowCastMode mode);
  399. /**
  400. * @brief Applies a billboard mode to sprites or meshes.
  401. *
  402. * This function sets the current billboard mode, determining how objects orient
  403. * themselves relative to the camera. It can be called at any time, including
  404. * between `R3D_Begin` and `R3D_End`. The set mode will apply to all subsequent
  405. * draw calls.
  406. *
  407. * @param mode The billboard mode to apply.
  408. */
  409. R3DAPI void R3D_ApplyBillboardMode(R3D_BillboardMode mode);
  410. /**
  411. * @brief Sets an alpha threshold for forward rendering.
  412. *
  413. * This function defines an alpha scissor threshold, determining the minimum alpha
  414. * value required for a fragment to be rendered. Fragments with an alpha value below
  415. * the threshold will be discarded.
  416. *
  417. * @param threshold The alpha value threshold (usually from 0.0 to 1.0).
  418. */
  419. R3DAPI void R3D_ApplyAlphaScissorThreshold(float threshold);
  420. // --------------------------------------------
  421. // CORE: Drawing Functions
  422. // --------------------------------------------
  423. /**
  424. * @brief Begins a rendering session for a 3D camera.
  425. *
  426. * This function starts a rendering session, preparing the engine to handle subsequent
  427. * draw calls using the provided camera settings.
  428. *
  429. * @param camera The camera to use for rendering the scene.
  430. */
  431. R3DAPI void R3D_Begin(Camera3D camera);
  432. /**
  433. * @brief Ends the current rendering session.
  434. *
  435. * This function signals the end of a rendering session, at which point the engine
  436. * will process all necessary render passes and output the final result to the main
  437. * or custom framebuffer.
  438. */
  439. R3DAPI void R3D_End(void);
  440. /**
  441. * @brief Draws a mesh with a specified material and transformation.
  442. *
  443. * This function renders a mesh with the provided material and transformation matrix.
  444. *
  445. * @param mesh The mesh to render.
  446. * @param material The material to apply to the mesh.
  447. * @param transform The transformation matrix to apply to the mesh.
  448. */
  449. R3DAPI void R3D_DrawMesh(Mesh mesh, Material material, Matrix transform);
  450. /**
  451. * @brief Draws a mesh with instancing support.
  452. *
  453. * This function renders a mesh multiple times with different transformation matrices
  454. * for each instance.
  455. *
  456. * @param mesh The mesh to render.
  457. * @param material The material to apply to the mesh.
  458. * @param instanceTransforms Array of transformation matrices for each instance.
  459. * @param instanceCount The number of instances to render.
  460. */
  461. R3DAPI void R3D_DrawMeshInstanced(Mesh mesh, Material material, Matrix* instanceTransforms, int instanceCount);
  462. /**
  463. * @brief Draws a mesh with instancing support and different colors per instance.
  464. *
  465. * This function renders a mesh multiple times with different transformation matrices
  466. * and different colors for each instance.
  467. *
  468. * @param mesh The mesh to render.
  469. * @param material The material to apply to the mesh.
  470. * @param instanceTransforms Array of transformation matrices for each instance.
  471. * @param instanceColors Array of colors for each instance.
  472. * @param instanceCount The number of instances to render.
  473. */
  474. R3DAPI void R3D_DrawMeshInstancedEx(Mesh mesh, Material material, Matrix* instanceTransforms, Color* instanceColors, int instanceCount);
  475. /**
  476. * @brief Draws a mesh with instancing support, a global transformation, and different colors per instance.
  477. *
  478. * This function renders a mesh multiple times using instancing, with a global transformation
  479. * applied to all instances, and individual transformation matrices and colors for each instance.
  480. * Each instance can have its own position, rotation, scale, and color while sharing the same mesh
  481. * and material.
  482. *
  483. * @param mesh The mesh to render.
  484. * @param material The material to apply to the mesh.
  485. * @param transform The global transformation matrix applied to all instances.
  486. * @param instanceTransforms Pointer to an array of transformation matrices for each instance, allowing unique transformations.
  487. * @param transformsStride The stride (in bytes) between consecutive transformation matrices in the array.
  488. * @param instanceColors Pointer to an array of colors for each instance, allowing unique colors.
  489. * @param colorsStride The stride (in bytes) between consecutive colors in the array.
  490. * @param instanceCount The number of instances to render.
  491. */
  492. R3DAPI void R3D_DrawMeshInstancedPro(Mesh mesh, Material material, Matrix transform,
  493. Matrix* instanceTransforms, int transformsStride,
  494. Color* instanceColors, int colorsStride,
  495. int instanceCount);
  496. /**
  497. * @brief Draws a model at a specified position and scale.
  498. *
  499. * This function renders a model at the given position with the specified scale factor.
  500. *
  501. * @param model The model to render.
  502. * @param position The position to place the model at.
  503. * @param scale The scale factor to apply to the model.
  504. */
  505. R3DAPI void R3D_DrawModel(Model model, Vector3 position, float scale);
  506. /**
  507. * @brief Draws a model with advanced transformation options.
  508. *
  509. * This function renders a model with a specified position, rotation axis, rotation
  510. * angle, and scale. It provides more control over how the model is transformed before
  511. * rendering.
  512. *
  513. * @param model The model to render.
  514. * @param position The position to place the model at.
  515. * @param rotationAxis The axis of rotation for the model.
  516. * @param rotationAngle The angle to rotate the model.
  517. * @param scale The scale factor to apply to the model.
  518. */
  519. R3DAPI void R3D_DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale);
  520. /**
  521. * @brief Draws a sprite at a specified position.
  522. *
  523. * This function renders a sprite in 3D space at the given position.
  524. * It supports negative scaling to flip the sprite.
  525. *
  526. * @param sprite The sprite to render.
  527. * @param position The position to place the sprite at.
  528. */
  529. R3DAPI void R3D_DrawSprite(R3D_Sprite sprite, Vector3 position);
  530. /**
  531. * @brief Draws a sprite with size and rotation options.
  532. *
  533. * This function allows rendering a sprite with a specified size and rotation.
  534. * It supports negative size values for flipping the sprite.
  535. *
  536. * @param sprite The sprite to render.
  537. * @param position The position to place the sprite at.
  538. * @param size The size of the sprite (negative values flip the sprite).
  539. * @param rotation The rotation angle in degrees.
  540. */
  541. R3DAPI void R3D_DrawSpriteEx(R3D_Sprite sprite, Vector3 position, Vector2 size, float rotation);
  542. /**
  543. * @brief Draws a sprite with full transformation control.
  544. *
  545. * This function provides advanced transformation options, allowing
  546. * customization of size, rotation axis, and rotation angle.
  547. * It supports all billboard modes, or can be drawn without billboarding.
  548. *
  549. * @param sprite The sprite to render.
  550. * @param position The position to place the sprite at.
  551. * @param size The size of the sprite (negative values flip the sprite).
  552. * @param rotationAxis The axis around which the sprite rotates.
  553. * @param rotationAngle The angle to rotate the sprite around the given axis.
  554. */
  555. R3DAPI void R3D_DrawSpritePro(R3D_Sprite sprite, Vector3 position, Vector2 size, Vector3 rotationAxis, float rotationAngle);
  556. /**
  557. * @brief Renders the current state of a CPU-based particle system.
  558. *
  559. * This function draws the particles of a CPU-simulated particle system
  560. * in their current state. It does not modify the simulation or update
  561. * particle properties such as position, velocity, or lifetime.
  562. *
  563. * @param system A pointer to the `R3D_ParticleSystem` to be rendered.
  564. * The particle system must be properly initialized and updated
  565. * to the desired state before calling this function.
  566. * @param mesh The mesh used to represent each particle.
  567. * @param material The material applied to the particle mesh.
  568. */
  569. R3DAPI void R3D_DrawParticleSystem(const R3D_ParticleSystem* system, Mesh mesh, Material material);
  570. /**
  571. * @brief Renders the current state of a CPU-based particle system with a global transformation.
  572. *
  573. * This function is similar to `R3D_DrawParticleSystem`, but it applies an additional
  574. * global transformation to all particles. This is useful for rendering particle effects
  575. * in a transformed space (e.g., attached to a moving object).
  576. *
  577. * @param system A pointer to the `R3D_ParticleSystem` to be rendered.
  578. * The particle system must be properly initialized and updated
  579. * to the desired state before calling this function.
  580. * @param mesh The mesh used to represent each particle.
  581. * @param material The material applied to the particle mesh.
  582. * @param transform A transformation matrix applied to all particles.
  583. */
  584. R3DAPI void R3D_DrawParticleSystemEx(const R3D_ParticleSystem* system, Mesh mesh, Material material, Matrix transform);
  585. // --------------------------------------------
  586. // LIGHTING: Lights Config Functions
  587. // --------------------------------------------
  588. /**
  589. * @brief Creates a new light of the specified type.
  590. *
  591. * This function creates a light of the given type. The light must be destroyed
  592. * manually when no longer needed by calling `R3D_DestroyLight`.
  593. *
  594. * @param type The type of light to create (directional, spot or omni-directional).
  595. * @return The ID of the created light.
  596. */
  597. R3DAPI R3D_Light R3D_CreateLight(R3D_LightType type);
  598. /**
  599. * @brief Destroys the specified light.
  600. *
  601. * This function deallocates the resources associated with the light and makes
  602. * the light ID invalid. It must be called after the light is no longer needed.
  603. *
  604. * @param id The ID of the light to destroy.
  605. */
  606. R3DAPI void R3D_DestroyLight(R3D_Light id);
  607. /**
  608. * @brief Checks if a light exists.
  609. *
  610. * This function checks if the specified light ID is valid and if the light exists.
  611. *
  612. * @param id The ID of the light to check.
  613. * @return True if the light exists, false otherwise.
  614. */
  615. R3DAPI bool R3D_IsLightExist(R3D_Light id);
  616. /**
  617. * @brief Gets the type of a light.
  618. *
  619. * This function returns the type of the specified light (directional, spot or omni-directional).
  620. *
  621. * @param id The ID of the light.
  622. * @return The type of the light.
  623. */
  624. R3DAPI R3D_LightType R3D_GetLightType(R3D_Light id);
  625. /**
  626. * @brief Checks if a light is active.
  627. *
  628. * This function checks whether the specified light is currently active (enabled or disabled).
  629. *
  630. * @param id The ID of the light to check.
  631. * @return True if the light is active, false otherwise.
  632. */
  633. R3DAPI bool R3D_IsLightActive(R3D_Light id);
  634. /**
  635. * @brief Toggles the state of a light (active or inactive).
  636. *
  637. * This function toggles the state of the specified light, turning it on if it is off,
  638. * or off if it is on.
  639. *
  640. * @param id The ID of the light to toggle.
  641. */
  642. R3DAPI void R3D_ToggleLight(R3D_Light id);
  643. /**
  644. * @brief Sets the active state of a light.
  645. *
  646. * This function allows manually turning a light on or off by specifying its active state.
  647. *
  648. * @param id The ID of the light to set the active state for.
  649. * @param active True to activate the light, false to deactivate it.
  650. */
  651. R3DAPI void R3D_SetLightActive(R3D_Light id, bool active);
  652. /**
  653. * @brief Gets the color of a light.
  654. *
  655. * This function retrieves the color of the specified light as a `Color` structure.
  656. *
  657. * @param id The ID of the light.
  658. * @return The color of the light as a `Color` structure.
  659. */
  660. R3DAPI Color R3D_GetLightColor(R3D_Light id);
  661. /**
  662. * @brief Gets the color of a light as a `Vector3`.
  663. *
  664. * This function retrieves the color of the specified light as a `Vector3`, where each
  665. * component (x, y, z) represents the RGB values of the light.
  666. *
  667. * @param id The ID of the light.
  668. * @return The color of the light as a `Vector3`.
  669. */
  670. R3DAPI Vector3 R3D_GetLightColorV(R3D_Light id);
  671. /**
  672. * @brief Sets the color of a light.
  673. *
  674. * This function sets the color of the specified light using a `Color` structure.
  675. *
  676. * @param id The ID of the light.
  677. * @param color The new color to set for the light.
  678. */
  679. R3DAPI void R3D_SetLightColor(R3D_Light id, Color color);
  680. /**
  681. * @brief Sets the color of a light using a `Vector3`.
  682. *
  683. * This function sets the color of the specified light using a `Vector3`, where each
  684. * component (x, y, z) represents the RGB values of the light.
  685. *
  686. * @param id The ID of the light.
  687. * @param color The new color to set for the light as a `Vector3`.
  688. */
  689. R3DAPI void R3D_SetLightColorV(R3D_Light id, Vector3 color);
  690. /**
  691. * @brief Gets the position of a light.
  692. *
  693. * This function retrieves the position of the specified light.
  694. * Only applicable to spot lights or omni-lights.
  695. *
  696. * @param id The ID of the light.
  697. * @return The position of the light as a `Vector3`.
  698. */
  699. R3DAPI Vector3 R3D_GetLightPosition(R3D_Light id);
  700. /**
  701. * @brief Sets the position of a light.
  702. *
  703. * This function sets the position of the specified light.
  704. * Only applicable to spot lights or omni-lights.
  705. *
  706. * @param id The ID of the light.
  707. * @param position The new position to set for the light.
  708. */
  709. R3DAPI void R3D_SetLightPosition(R3D_Light id, Vector3 position);
  710. /**
  711. * @brief Gets the direction of a light.
  712. *
  713. * This function retrieves the direction of the specified light.
  714. * Only applicable to directional lights or spot lights.
  715. *
  716. * @param id The ID of the light.
  717. * @return The direction of the light as a `Vector3`.
  718. */
  719. R3DAPI Vector3 R3D_GetLightDirection(R3D_Light id);
  720. /**
  721. * @brief Sets the direction of a light.
  722. *
  723. * This function sets the direction of the specified light.
  724. * Only applicable to directional lights or spot lights.
  725. *
  726. * @param id The ID of the light.
  727. * @param direction The new direction to set for the light.
  728. */
  729. R3DAPI void R3D_SetLightDirection(R3D_Light id, Vector3 direction);
  730. /**
  731. * @brief Sets the target of a directional light.
  732. *
  733. * This function sets the target that a directional light will point towards.
  734. * Only applicable to directional lights or spot lights.
  735. *
  736. * @param id The ID of the light.
  737. * @param target The target position the light should focus on.
  738. */
  739. R3DAPI void R3D_SetLightTarget(R3D_Light id, Vector3 target);
  740. /**
  741. * @brief Gets the energy level of a light.
  742. *
  743. * This function retrieves the energy level (intensity) of the specified light.
  744. * Energy typically affects the brightness of the light.
  745. *
  746. * @param id The ID of the light.
  747. * @return The energy level of the light.
  748. */
  749. R3DAPI float R3D_GetLightEnergy(R3D_Light id);
  750. /**
  751. * @brief Sets the energy level of a light.
  752. *
  753. * This function sets the energy (intensity) of the specified light.
  754. * A higher energy value will result in a brighter light.
  755. *
  756. * @param id The ID of the light.
  757. * @param energy The new energy value to set for the light.
  758. */
  759. R3DAPI void R3D_SetLightEnergy(R3D_Light id, float energy);
  760. /**
  761. * @brief Gets the specular intensity of a light.
  762. *
  763. * This function retrieves the current specular intensity of the specified light.
  764. * Specular intensity affects how shiny surfaces appear when reflecting the light.
  765. *
  766. * @param id The ID of the light.
  767. * @return The current specular intensity of the light.
  768. */
  769. R3DAPI float R3D_GetLightSpecular(R3D_Light id);
  770. /**
  771. * @brief Sets the specular intensity of a light.
  772. *
  773. * This function sets the specular intensity of the specified light.
  774. * Higher specular values result in stronger and sharper highlights on reflective surfaces.
  775. *
  776. * @param id The ID of the light.
  777. * @param specular The new specular intensity value to set for the light.
  778. */
  779. R3DAPI void R3D_SetLightSpecular(R3D_Light id, float specular);
  780. /**
  781. * @brief Gets the range of a light.
  782. *
  783. * This function retrieves the range of the specified light, which determines how far the light can affect.
  784. * Only applicable to spot lights or omni-lights.
  785. *
  786. * @param id The ID of the light.
  787. * @return The range of the light.
  788. */
  789. R3DAPI float R3D_GetLightRange(R3D_Light id);
  790. /**
  791. * @brief Sets the range of a light.
  792. *
  793. * This function sets the range of the specified light.
  794. * The range determines how far the light can illuminate the scene before it fades out.
  795. * Only applicable to spot lights or omni-lights.
  796. *
  797. * @param id The ID of the light.
  798. * @param range The new range to set for the light.
  799. */
  800. R3DAPI void R3D_SetLightRange(R3D_Light id, float range);
  801. /**
  802. * @brief Gets the size of a light source.
  803. *
  804. * This function retrieves the size of the specified light source, which is used for PCSS.
  805. * The size affects how shadows are computed and how soft or sharp they appear.
  806. *
  807. * @param id The ID of the light.
  808. * @return The size of the light.
  809. */
  810. R3DAPI float R3D_GetLightSize(R3D_Light id);
  811. /**
  812. * @brief Sets the size of a light source.
  813. *
  814. * This function sets the size of the specified light source.
  815. * The size influences how shadows are rendered, with larger sizes creating softer shadows.
  816. *
  817. * @param id The ID of the light.
  818. * @param size The new size to set for the light.
  819. */
  820. R3DAPI void R3D_SetLightSize(R3D_Light id, float size);
  821. /**
  822. * @brief Gets the attenuation factor of a light.
  823. *
  824. * This function retrieves the attenuation factor of the specified light.
  825. * Attenuation controls how the intensity of a light decreases with distance.
  826. * Only applicable to spot lights or omni-lights.
  827. *
  828. * @param id The ID of the light.
  829. * @return The attenuation factor of the light.
  830. */
  831. R3DAPI float R3D_GetLightAttenuation(R3D_Light id);
  832. /**
  833. * @brief Sets the attenuation factor of a light.
  834. *
  835. * This function sets the attenuation factor of the specified light.
  836. * A higher attenuation value causes the light to lose intensity more quickly as the distance increases.
  837. * Only applicable to spot lights or omni-lights.
  838. *
  839. * @param id The ID of the light.
  840. * @param attenuation The new attenuation factor to set for the light.
  841. */
  842. R3DAPI void R3D_SetLightAttenuation(R3D_Light id, float attenuation);
  843. /**
  844. * @brief Gets the inner cutoff angle of a spotlight.
  845. *
  846. * This function retrieves the inner cutoff angle of a spotlight.
  847. * The inner cutoff defines the cone of light where the light is at full intensity.
  848. *
  849. * @param id The ID of the light.
  850. * @return The inner cutoff angle in degrees of the spotlight.
  851. */
  852. R3DAPI float R3D_GetLightInnerCutOff(R3D_Light id);
  853. /**
  854. * @brief Sets the inner cutoff angle of a spotlight.
  855. *
  856. * This function sets the inner cutoff angle of a spotlight.
  857. * The inner cutoff angle defines the cone where the light is at full intensity.
  858. * Anything outside this cone starts to fade.
  859. *
  860. * @param id The ID of the light.
  861. * @param degrees The new inner cutoff angle in degrees.
  862. */
  863. R3DAPI void R3D_SetLightInnerCutOff(R3D_Light id, float degrees);
  864. /**
  865. * @brief Gets the outer cutoff angle of a spotlight.
  866. *
  867. * This function retrieves the outer cutoff angle of a spotlight.
  868. * The outer cutoff defines the outer boundary of the light's cone, where the light starts to fade.
  869. *
  870. * @param id The ID of the light.
  871. * @return The outer cutoff angle in degrees of the spotlight.
  872. */
  873. R3DAPI float R3D_GetLightOuterCutOff(R3D_Light id);
  874. /**
  875. * @brief Sets the outer cutoff angle of a spotlight.
  876. *
  877. * This function sets the outer cutoff angle of a spotlight.
  878. * The outer cutoff defines the boundary of the light's cone where the light intensity starts to gradually decrease.
  879. *
  880. * @param id The ID of the light.
  881. * @param degrees The new outer cutoff angle in degrees.
  882. */
  883. R3DAPI void R3D_SetLightOuterCutOff(R3D_Light id, float degrees);
  884. // --------------------------------------------
  885. // LIGHTING: Shadow Config Functions
  886. // --------------------------------------------
  887. /**
  888. * @brief Enables shadow casting for a light and sets the resolution of its shadow map.
  889. *
  890. * This function enables shadow casting for a specified light and allocates a shadow map with the specified resolution.
  891. * Shadows can be rendered from the light based on this shadow map.
  892. *
  893. * @param id The ID of the light for which shadows should be enabled.
  894. * @param resolution The resolution of the shadow map to be used by the light.
  895. */
  896. R3DAPI void R3D_EnableShadow(R3D_Light id, int resolution);
  897. /**
  898. * @brief Disables shadow casting for a light and optionally destroys its shadow map.
  899. *
  900. * This function disables shadow casting for the specified light and optionally frees the memory
  901. * used by its shadow map. If `destroyMap` is true, the shadow map will be destroyed, otherwise,
  902. * the map will be retained but the light will no longer cast shadows.
  903. *
  904. * @param id The ID of the light for which shadows should be disabled.
  905. * @param destroyMap Whether or not to destroy the shadow map associated with the light.
  906. */
  907. R3DAPI void R3D_DisableShadow(R3D_Light id, bool destroyMap);
  908. /**
  909. * @brief Checks if shadow casting is enabled for a light.
  910. *
  911. * This function checks if shadow casting is currently enabled for the specified light.
  912. *
  913. * @param id The ID of the light.
  914. * @return True if shadow casting is enabled, false otherwise.
  915. */
  916. R3DAPI bool R3D_IsShadowEnabled(R3D_Light id);
  917. /**
  918. * @brief Checks if a light has an associated shadow map.
  919. *
  920. * This function checks if the specified light has a shadow map allocated for it.
  921. *
  922. * @param id The ID of the light.
  923. * @return True if the light has a shadow map, false otherwise.
  924. */
  925. R3DAPI bool R3D_HasShadowMap(R3D_Light id);
  926. /**
  927. * @brief Gets the shadow map update mode of a light.
  928. *
  929. * This function retrieves the current mode for updating the shadow map of a light. The mode can be:
  930. * - Interval: Updates the shadow map at a fixed interval.
  931. * - Continuous: Updates the shadow map continuously.
  932. * - Manual: Updates the shadow map manually (via explicit function calls).
  933. *
  934. * @param id The ID of the light.
  935. * @return The shadow map update mode.
  936. */
  937. R3DAPI R3D_ShadowUpdateMode R3D_GetShadowUpdateMode(R3D_Light id);
  938. /**
  939. * @brief Sets the shadow map update mode of a light.
  940. *
  941. * This function sets the mode for updating the shadow map of the specified light.
  942. * The update mode controls when and how often the shadow map is refreshed.
  943. *
  944. * @param id The ID of the light.
  945. * @param mode The update mode to set for the shadow map (Interval, Continuous, or Manual).
  946. */
  947. R3DAPI void R3D_SetShadowUpdateMode(R3D_Light id, R3D_ShadowUpdateMode mode);
  948. /**
  949. * @brief Gets the frequency of shadow map updates for the interval update mode.
  950. *
  951. * This function retrieves the frequency (in milliseconds) at which the shadow map should be updated when
  952. * the interval update mode is enabled. This function is only relevant if the shadow map update mode is set
  953. * to "Interval".
  954. *
  955. * @param id The ID of the light.
  956. * @return The frequency in milliseconds at which the shadow map is updated.
  957. */
  958. R3DAPI int R3D_GetShadowUpdateFrequency(R3D_Light id);
  959. /**
  960. * @brief Sets the frequency of shadow map updates for the interval update mode.
  961. *
  962. * This function sets the frequency (in milliseconds) at which the shadow map should be updated when
  963. * the interval update mode is enabled. This function is only relevant if the shadow map update mode is set
  964. * to "Interval".
  965. *
  966. * @param id The ID of the light.
  967. * @param msec The frequency in milliseconds at which to update the shadow map.
  968. */
  969. R3DAPI void R3D_SetShadowUpdateFrequency(R3D_Light id, int msec);
  970. /**
  971. * @brief Forces an immediate update of the shadow map during the next rendering pass.
  972. *
  973. * This function forces the shadow map of the specified light to be updated during the next call to `R3D_End`.
  974. * This is primarily used for the manual update mode, but may also work for the interval mode.
  975. *
  976. * @param id The ID of the light.
  977. */
  978. R3DAPI void R3D_UpdateShadowMap(R3D_Light id);
  979. /**
  980. * @brief Gets the shadow bias of a light.
  981. *
  982. * This function retrieves the shadow bias value for the specified light. The shadow bias helps prevent shadow artifacts,
  983. * such as shadow acne, by slightly offsetting the depth comparisons used in shadow mapping.
  984. *
  985. * @param id The ID of the light.
  986. * @return The shadow bias value.
  987. */
  988. R3DAPI float R3D_GetShadowBias(R3D_Light id);
  989. /**
  990. * @brief Sets the shadow bias of a light.
  991. *
  992. * This function sets the shadow bias value for the specified light. Adjusting the shadow bias can help avoid shadow
  993. * artifacts such as shadow acne by modifying the depth comparisons used in shadow mapping.
  994. *
  995. * @param id The ID of the light.
  996. * @param value The shadow bias value to set.
  997. */
  998. R3DAPI void R3D_SetShadowBias(R3D_Light id, float value);
  999. // --------------------------------------------
  1000. // LIGHTING: Light Helper Functions
  1001. // --------------------------------------------
  1002. /**
  1003. * @brief Draws the area of influence of the light in 3D space.
  1004. *
  1005. * This function visualizes the area affected by a light in 3D space.
  1006. * It draws the light's influence, such as the cone for spotlights or the volume for omni-lights.
  1007. * This function is only relevant for spotlights and omni-lights.
  1008. *
  1009. * @note This function should be called while using the default 3D rendering mode of raylib,
  1010. * not with R3D's rendering mode. It uses raylib's 3D drawing functions to render the light's shape.
  1011. *
  1012. * @param id The ID of the light.
  1013. */
  1014. R3DAPI void R3D_DrawLightShape(R3D_Light id);
  1015. // --------------------------------------------
  1016. // PARTICLES: Particle System Functions
  1017. // --------------------------------------------
  1018. /**
  1019. * @brief Loads a particle emitter system for the CPU.
  1020. *
  1021. * This function initializes a particle emitter system on the CPU with a specified maximum
  1022. * number of particles. It prepares the necessary data structures and allocates memory
  1023. * for managing the particles.
  1024. *
  1025. * @param maxParticles The maximum number of particles the system can handle at once.
  1026. * This value determines the memory allocation and performance constraints.
  1027. * @return A newly initialized `R3D_ParticleSystem` structure.
  1028. * The caller is responsible for properly managing and freeing the system when no longer needed.
  1029. */
  1030. R3DAPI R3D_ParticleSystem R3D_LoadParticleSystem(int maxParticles);
  1031. /**
  1032. * @brief Unloads the particle emitter system and frees allocated memory.
  1033. *
  1034. * This function deallocates the memory used by the particle emitter system and clears the associated resources.
  1035. * It should be called when the particle system is no longer needed to prevent memory leaks.
  1036. *
  1037. * @param system A pointer to the `R3D_ParticleSystem` to be unloaded.
  1038. */
  1039. R3DAPI void R3D_UnloadParticleSystem(R3D_ParticleSystem* system);
  1040. /**
  1041. * @brief Emits a particle in the particle system.
  1042. *
  1043. * This function triggers the emission of a new particle in the particle system. It handles the logic of adding a new
  1044. * particle to the system and initializing its properties based on the current state of the system.
  1045. *
  1046. * @param system A pointer to the `R3D_ParticleSystemCPU` where the particle will be emitted.
  1047. * @return `true` if the particle was successfully emitted, `false` if the system is at full capacity and cannot emit more particles.
  1048. */
  1049. R3DAPI bool R3D_EmitParticle(R3D_ParticleSystem* system);
  1050. /**
  1051. * @brief Updates the particle emitter system by advancing particle positions.
  1052. *
  1053. * This function updates the positions and properties of particles in the system based on the elapsed time. It handles
  1054. * simulation of particle movement, gravity, and other physics-based calculations.
  1055. *
  1056. * @param system A pointer to the `R3D_ParticleSystem` to be updated.
  1057. * @param deltaTime The time elapsed since the last update (in seconds).
  1058. */
  1059. R3DAPI void R3D_UpdateParticleSystem(R3D_ParticleSystem* system, float deltaTime);
  1060. /**
  1061. * @brief Computes and returns the AABB (Axis-Aligned Bounding Box) of the particle emitter system.
  1062. *
  1063. * This function performs a simulation of the particle system to estimate the AABB of the particles. It calculates the
  1064. * possible positions of each particle at both half of their lifetime and at the end of their lifetime. The resulting
  1065. * AABB approximates the region of space the particle system occupies, which helps in determining if the system should
  1066. * be rendered or not based on camera frustum culling.
  1067. *
  1068. * @param system A pointer to the `R3D_ParticleSystem` whose AABB is to be computed.
  1069. * @return The computed `BoundingBox` of the particle system.
  1070. */
  1071. R3DAPI BoundingBox R3D_GetParticleSystemBoundingBox(R3D_ParticleSystem* system);
  1072. // --------------------------------------------
  1073. // CURVES: Interpolation Curves Functions
  1074. // --------------------------------------------
  1075. /**
  1076. * @brief Load a sprite from a texture.
  1077. *
  1078. * This function creates a `R3D_Sprite` using the provided texture. The texture will be used as the albedo of the sprite's material.
  1079. *
  1080. * @warning The lifetime of the provided texture is managed by the caller.
  1081. *
  1082. * @param texture The `Texture2D` to be used for the sprite.
  1083. * @param xFrameCount The number of frames in the horizontal direction.
  1084. * @param yFrameCount The number of frames in the vertical direction.
  1085. *
  1086. * @return A `R3D_Sprite` object initialized with the given texture and frame configuration.
  1087. */
  1088. R3DAPI R3D_Sprite R3D_LoadSprite(Texture2D texture, int xFrameCount, int yFrameCount);
  1089. /**
  1090. * @brief Unload a sprite and free associated resources.
  1091. *
  1092. * This function releases the resources allocated for a `R3D_Sprite`.
  1093. * It should be called when the sprite is no longer needed to avoid memory leaks.
  1094. *
  1095. * @warning This function does not free the texture associated with the sprite.
  1096. * The caller is responsible for managing the texture's lifetime.
  1097. *
  1098. * @param sprite The `R3D_Sprite` to be unloaded.
  1099. */
  1100. R3DAPI void R3D_UnloadSprite(R3D_Sprite sprite);
  1101. /**
  1102. * @brief Updates the animation of a sprite.
  1103. *
  1104. * This function updates the current frame of the sprite's animation based on the provided speed. The animation frames are read from
  1105. * right to left, advancing the cursor to the next row after completing a line.
  1106. *
  1107. * @note The `speed` parameter can be calculated as the number of frames per second multiplied by `GetFrameTime()`.
  1108. *
  1109. * @param sprite A pointer to the `R3D_Sprite` to update.
  1110. * @param speed The speed at which the animation progresses, in frames per second.
  1111. */
  1112. R3DAPI void R3D_UpdateSprite(R3D_Sprite* sprite, float speed);
  1113. /**
  1114. * @brief Updates the animation of a sprite with specified frame boundaries.
  1115. *
  1116. * This function updates the current frame of the sprite's animation while restricting it between `firstFrame` and `lastFrame`.
  1117. * This is useful for spritesheets containing multiple animations.
  1118. *
  1119. * @note The frames are read from right to left, and the cursor moves to the next row after completing a line.
  1120. * @note The `speed` parameter can be calculated as the number of frames per second multiplied by `GetFrameTime()`.
  1121. *
  1122. * @param sprite A pointer to the `R3D_Sprite` to update.
  1123. * @param firstFrame The first frame of the animation loop.
  1124. * @param lastFrame The last frame of the animation loop.
  1125. * @param speed The speed at which the animation progresses, in frames per second.
  1126. */
  1127. R3DAPI void R3D_UpdateSpriteEx(R3D_Sprite* sprite, int firstFrame, int lastFrame, float speed);
  1128. // --------------------------------------------
  1129. // CURVES: Interpolation Curves Functions
  1130. // --------------------------------------------
  1131. /**
  1132. * @brief Loads an interpolation curve with a specified initial capacity.
  1133. *
  1134. * This function initializes an interpolation curve with the given capacity. The capacity represents the initial size of
  1135. * the memory allocated for the curve. You can add keyframes to the curve using `R3D_AddKeyframe`. If adding a keyframe
  1136. * exceeds the initial capacity, the system will automatically reallocate memory and double the initial capacity.
  1137. *
  1138. * @param capacity The initial capacity (size) of the interpolation curve. This is the number of keyframes that can be added
  1139. * before a reallocation occurs.
  1140. * @return An initialized interpolation curve with the specified capacity.
  1141. */
  1142. R3DAPI R3D_InterpolationCurve R3D_LoadInterpolationCurve(int capacity);
  1143. /**
  1144. * @brief Unloads the interpolation curve and frees the allocated memory.
  1145. *
  1146. * This function deallocates the memory associated with the interpolation curve and clears any keyframes stored in it.
  1147. * It should be called when the curve is no longer needed to avoid memory leaks.
  1148. *
  1149. * @param curve The interpolation curve to be unloaded.
  1150. */
  1151. R3DAPI void R3D_UnloadInterpolationCurve(R3D_InterpolationCurve curve);
  1152. /**
  1153. * @brief Adds a keyframe to the interpolation curve.
  1154. *
  1155. * This function adds a keyframe to the given interpolation curve at a specific time and value. If the addition of the
  1156. * keyframe requires reallocating memory and the reallocation fails, the previously allocated memory and keyframes are
  1157. * preserved, but the new keyframe is not added.
  1158. *
  1159. * @param curve A pointer to the interpolation curve to which the keyframe will be added.
  1160. * @param time The time at which the keyframe will be added.
  1161. * @param value The value associated with the keyframe.
  1162. * @return `true` if the keyframe was successfully added, or `false` if the reallocation failed.
  1163. */
  1164. R3DAPI bool R3D_AddKeyframe(R3D_InterpolationCurve* curve, float time, float value);
  1165. /**
  1166. * @brief Evaluates the interpolation curve at a specific time.
  1167. *
  1168. * This function evaluates the value of the interpolation curve at a given time. The curve will interpolate between
  1169. * keyframes based on the time provided.
  1170. *
  1171. * @param curve The interpolation curve to be evaluated.
  1172. * @param time The time at which to evaluate the curve.
  1173. * @return The value of the curve at the specified time.
  1174. */
  1175. R3DAPI float R3D_EvaluateCurve(R3D_InterpolationCurve curve, float time);
  1176. // --------------------------------------------
  1177. // ENVIRONMENT: Background And Ambient
  1178. // --------------------------------------------
  1179. /**
  1180. * @brief Sets the background color when no skybox is enabled.
  1181. *
  1182. * This function defines the background color to be used when no skybox is active.
  1183. * The color will be used for the clear color of the scene.
  1184. *
  1185. * @param color The color to set as the background color.
  1186. */
  1187. R3DAPI void R3D_SetBackgroundColor(Color color);
  1188. /**
  1189. * @brief Sets the ambient light color when no skybox is enabled.
  1190. *
  1191. * This function defines the ambient light color to be used when no skybox is active.
  1192. * It affects the overall lighting of the scene when no skybox is present.
  1193. *
  1194. * @param color The color to set for ambient light.
  1195. */
  1196. R3DAPI void R3D_SetAmbientColor(Color color);
  1197. /**
  1198. * @brief Enables a skybox for the scene.
  1199. *
  1200. * This function enables a skybox in the scene, replacing the default background with
  1201. * a 3D environment. The skybox is defined by the specified skybox asset.
  1202. *
  1203. * @param skybox The skybox to enable.
  1204. */
  1205. R3DAPI void R3D_EnableSkybox(R3D_Skybox skybox);
  1206. /**
  1207. * @brief Disables the skybox in the scene.
  1208. *
  1209. * This function disables the skybox, reverting back to the default background
  1210. * color (or no background if none is set). It should be called to remove the skybox
  1211. * from the scene.
  1212. */
  1213. R3DAPI void R3D_DisableSkybox(void);
  1214. /**
  1215. * @brief Sets the rotation of the skybox.
  1216. *
  1217. * This function allows you to specify the rotation of the skybox along the
  1218. * pitch, yaw, and roll axes, which allows the skybox to be rotated in the scene.
  1219. *
  1220. * @param pitch The rotation angle around the X-axis (in degrees).
  1221. * @param yaw The rotation angle around the Y-axis (in degrees).
  1222. * @param roll The rotation angle around the Z-axis (in degrees).
  1223. */
  1224. R3DAPI void R3D_SetSkyboxRotation(float pitch, float yaw, float roll);
  1225. /**
  1226. * @brief Gets the current rotation of the skybox.
  1227. *
  1228. * This function returns the current rotation of the skybox as a vector containing
  1229. * the pitch, yaw, and roll values in degrees.
  1230. *
  1231. * @return A vector containing the current pitch, yaw, and roll of the skybox.
  1232. */
  1233. R3DAPI Vector3 R3D_GetSkyboxRotation(void);
  1234. // --------------------------------------------
  1235. // ENVIRONMENT: SSAO Config Functions
  1236. // --------------------------------------------
  1237. /**
  1238. * @brief Enables or disables Screen Space Ambient Occlusion (SSAO).
  1239. *
  1240. * This function toggles the SSAO effect. When enabled, SSAO enhances the realism
  1241. * of the scene by simulating ambient occlusion, darkening areas where objects
  1242. * are close together or in corners.
  1243. *
  1244. * @param enabled Whether to enable or disable SSAO.
  1245. */
  1246. R3DAPI void R3D_SetSSAO(bool enabled);
  1247. /**
  1248. * @brief Gets the current state of SSAO.
  1249. *
  1250. * This function checks if SSAO is currently enabled or disabled.
  1251. *
  1252. * @return True if SSAO is enabled, false otherwise.
  1253. */
  1254. R3DAPI bool R3D_GetSSAO(void);
  1255. /**
  1256. * @brief Sets the radius for SSAO effect.
  1257. *
  1258. * This function sets the radius used by the SSAO effect to calculate occlusion.
  1259. * A higher value will affect a larger area around each pixel, while a smaller value
  1260. * will create sharper and more localized occlusion.
  1261. *
  1262. * @param value The radius value to set for SSAO.
  1263. */
  1264. R3DAPI void R3D_SetSSAORadius(float value);
  1265. /**
  1266. * @brief Gets the current SSAO radius.
  1267. *
  1268. * This function retrieves the current radius value used by the SSAO effect.
  1269. *
  1270. * @return The radius value for SSAO.
  1271. */
  1272. R3DAPI float R3D_GetSSAORadius(void);
  1273. /**
  1274. * @brief Sets the bias for SSAO effect.
  1275. *
  1276. * This function sets the bias used by the SSAO effect to adjust how much occlusion
  1277. * is applied to the scene. A higher value can reduce artifacts, but may also
  1278. * result in less pronounced ambient occlusion.
  1279. *
  1280. * @param value The bias value for SSAO.
  1281. */
  1282. R3DAPI void R3D_SetSSAOBias(float value);
  1283. /**
  1284. * @brief Gets the current SSAO bias.
  1285. *
  1286. * This function retrieves the current bias value used by the SSAO effect.
  1287. *
  1288. * @return The SSAO bias value.
  1289. */
  1290. R3DAPI float R3D_GetSSAOBias(void);
  1291. /**
  1292. * @brief Sets the number of iterations for SSAO effect.
  1293. *
  1294. * This function sets the number of iterations (or samples) used to calculate the
  1295. * SSAO effect. A higher value will result in a more accurate and smoother effect,
  1296. * but may also be more performance-intensive.
  1297. *
  1298. * @param value The number of iterations for SSAO.
  1299. */
  1300. R3DAPI void R3D_SetSSAOIterations(int value);
  1301. /**
  1302. * @brief Gets the current number of SSAO iterations.
  1303. *
  1304. * This function retrieves the current number of iterations (or samples) used to
  1305. * calculate the SSAO effect.
  1306. *
  1307. * @return The number of SSAO iterations.
  1308. */
  1309. R3DAPI int R3D_GetSSAOIterations(void);
  1310. // --------------------------------------------
  1311. // ENVIRONMENT: Bloom Config Functions
  1312. // --------------------------------------------
  1313. /**
  1314. * @brief Sets the bloom mode.
  1315. *
  1316. * This function configures the bloom effect mode, which determines how the bloom
  1317. * effect is applied to the rendered scene.
  1318. *
  1319. * @param mode The bloom mode to set.
  1320. */
  1321. R3DAPI void R3D_SetBloomMode(R3D_Bloom mode);
  1322. /**
  1323. * @brief Gets the current bloom mode.
  1324. *
  1325. * This function retrieves the bloom mode currently applied to the scene.
  1326. *
  1327. * @return The current bloom mode.
  1328. */
  1329. R3DAPI R3D_Bloom R3D_GetBloomMode(void);
  1330. /**
  1331. * @brief Sets the bloom intensity.
  1332. *
  1333. * This function controls the strength of the bloom effect. Higher values result
  1334. * in a more intense glow effect on bright areas of the scene.
  1335. *
  1336. * @param value The intensity value for bloom.
  1337. */
  1338. R3DAPI void R3D_SetBloomIntensity(float value);
  1339. /**
  1340. * @brief Gets the current bloom intensity.
  1341. *
  1342. * This function retrieves the intensity value of the bloom effect.
  1343. *
  1344. * @return The current bloom intensity.
  1345. */
  1346. R3DAPI float R3D_GetBloomIntensity(void);
  1347. /**
  1348. * @brief Sets the HDR threshold for bloom.
  1349. *
  1350. * This function defines the brightness threshold above which pixels contribute
  1351. * to the bloom effect. Lower values will make more areas of the image glow.
  1352. *
  1353. * @param value The HDR threshold for bloom.
  1354. */
  1355. R3DAPI void R3D_SetBloomHdrThreshold(float value);
  1356. /**
  1357. * @brief Gets the current HDR threshold for bloom.
  1358. *
  1359. * This function retrieves the brightness threshold above which pixels contribute
  1360. * to the bloom effect.
  1361. *
  1362. * @return The current HDR threshold for bloom.
  1363. */
  1364. R3DAPI float R3D_GetBloomHdrThreshold(void);
  1365. /**
  1366. * @brief Sets the HDR threshold for the sky in bloom.
  1367. *
  1368. * This function defines a separate HDR threshold for the sky when applying bloom.
  1369. * This allows finer control over the intensity of the bloom effect on sky elements.
  1370. *
  1371. * @param value The HDR threshold for bloom on the sky.
  1372. */
  1373. R3DAPI void R3D_SetBloomSkyHdrThreshold(float value);
  1374. /**
  1375. * @brief Gets the current HDR threshold for bloom on the sky.
  1376. *
  1377. * This function retrieves the HDR threshold specifically applied to the sky for bloom.
  1378. *
  1379. * @return The current HDR threshold for sky bloom.
  1380. */
  1381. R3DAPI float R3D_GetBloomSkyHdrThreshold(void);
  1382. /**
  1383. * @brief Sets the number of iterations for the bloom effect.
  1384. *
  1385. * This function defines how many iterations are performed to blur the bright areas.
  1386. * Higher values result in a smoother and more pronounced bloom effect but may
  1387. * impact performance.
  1388. *
  1389. * @param value The number of bloom iterations.
  1390. */
  1391. R3DAPI void R3D_SetBloomIterations(int value);
  1392. /**
  1393. * @brief Gets the current number of bloom iterations.
  1394. *
  1395. * This function retrieves the number of iterations used to process the bloom effect.
  1396. *
  1397. * @return The current number of bloom iterations.
  1398. */
  1399. R3DAPI int R3D_GetBloomIterations(void);
  1400. // --------------------------------------------
  1401. // ENVIRONMENT: Fog Config Functions
  1402. // --------------------------------------------
  1403. /**
  1404. * @brief Sets the fog mode.
  1405. *
  1406. * This function defines the type of fog effect applied to the scene.
  1407. * Different modes may provide linear, exponential, or volumetric fog effects.
  1408. *
  1409. * @param mode The fog mode to set.
  1410. */
  1411. R3DAPI void R3D_SetFogMode(R3D_Fog mode);
  1412. /**
  1413. * @brief Gets the current fog mode.
  1414. *
  1415. * This function retrieves the fog mode currently applied to the scene.
  1416. *
  1417. * @return The current fog mode.
  1418. */
  1419. R3DAPI R3D_Fog R3D_GetFogMode(void);
  1420. /**
  1421. * @brief Sets the color of the fog.
  1422. *
  1423. * This function defines the color of the fog effect applied to the scene.
  1424. * The fog color blends with objects as they are affected by fog.
  1425. *
  1426. * @param color The color to set for the fog.
  1427. */
  1428. R3DAPI void R3D_SetFogColor(Color color);
  1429. /**
  1430. * @brief Gets the current fog color.
  1431. *
  1432. * This function retrieves the color currently used for the fog effect.
  1433. *
  1434. * @return The current fog color.
  1435. */
  1436. R3DAPI Color R3D_GetFogColor(void);
  1437. /**
  1438. * @brief Sets the start distance of the fog.
  1439. *
  1440. * This function defines the distance from the camera at which fog begins to appear.
  1441. * Objects closer than this distance will not be affected by fog.
  1442. *
  1443. * @param value The start distance for the fog effect.
  1444. */
  1445. R3DAPI void R3D_SetFogStart(float value);
  1446. /**
  1447. * @brief Gets the current fog start distance.
  1448. *
  1449. * This function retrieves the distance at which the fog begins to be applied.
  1450. *
  1451. * @return The current fog start distance.
  1452. */
  1453. R3DAPI float R3D_GetFogStart(void);
  1454. /**
  1455. * @brief Sets the end distance of the fog.
  1456. *
  1457. * This function defines the distance from the camera at which fog reaches full intensity.
  1458. * Objects beyond this distance will be completely covered by fog.
  1459. *
  1460. * @param value The end distance for the fog effect.
  1461. */
  1462. R3DAPI void R3D_SetFogEnd(float value);
  1463. /**
  1464. * @brief Gets the current fog end distance.
  1465. *
  1466. * This function retrieves the distance at which the fog is fully applied.
  1467. *
  1468. * @return The current fog end distance.
  1469. */
  1470. R3DAPI float R3D_GetFogEnd(void);
  1471. /**
  1472. * @brief Sets the density of the fog.
  1473. *
  1474. * This function controls how thick the fog appears. Higher values result in
  1475. * denser fog, making objects fade out more quickly.
  1476. *
  1477. * @param value The density of the fog (higher values increase fog thickness).
  1478. */
  1479. R3DAPI void R3D_SetFogDensity(float value);
  1480. /**
  1481. * @brief Gets the current fog density.
  1482. *
  1483. * This function retrieves the current density of the fog.
  1484. *
  1485. * @return The current fog density.
  1486. */
  1487. R3DAPI float R3D_GetFogDensity(void);
  1488. // --------------------------------------------
  1489. // ENVIRONMENT: Tonemap Config Functions
  1490. // --------------------------------------------
  1491. /**
  1492. * @brief Sets the tonemapping mode.
  1493. *
  1494. * This function defines the tonemapping algorithm applied to the final rendered image.
  1495. * Different tonemap modes affect color balance, brightness compression, and overall
  1496. * scene appearance.
  1497. *
  1498. * @param mode The tonemap mode to set.
  1499. */
  1500. R3DAPI void R3D_SetTonemapMode(R3D_Tonemap mode);
  1501. /**
  1502. * @brief Gets the current tonemapping mode.
  1503. *
  1504. * This function retrieves the tonemap mode currently applied to the scene.
  1505. *
  1506. * @return The current tonemap mode.
  1507. */
  1508. R3DAPI R3D_Tonemap R3D_GetTonemapMode(void);
  1509. /**
  1510. * @brief Sets the exposure level for tonemapping.
  1511. *
  1512. * This function adjusts the exposure level used in tonemapping, affecting
  1513. * the overall brightness of the rendered scene.
  1514. *
  1515. * @param value The exposure value (higher values make the scene brighter).
  1516. */
  1517. R3DAPI void R3D_SetTonemapExposure(float value);
  1518. /**
  1519. * @brief Gets the current tonemap exposure level.
  1520. *
  1521. * This function retrieves the current exposure setting used in tonemapping.
  1522. *
  1523. * @return The current tonemap exposure value.
  1524. */
  1525. R3DAPI float R3D_GetTonemapExposure(void);
  1526. /**
  1527. * @brief Sets the white point for tonemapping.
  1528. *
  1529. * This function defines the reference white level, which determines how bright
  1530. * areas of the scene are mapped to the final output.
  1531. *
  1532. * @param value The white point value.
  1533. */
  1534. R3DAPI void R3D_SetTonemapWhite(float value);
  1535. /**
  1536. * @brief Gets the current tonemap white point.
  1537. *
  1538. * This function retrieves the white point setting used in tonemapping.
  1539. *
  1540. * @return The current tonemap white value.
  1541. */
  1542. R3DAPI float R3D_GetTonemapWhite(void);
  1543. // --------------------------------------------
  1544. // ENVIRONMENT: Color Adjustment Functions
  1545. // --------------------------------------------
  1546. /**
  1547. * @brief Sets the global brightness adjustment.
  1548. *
  1549. * This function controls the brightness of the final rendered image.
  1550. * Higher values make the image brighter, while lower values darken it.
  1551. *
  1552. * @param value The brightness adjustment value.
  1553. */
  1554. R3DAPI void R3D_SetBrightness(float value);
  1555. /**
  1556. * @brief Gets the current brightness level.
  1557. *
  1558. * This function retrieves the brightness setting applied to the scene.
  1559. *
  1560. * @return The current brightness value.
  1561. */
  1562. R3DAPI float R3D_GetBrightness(void);
  1563. /**
  1564. * @brief Sets the global contrast adjustment.
  1565. *
  1566. * This function controls the contrast of the final rendered image.
  1567. * Higher values increase the difference between dark and bright areas.
  1568. *
  1569. * @param value The contrast adjustment value.
  1570. */
  1571. R3DAPI void R3D_SetContrast(float value);
  1572. /**
  1573. * @brief Gets the current contrast level.
  1574. *
  1575. * This function retrieves the contrast setting applied to the scene.
  1576. *
  1577. * @return The current contrast value.
  1578. */
  1579. R3DAPI float R3D_GetContrast(void);
  1580. /**
  1581. * @brief Sets the global saturation adjustment.
  1582. *
  1583. * This function controls the color intensity of the final rendered image.
  1584. * Higher values make colors more vibrant, while lower values desaturate them.
  1585. *
  1586. * @param value The saturation adjustment value.
  1587. */
  1588. R3DAPI void R3D_SetSaturation(float value);
  1589. /**
  1590. * @brief Gets the current saturation level.
  1591. *
  1592. * This function retrieves the saturation setting applied to the scene.
  1593. *
  1594. * @return The current saturation value.
  1595. */
  1596. R3DAPI float R3D_GetSaturation(void);
  1597. // --------------------------------------------
  1598. // SKYBOX: Skybox Loading Functions
  1599. // --------------------------------------------
  1600. /**
  1601. * @brief Loads a skybox from a texture file.
  1602. *
  1603. * This function loads a skybox from a texture file using a specified cubemap layout.
  1604. * The layout defines how the six faces of the cubemap are arranged within the texture.
  1605. *
  1606. * @param fileName The path to the texture file.
  1607. * @param layout The cubemap layout format.
  1608. * @return The loaded skybox object.
  1609. */
  1610. R3DAPI R3D_Skybox R3D_LoadSkybox(const char* fileName, CubemapLayout layout);
  1611. /**
  1612. * @brief Loads a skybox from a high dynamic range (HDR) image.
  1613. *
  1614. * This function loads a skybox from an HDR image and converts it into a cubemap.
  1615. * The size parameter determines the resolution of the generated cubemap.
  1616. *
  1617. * @param fileName The path to the HDR image file.
  1618. * @param size The resolution of the cubemap (e.g., 512, 1024).
  1619. * @return The loaded skybox object.
  1620. */
  1621. R3DAPI R3D_Skybox R3D_LoadSkyboxHDR(const char* fileName, int size);
  1622. /**
  1623. * @brief Unloads a skybox and frees its resources.
  1624. *
  1625. * This function removes a previously loaded skybox from memory.
  1626. * It should be called when the skybox is no longer needed to prevent memory leaks.
  1627. *
  1628. * @param sky The skybox to unload.
  1629. */
  1630. R3DAPI void R3D_UnloadSkybox(R3D_Skybox sky);
  1631. // --------------------------------------------
  1632. // CULLING: Frustum Test Functions
  1633. // --------------------------------------------
  1634. /**
  1635. * @brief Checks if a point is inside the view frustum.
  1636. *
  1637. * This function determines whether a given 3D point is within the current camera's frustum.
  1638. * It must be called between `R3D_Begin` and `R3D_End`.
  1639. *
  1640. * @param position The position of the point to check.
  1641. * @return `true` if the point is inside the frustum, `false` otherwise.
  1642. */
  1643. R3DAPI bool R3D_IsPointInFrustum(Vector3 position);
  1644. /**
  1645. * @brief Checks if a point is inside the view frustum (alternative XYZ version).
  1646. *
  1647. * This function performs the same check as `R3D_IsPointInFrustum`, but allows specifying
  1648. * the point coordinates separately instead of using a `Vector3`.
  1649. * It must be called between `R3D_Begin` and `R3D_End`.
  1650. *
  1651. * @param x The X coordinate of the point.
  1652. * @param y The Y coordinate of the point.
  1653. * @param z The Z coordinate of the point.
  1654. * @return `true` if the point is inside the frustum, `false` otherwise.
  1655. */
  1656. R3DAPI bool R3D_IsPointInFrustumXYZ(float x, float y, float z);
  1657. /**
  1658. * @brief Checks if a sphere is inside the view frustum.
  1659. *
  1660. * This function tests whether a sphere, defined by a center position and radius,
  1661. * is at least partially inside the camera's frustum.
  1662. * It must be called between `R3D_Begin` and `R3D_End`.
  1663. *
  1664. * @param position The center of the sphere.
  1665. * @param radius The radius of the sphere.
  1666. * @return `true` if the sphere is at least partially inside the frustum, `false` otherwise.
  1667. */
  1668. R3DAPI bool R3D_IsSphereInFrustum(Vector3 position, float radius);
  1669. /**
  1670. * @brief Checks if an axis-aligned bounding box (AABB) is inside the view frustum.
  1671. *
  1672. * This function determines whether an AABB is at least partially visible within the camera's frustum.
  1673. * It must be called between `R3D_Begin` and `R3D_End`.
  1674. *
  1675. * @param aabb The bounding box to test.
  1676. * @return `true` if any part of the bounding box is inside the frustum, `false` otherwise.
  1677. */
  1678. R3DAPI bool R3D_IsBoundingBoxInFrustum(BoundingBox aabb);
  1679. // --------------------------------------------
  1680. // UTILS: Material Configuration Functions
  1681. // --------------------------------------------
  1682. /**
  1683. * @brief Sets the albedo (diffuse color) properties of a material.
  1684. *
  1685. * This function assigns an albedo texture and color to a material.
  1686. * If a texture is provided, it is used as the albedo map. The color is multiplied
  1687. * with the texture if both are set.
  1688. *
  1689. * @param material Pointer to the material to modify.
  1690. * @param texture Optional albedo texture (set to NULL for none).
  1691. * @param color Albedo color to apply.
  1692. */
  1693. R3DAPI void R3D_SetMaterialAlbedo(Material* material, Texture2D* texture, Color color);
  1694. /**
  1695. * @brief Sets the ambient occlusion properties of a material.
  1696. *
  1697. * This function assigns an ambient occlusion (AO) texture and intensity value to a material.
  1698. * If a texture is provided, it is used as the AO map. The intensity controls the effect strength.
  1699. *
  1700. * @param material Pointer to the material to modify.
  1701. * @param texture Optional occlusion texture (set to NULL for none).
  1702. * @param value Occlusion strength (0.0 to 1.0).
  1703. */
  1704. R3DAPI void R3D_SetMaterialOcclusion(Material* material, Texture2D* texture, float value);
  1705. /**
  1706. * @brief Sets the roughness properties of a material.
  1707. *
  1708. * This function assigns a roughness texture and scalar value to a material.
  1709. * If a texture is provided, it is used as the roughness map. The scalar value is multiplied
  1710. * with the texture if both are set.
  1711. *
  1712. * @param material Pointer to the material to modify.
  1713. * @param texture Optional roughness texture (set to NULL for none).
  1714. * @param value Roughness factor (0.0 = smooth, 1.0 = rough).
  1715. */
  1716. R3DAPI void R3D_SetMaterialRoughness(Material* material, Texture2D* texture, float value);
  1717. /**
  1718. * @brief Sets the metalness properties of a material.
  1719. *
  1720. * This function assigns a metalness texture and scalar value to a material.
  1721. * If a texture is provided, it is used as the metalness map. The scalar value is multiplied
  1722. * with the texture if both are set.
  1723. *
  1724. * @param material Pointer to the material to modify.
  1725. * @param texture Optional metalness texture (set to NULL for none).
  1726. * @param value Metalness factor (0.0 = non-metallic, 1.0 = metallic).
  1727. */
  1728. R3DAPI void R3D_SetMaterialMetalness(Material* material, Texture2D* texture, float value);
  1729. /**
  1730. * @brief Sets the emission properties of a material.
  1731. *
  1732. * This function assigns an emission texture, emission color, and intensity to a material.
  1733. * If a texture is provided, it is used as the emission map. The color and intensity control
  1734. * the final emission effect.
  1735. *
  1736. * @param material Pointer to the material to modify.
  1737. * @param texture Optional emission texture (set to NULL for none).
  1738. * @param color Emission color.
  1739. * @param value Emission intensity.
  1740. */
  1741. R3DAPI void R3D_SetMaterialEmission(Material* material, Texture2D* texture, Color color, float value);
  1742. // --------------------------------------------
  1743. // UTILS: Default Texture Retrieval Functions
  1744. // --------------------------------------------
  1745. /**
  1746. * @brief Retrieves a default white texture.
  1747. *
  1748. * This texture is fully white (1,1,1,1), useful for default material properties.
  1749. *
  1750. * @return A white texture.
  1751. */
  1752. R3DAPI Texture2D R3D_GetWhiteTexture(void);
  1753. /**
  1754. * @brief Retrieves a default black texture.
  1755. *
  1756. * This texture is fully black (0,0,0,1), useful for masking or default values.
  1757. *
  1758. * @return A black texture.
  1759. */
  1760. R3DAPI Texture2D R3D_GetBlackTexture(void);
  1761. /**
  1762. * @brief Retrieves a default normal map texture.
  1763. *
  1764. * This texture represents a neutral normal map (0.5, 0.5, 1.0), which applies no normal variation.
  1765. *
  1766. * @return A neutral normal texture.
  1767. */
  1768. R3DAPI Texture2D R3D_GetNormalTexture(void);
  1769. // --------------------------------------------
  1770. // UTILS: Render Texture Retrieval Functions
  1771. // --------------------------------------------
  1772. /**
  1773. * @brief Retrieves the final scene color buffer.
  1774. *
  1775. * This texture stores the final rendered scene as a 24-bit RGB buffer.
  1776. *
  1777. * @return The final color buffer texture.
  1778. */
  1779. R3DAPI Texture2D R3D_GetBufferColor(void);
  1780. /**
  1781. * @brief Retrieves the buffer containing the scene's normal data.
  1782. *
  1783. * This texture stores octahedral-compressed normals using two 16-bit per-channel RG components.
  1784. *
  1785. * @note You can find the decoding functions in the embedded shaders, such as 'screen/lighting.fs.glsl'.
  1786. *
  1787. * @return The normal buffer texture.
  1788. */
  1789. R3DAPI Texture2D R3D_GetBufferNormal(void);
  1790. /**
  1791. * @brief Retrieves the final depth buffer.
  1792. *
  1793. * 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.
  1794. * It is useful for post-processing effects outside of R3D.
  1795. *
  1796. * @note If you modify the texture parameters to sample the stencil instead of the depth,
  1797. * make sure to reset the parameters afterward.
  1798. *
  1799. * @return The final depth buffer texture.
  1800. */
  1801. R3DAPI Texture2D R3D_GetBufferDepth(void);
  1802. // --------------------------------------------
  1803. // UTILS: Camera Matrices Retrieval Functions
  1804. // --------------------------------------------
  1805. /**
  1806. * @brief Retrieves the view matrix.
  1807. *
  1808. * This matrix represents the camera's transformation from world space to view space.
  1809. * It is updated at the last call to 'R3D_Begin'.
  1810. *
  1811. * @return The current view matrix.
  1812. */
  1813. R3DAPI Matrix R3D_GetMatrixView(void);
  1814. /**
  1815. * @brief Retrieves the inverse view matrix.
  1816. *
  1817. * This matrix transforms coordinates from view space back to world space.
  1818. * It is updated at the last call to 'R3D_Begin'.
  1819. *
  1820. * @return The current inverse view matrix.
  1821. */
  1822. R3DAPI Matrix R3D_GetMatrixInvView(void);
  1823. /**
  1824. * @brief Retrieves the projection matrix.
  1825. *
  1826. * This matrix defines the transformation from view space to clip space.
  1827. * It is updated at the last call to 'R3D_Begin'.
  1828. *
  1829. * @return The current projection matrix.
  1830. */
  1831. R3DAPI Matrix R3D_GetMatrixProjection(void);
  1832. /**
  1833. * @brief Retrieves the inverse projection matrix.
  1834. *
  1835. * This matrix transforms coordinates from clip space back to view space.
  1836. * It is updated at the last call to 'R3D_Begin'.
  1837. *
  1838. * @return The current inverse projection matrix.
  1839. */
  1840. R3DAPI Matrix R3D_GetMatrixInvProjection(void);
  1841. // --------------------------------------------
  1842. // UTILS: Debug Buffer Rendering Functions
  1843. // --------------------------------------------
  1844. /**
  1845. * @brief Renders the internal albedo buffer to the screen.
  1846. *
  1847. * This function displays the albedo (diffuse) buffer as a 2D texture.
  1848. * It must be called outside of `R3D_Begin` and `R3D_End`.
  1849. *
  1850. * @param x X position to draw the buffer.
  1851. * @param y Y position to draw the buffer.
  1852. * @param w Width of the drawn buffer.
  1853. * @param h Height of the drawn buffer.
  1854. */
  1855. R3DAPI void R3D_DrawBufferAlbedo(float x, float y, float w, float h);
  1856. /**
  1857. * @brief Renders the internal emission buffer to the screen.
  1858. *
  1859. * Displays the emission buffer, which contains emissive lighting data.
  1860. * Must be called outside of `R3D_Begin` and `R3D_End`.
  1861. *
  1862. * @param x X position to draw the buffer.
  1863. * @param y Y position to draw the buffer.
  1864. * @param w Width of the drawn buffer.
  1865. * @param h Height of the drawn buffer.
  1866. */
  1867. R3DAPI void R3D_DrawBufferEmission(float x, float y, float w, float h);
  1868. /**
  1869. * @brief Renders the internal normal buffer to the screen.
  1870. *
  1871. * Displays the normal buffer, showing world-space normal data as colors.
  1872. * Must be called outside of `R3D_Begin` and `R3D_End`.
  1873. *
  1874. * @param x X position to draw the buffer.
  1875. * @param y Y position to draw the buffer.
  1876. * @param w Width of the drawn buffer.
  1877. * @param h Height of the drawn buffer.
  1878. */
  1879. R3DAPI void R3D_DrawBufferNormal(float x, float y, float w, float h);
  1880. /**
  1881. * @brief Renders the ORM (Occlusion, Roughness, Metalness) buffer to the screen.
  1882. *
  1883. * Displays the ORM buffer, where each channel stores different material properties:
  1884. * - Red: Ambient occlusion
  1885. * - Green: Roughness
  1886. * - Blue: Metalness
  1887. *
  1888. * Must be called outside of `R3D_Begin` and `R3D_End`.
  1889. *
  1890. * @param x X position to draw the buffer.
  1891. * @param y Y position to draw the buffer.
  1892. * @param w Width of the drawn buffer.
  1893. * @param h Height of the drawn buffer.
  1894. */
  1895. R3DAPI void R3D_DrawBufferORM(float x, float y, float w, float h);
  1896. /**
  1897. * @brief Renders the SSAO (Screen Space Ambient Occlusion) buffer to the screen.
  1898. *
  1899. * Displays the SSAO buffer, showing ambient occlusion data in grayscale.
  1900. * Must be called outside of `R3D_Begin` and `R3D_End`.
  1901. *
  1902. * @param x X position to draw the buffer.
  1903. * @param y Y position to draw the buffer.
  1904. * @param w Width of the drawn buffer.
  1905. * @param h Height of the drawn buffer.
  1906. */
  1907. R3DAPI void R3D_DrawBufferSSAO(float x, float y, float w, float h);
  1908. /**
  1909. * @brief Renders the bright colors buffer to the screen.
  1910. *
  1911. * Displays the bright color buffer, which is used for bloom effects.
  1912. * Must be called outside of `R3D_Begin` and `R3D_End`.
  1913. *
  1914. * @param x X position to draw the buffer.
  1915. * @param y Y position to draw the buffer.
  1916. * @param w Width of the drawn buffer.
  1917. * @param h Height of the drawn buffer.
  1918. */
  1919. R3DAPI void R3D_DrawBufferBrightColors(float x, float y, float w, float h);
  1920. /**
  1921. * @brief Renders the bloom buffer to the screen.
  1922. *
  1923. * Displays the bloom effect buffer, showing the extracted bright areas after blur processing.
  1924. * Must be called outside of `R3D_Begin` and `R3D_End`.
  1925. *
  1926. * @param x X position to draw the buffer.
  1927. * @param y Y position to draw the buffer.
  1928. * @param w Width of the drawn buffer.
  1929. * @param h Height of the drawn buffer.
  1930. */
  1931. R3DAPI void R3D_DrawBufferBloom(float x, float y, float w, float h);
  1932. #ifdef __cplusplus
  1933. }
  1934. #endif // __cplusplus
  1935. #endif // R3D_H