r3d_cubemap.odin 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* r3d_cubemap.odin -- R3D Cubemap 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 Supported cubemap source layouts.
  31. *
  32. * Used when converting an image into a cubemap. AUTO_DETECT tries to guess
  33. * the layout based on image dimensions.
  34. */
  35. CubemapLayout :: enum u32 {
  36. AUTO_DETECT = 0, ///< Automatically detect layout type
  37. LINE_VERTICAL = 1, ///< Layout is defined by a vertical line with faces
  38. LINE_HORIZONTAL = 2, ///< Layout is defined by a horizontal line with faces
  39. CROSS_THREE_BY_FOUR = 3, ///< Layout is defined by a 3x4 cross with cubemap faces
  40. CROSS_FOUR_BY_THREE = 4, ///< Layout is defined by a 4x3 cross with cubemap faces
  41. PANORAMA = 5, ///< Layout is defined by an equirectangular panorama
  42. }
  43. /**
  44. * @brief GPU cubemap texture.
  45. *
  46. * Holds the OpenGL texture handle and its base resolution (per face).
  47. */
  48. Cubemap :: struct {
  49. texture: u32,
  50. fbo: u32,
  51. size: i32,
  52. }
  53. /**
  54. * @brief Parameters for procedural sky generation.
  55. *
  56. * Curves control gradient falloff (lower = sharper transition at horizon).
  57. */
  58. CubemapSky :: struct {
  59. skyTopColor: rl.Color, // Sky color at zenith
  60. skyHorizonColor: rl.Color, // Sky color at horizon
  61. skyHorizonCurve: f32, // Gradient curve exponent (0.01 - 1.0, typical: 0.15)
  62. skyEnergy: f32, // Sky brightness multiplier
  63. groundBottomColor: rl.Color, // Ground color at nadir
  64. groundHorizonColor: rl.Color, // Ground color at horizon
  65. groundHorizonCurve: f32, // Gradient curve exponent (typical: 0.02)
  66. groundEnergy: f32, // Ground brightness multiplier
  67. sunDirection: rl.Vector3, // Direction from which light comes (can take not normalized)
  68. sunColor: rl.Color, // Sun disk color
  69. sunSize: f32, // Sun angular size in radians (real sun: ~0.0087 rad = 0.5°)
  70. sunCurve: f32, // Sun edge softness exponent (typical: 0.15)
  71. sunEnergy: f32, // Sun brightness multiplier
  72. }
  73. @(default_calling_convention="c", link_prefix="R3D_")
  74. foreign lib {
  75. /**
  76. * @brief Loads a cubemap from an image file.
  77. *
  78. * The layout parameter tells how faces are arranged inside the source image.
  79. */
  80. LoadCubemap :: proc(fileName: cstring, layout: CubemapLayout) -> Cubemap ---
  81. /**
  82. * @brief Builds a cubemap from an existing rl.Image.
  83. *
  84. * Same behavior as R3D_LoadCubemap(), but without loading from disk.
  85. */
  86. LoadCubemapFromImage :: proc(image: rl.Image, layout: CubemapLayout) -> Cubemap ---
  87. /**
  88. * @brief Generates a procedural sky cubemap.
  89. *
  90. * Creates a GPU cubemap with procedural gradient sky and sun rendering.
  91. * The cubemap is ready for use as environment map or IBL source.
  92. */
  93. GenCubemapSky :: proc(size: i32, params: CubemapSky) -> Cubemap ---
  94. /**
  95. * @brief Releases GPU resources associated with a cubemap.
  96. */
  97. UnloadCubemap :: proc(cubemap: Cubemap) ---
  98. /**
  99. * @brief Updates an existing procedural sky cubemap.
  100. *
  101. * Re-renders the cubemap with new parameters. Faster than unload + generate
  102. * when animating sky conditions (time of day, weather, etc.).
  103. */
  104. UpdateCubemapSky :: proc(cubemap: ^Cubemap, params: CubemapSky) ---
  105. }
  106. CUBEMAP_SKY_BASE :: CubemapSky {
  107. skyTopColor = {98, 116, 140, 255},
  108. skyHorizonColor = {165, 167, 171, 255},
  109. skyHorizonCurve = 0.15,
  110. skyEnergy = 1.0,
  111. groundBottomColor = {51, 43, 34, 255},
  112. groundHorizonColor = {165, 167, 171, 255},
  113. groundHorizonCurve = 0.02,
  114. groundEnergy = 1.0,
  115. sunDirection = {-1.0, -1.0, -1.0},
  116. sunColor = {255, 255, 255, 255},
  117. sunSize = 1.5 * rl.DEG2RAD,
  118. sunCurve = 0.15,
  119. sunEnergy = 1.0,
  120. }