light.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2025, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file light.h
  35. * @brief Defines the aiLight data structure
  36. */
  37. #pragma once
  38. #ifndef AI_LIGHT_H_INC
  39. #define AI_LIGHT_H_INC
  40. #ifdef __GNUC__
  41. # pragma GCC system_header
  42. #endif
  43. #include <assimp/types.h>
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. // ---------------------------------------------------------------------------
  48. /** Enumerates all supported types of light sources.
  49. */
  50. enum aiLightSourceType {
  51. aiLightSource_UNDEFINED = 0x0,
  52. //! A directional light source has a well-defined direction
  53. //! but is infinitely far away. That's quite a good
  54. //! approximation for sun light.
  55. aiLightSource_DIRECTIONAL = 0x1,
  56. //! A point light source has a well-defined position
  57. //! in space but no direction - it emits light in all
  58. //! directions. A normal bulb is a point light.
  59. aiLightSource_POINT = 0x2,
  60. //! A spot light source emits light in a specific
  61. //! angle. It has a position and a direction it is pointing to.
  62. //! A good example for a spot light is a light spot in
  63. //! sport arenas.
  64. aiLightSource_SPOT = 0x3,
  65. //! The generic light level of the world, including the bounces
  66. //! of all other light sources.
  67. //! Typically, there's at most one ambient light in a scene.
  68. //! This light type doesn't have a valid position, direction, or
  69. //! other properties, just a color.
  70. aiLightSource_AMBIENT = 0x4,
  71. //! An area light is a rectangle with predefined size that uniformly
  72. //! emits light from one of its sides. The position is center of the
  73. //! rectangle and direction is its normal vector.
  74. aiLightSource_AREA = 0x5,
  75. /** This value is not used. It is just there to force the
  76. * compiler to map this enum to a 32 Bit integer.
  77. */
  78. #ifndef SWIG
  79. _aiLightSource_Force32Bit = INT_MAX
  80. #endif
  81. };
  82. // ---------------------------------------------------------------------------
  83. /** Helper structure to describe a light source.
  84. *
  85. * Assimp supports multiple sorts of light sources, including
  86. * directional, point and spot lights. All of them are defined with just
  87. * a single structure and distinguished by their parameters.
  88. * Note - some file formats (such as 3DS, ASE) export a "target point" -
  89. * the point a spot light is looking at (it can even be animated). Assimp
  90. * writes the target point as a sub-node of a spot-lights's main node,
  91. * called "<spotName>.Target". However, this is just additional information
  92. * then, the transformation tracks of the main node make the
  93. * spot light already point in the right direction.
  94. */
  95. struct aiLight {
  96. /** The name of the light source.
  97. *
  98. * There must be a node in the scene-graph with the same name.
  99. * This node specifies the position of the light in the scene
  100. * hierarchy and can be animated.
  101. */
  102. C_STRUCT aiString mName;
  103. /** The type of the light source.
  104. *
  105. * aiLightSource_UNDEFINED is not a valid value for this member.
  106. */
  107. C_ENUM aiLightSourceType mType;
  108. /** Position of the light source in space. Relative to the
  109. * transformation of the node corresponding to the light.
  110. *
  111. * The position is undefined for directional lights.
  112. */
  113. C_STRUCT aiVector3D mPosition;
  114. /** Direction of the light source in space. Relative to the
  115. * transformation of the node corresponding to the light.
  116. *
  117. * The direction is undefined for point lights. The vector
  118. * may be normalized, but it needn't.
  119. */
  120. C_STRUCT aiVector3D mDirection;
  121. /** Up direction of the light source in space. Relative to the
  122. * transformation of the node corresponding to the light.
  123. *
  124. * The direction is undefined for point lights. The vector
  125. * may be normalized, but it needn't.
  126. */
  127. C_STRUCT aiVector3D mUp;
  128. /** Constant light attenuation factor.
  129. *
  130. * The intensity of the light source at a given distance 'd' from
  131. * the light's position is
  132. * @code
  133. * Atten = 1/( att0 + att1 * d + att2 * d*d)
  134. * @endcode
  135. * This member corresponds to the att0 variable in the equation.
  136. * Naturally undefined for directional lights.
  137. */
  138. float mAttenuationConstant;
  139. /** Linear light attenuation factor.
  140. *
  141. * The intensity of the light source at a given distance 'd' from
  142. * the light's position is
  143. * @code
  144. * Atten = 1/( att0 + att1 * d + att2 * d*d)
  145. * @endcode
  146. * This member corresponds to the att1 variable in the equation.
  147. * Naturally undefined for directional lights.
  148. */
  149. float mAttenuationLinear;
  150. /** Quadratic light attenuation factor.
  151. *
  152. * The intensity of the light source at a given distance 'd' from
  153. * the light's position is
  154. * @code
  155. * Atten = 1/( att0 + att1 * d + att2 * d*d)
  156. * @endcode
  157. * This member corresponds to the att2 variable in the equation.
  158. * Naturally undefined for directional lights.
  159. */
  160. float mAttenuationQuadratic;
  161. /** Diffuse color of the light source
  162. *
  163. * The diffuse light color is multiplied with the diffuse
  164. * material color to obtain the final color that contributes
  165. * to the diffuse shading term.
  166. */
  167. C_STRUCT aiColor3D mColorDiffuse;
  168. /** Specular color of the light source
  169. *
  170. * The specular light color is multiplied with the specular
  171. * material color to obtain the final color that contributes
  172. * to the specular shading term.
  173. */
  174. C_STRUCT aiColor3D mColorSpecular;
  175. /** Ambient color of the light source
  176. *
  177. * The ambient light color is multiplied with the ambient
  178. * material color to obtain the final color that contributes
  179. * to the ambient shading term. Most renderers will ignore
  180. * this value it, is just a remaining of the fixed-function pipeline
  181. * that is still supported by quite many file formats.
  182. */
  183. C_STRUCT aiColor3D mColorAmbient;
  184. /** Inner angle of a spot light's light cone.
  185. *
  186. * The spot light has maximum influence on objects inside this
  187. * angle. The angle is given in radians. It is 2PI for point
  188. * lights and undefined for directional lights.
  189. */
  190. float mAngleInnerCone;
  191. /** Outer angle of a spot light's light cone.
  192. *
  193. * The spot light does not affect objects outside this angle.
  194. * The angle is given in radians. It is 2PI for point lights and
  195. * undefined for directional lights. The outer angle must be
  196. * greater than or equal to the inner angle.
  197. * It is assumed that the application uses a smooth
  198. * interpolation between the inner and the outer cone of the
  199. * spot light.
  200. */
  201. float mAngleOuterCone;
  202. /** Size of area light source. */
  203. C_STRUCT aiVector2D mSize;
  204. #ifdef __cplusplus
  205. aiLight() AI_NO_EXCEPT
  206. : mType (aiLightSource_UNDEFINED)
  207. , mAttenuationConstant (0.f)
  208. , mAttenuationLinear (1.f)
  209. , mAttenuationQuadratic (0.f)
  210. , mAngleInnerCone ((float)AI_MATH_TWO_PI)
  211. , mAngleOuterCone ((float)AI_MATH_TWO_PI)
  212. , mSize (0.f, 0.f)
  213. {
  214. }
  215. #endif
  216. };
  217. #ifdef __cplusplus
  218. }
  219. #endif
  220. #endif // !! AI_LIGHT_H_INC