r3d_decal.odin 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* r3d_decal.odin -- R3D Decal 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 Represents a decal and its properties.
  31. *
  32. * This structure defines a decal that can be projected onto geometry that has already been rendered.
  33. *
  34. * @note Decals are drawn using deferred screen space rendering and do not interact with any
  35. * forward rendered or non-opaque objects.
  36. */
  37. Decal :: struct {
  38. albedo: AlbedoMap, ///< Albedo map (if the texture is undefined, implicitly treat `applyColor` as false, with alpha = 1.0)
  39. emission: EmissionMap, ///< Emission map
  40. normal: NormalMap, ///< Normal map
  41. orm: OrmMap, ///< Occlusion-Roughness-Metalness map
  42. uvOffset: rl.Vector2, ///< UV offset (default: {0.0f, 0.0f})
  43. uvScale: rl.Vector2, ///< UV scale (default: {1.0f, 1.0f})
  44. alphaCutoff: f32, ///< Alpha cutoff threshold (default: 0.01f)
  45. normalThreshold: f32, ///< Maximum angle against the surface normal to draw decal. 0.0f disables threshold. (default: 0.0f)
  46. fadeWidth: f32, ///< The width of fading along the normal threshold (default: 0.0f)
  47. applyColor: bool, ///< Indicates that the albedo color will not be rendered, only the alpha component of the albedo will be used as a mask. (default: true)
  48. shader: ^SurfaceShader, ///< Custom shader applied to the decal (default: NULL)
  49. }
  50. @(default_calling_convention="c", link_prefix="R3D_")
  51. foreign lib {
  52. /**
  53. * @brief Unload all map textures assigned to a R3D_Decal.
  54. *
  55. * Frees all underlying textures in a R3D_Decal that are not a default texture.
  56. *
  57. * @param decal to unload maps from.
  58. */
  59. UnloadDecalMaps :: proc(decal: Decal) ---
  60. }
  61. /**
  62. * @brief Default decal configuration.
  63. *
  64. * Contains a R3D_Decal structure with sensible default values for all rendering parameters.
  65. */
  66. DECAL_BASE :: Decal {
  67. albedo = {
  68. texture = {},
  69. color = {255, 255, 255, 255},
  70. },
  71. emission = {
  72. texture = {},
  73. color = {255, 255, 255, 255},
  74. energy = 0.0,
  75. },
  76. normal = {
  77. texture = {},
  78. scale = 1.0,
  79. },
  80. orm = {
  81. texture = {},
  82. occlusion = 1.0,
  83. roughness = 1.0,
  84. metalness = 0.0,
  85. },
  86. uvOffset = {0.0, 0.0},
  87. uvScale = {1.0, 1.0},
  88. alphaCutoff = 0.01,
  89. normalThreshold = 0,
  90. fadeWidth = 0,
  91. applyColor = true,
  92. shader = nil,
  93. }