r3d_probe.odin 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* r3d_probe.odin -- R3D Probe Module.
  2. *
  3. * Copyright (c) 2025-2026 Le Juez Victor
  4. *
  5. * This software is provided 'as-is', without any express or implied warranty.
  6. * For conditions of distribution and use, see accompanying LICENSE file.
  7. */
  8. package r3d
  9. import rl "vendor:raylib"
  10. when ODIN_OS == .Windows {
  11. foreign import lib {
  12. "windows/libr3d.a",
  13. "system:raylib",
  14. "system:assimp",
  15. }
  16. } else when ODIN_OS == .Linux {
  17. foreign import lib {
  18. "linux/libr3d.a",
  19. "system:raylib",
  20. "system:assimp",
  21. }
  22. } else when ODIN_OS == .Darwin {
  23. foreign import lib {
  24. "darwin/libr3d.a",
  25. "system:raylib",
  26. "system:assimp",
  27. }
  28. }
  29. /**
  30. * @brief Modes for updating probes.
  31. *
  32. * Controls how often probe captures are refreshed.
  33. */
  34. ProbeUpdateMode :: enum u32 {
  35. ONCE = 0, ///< Updated only when its state or content changes
  36. ALWAYS = 1, ///< Updated during every frames
  37. }
  38. /**
  39. * @brief Unique identifier for an R3D probe.
  40. *
  41. * Negative values indicate an invalid probe.
  42. */
  43. Probe :: i32
  44. @(default_calling_convention="c", link_prefix="R3D_")
  45. foreign lib {
  46. /**
  47. * @brief Creates a new probe of the specified type.
  48. *
  49. * The returned probe must be destroyed using ::R3D_DestroyProbe
  50. * when it is no longer needed.
  51. *
  52. * @param flags IBL components that the probe must support.
  53. * @return A valid probe ID, or a negative value on failure.
  54. */
  55. CreateProbe :: proc(flags: ProbeFlags) -> Probe ---
  56. /**
  57. * @brief Destroys a probe and frees its resources.
  58. *
  59. * @param id Probe ID to destroy.
  60. */
  61. DestroyProbe :: proc(id: Probe) ---
  62. /**
  63. * @brief Returns whether a probe exists.
  64. *
  65. * @param id Probe ID.
  66. * @return true if the probe is valid and allocated, otherwise false.
  67. */
  68. IsProbeExist :: proc(id: Probe) -> bool ---
  69. /**
  70. * @brief Returns the probe flags.
  71. *
  72. * @param id Probe ID.
  73. * @return The flags assigned to the probe.
  74. */
  75. GetProbeFlags :: proc(id: Probe) -> ProbeFlags ---
  76. /**
  77. * @brief Returns whether a probe is currently active.
  78. *
  79. * Inactive probes do not contribute to lighting.
  80. *
  81. * @param id Probe ID.
  82. * @return true if active, otherwise false.
  83. */
  84. IsProbeActive :: proc(id: Probe) -> bool ---
  85. /**
  86. * @brief Enables or disables a probe.
  87. *
  88. * @param id Probe ID.
  89. * @param active Set to true to enable the probe.
  90. */
  91. SetProbeActive :: proc(id: Probe, active: bool) ---
  92. /**
  93. * @brief Gets the probe update mode.
  94. *
  95. * - R3D_PROBE_UPDATE_ONCE:
  96. * Captured once, then reused unless its state changes.
  97. *
  98. * - R3D_PROBE_UPDATE_ALWAYS:
  99. * Recaptured every frame.
  100. *
  101. * Use "ONCE" for static scenes, "ALWAYS" for highly dynamic scenes.
  102. */
  103. GetProbeUpdateMode :: proc(id: Probe) -> ProbeUpdateMode ---
  104. /**
  105. * @brief Sets the probe update mode.
  106. *
  107. * Controls when the probe capture is refreshed.
  108. *
  109. * @param id Probe ID.
  110. * @param mode Update mode to apply.
  111. */
  112. SetProbeUpdateMode :: proc(id: Probe, mode: ProbeUpdateMode) ---
  113. /**
  114. * @brief Returns whether the probe is considered indoors.
  115. *
  116. * Indoor probes do not sample skybox or environment maps.
  117. * Instead they rely only on ambient and background colors.
  118. *
  119. * Use this for rooms, caves, tunnels, etc...
  120. * where outside lighting should not bleed inside.
  121. */
  122. GetProbeInterior :: proc(id: Probe) -> bool ---
  123. /**
  124. * @brief Enables or disables indoor mode for the probe.
  125. */
  126. SetProbeInterior :: proc(id: Probe, active: bool) ---
  127. /**
  128. * @brief Returns whether shadows are captured by this probe.
  129. *
  130. * When enabled, shadowing is baked into the captured lighting.
  131. * This improves realism, but increases capture cost.
  132. */
  133. GetProbeShadows :: proc(id: Probe) -> bool ---
  134. /**
  135. * @brief Enables or disables shadow rendering during probe capture.
  136. */
  137. SetProbeShadows :: proc(id: Probe, active: bool) ---
  138. /**
  139. * @brief Gets the world position of the probe.
  140. */
  141. GetProbePosition :: proc(id: Probe) -> rl.Vector3 ---
  142. /**
  143. * @brief Sets the world position of the probe.
  144. */
  145. SetProbePosition :: proc(id: Probe, position: rl.Vector3) ---
  146. /**
  147. * @brief Gets the effective range of the probe.
  148. *
  149. * The range defines the radius (in world units) within which this probe
  150. * contributes to lighting. Objects outside this sphere receive no influence.
  151. */
  152. GetProbeRange :: proc(id: Probe) -> f32 ---
  153. /**
  154. * @brief Sets the effective range of the probe.
  155. *
  156. * @param range Radius in world units. Must be > 0.
  157. */
  158. SetProbeRange :: proc(id: Probe, range: f32) ---
  159. /**
  160. * @brief Gets the falloff factor applied to probe contributions.
  161. *
  162. * Falloff controls how lighting fades as distance increases.
  163. *
  164. * Internally this uses a power curve:
  165. * attenuation = 1.0 - pow(dist / probe.range, probe.falloff)
  166. *
  167. * Effects:
  168. * - falloff = 1 -> linear fade
  169. * - falloff > 1 -> light stays strong near the probe, drops faster at the edge
  170. * - falloff < 1 -> softer fade across the whole range
  171. */
  172. GetProbeFalloff :: proc(id: Probe) -> f32 ---
  173. /**
  174. * @brief Sets the falloff factor used for distance attenuation.
  175. *
  176. * Larger values make the probe feel more localized.
  177. */
  178. SetProbeFalloff :: proc(id: Probe, falloff: f32) ---
  179. }
  180. /**
  181. * @brief Bit-flags controlling what components are generated.
  182. *
  183. * - R3D_PROBE_ILLUMINATION -> generate diffuse irradiance
  184. * - R3D_PROBE_REFLECTION -> generate specular prefiltered map
  185. */
  186. ProbeFlag :: enum u32 {
  187. ILLUMINATION = 0,
  188. REFLECTION = 1,
  189. }
  190. ProbeFlags :: bit_set[ProbeFlag; u32]