light.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2021, 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. {
  52. aiLightSource_UNDEFINED = 0x0,
  53. //! A directional light source has a well-defined direction
  54. //! but is infinitely far away. That's quite a good
  55. //! approximation for sun light.
  56. aiLightSource_DIRECTIONAL = 0x1,
  57. //! A point light source has a well-defined position
  58. //! in space but no direction - it emits light in all
  59. //! directions. A normal bulb is a point light.
  60. aiLightSource_POINT = 0x2,
  61. //! A spot light source emits light in a specific
  62. //! angle. It has a position and a direction it is pointing to.
  63. //! A good example for a spot light is a light spot in
  64. //! sport arenas.
  65. aiLightSource_SPOT = 0x3,
  66. //! The generic light level of the world, including the bounces
  67. //! of all other light sources.
  68. //! Typically, there's at most one ambient light in a scene.
  69. //! This light type doesn't have a valid position, direction, or
  70. //! other properties, just a color.
  71. aiLightSource_AMBIENT = 0x4,
  72. //! An area light is a rectangle with predefined size that uniformly
  73. //! emits light from one of its sides. The position is center of the
  74. //! rectangle and direction is its normal vector.
  75. aiLightSource_AREA = 0x5,
  76. /** This value is not used. It is just there to force the
  77. * compiler to map this enum to a 32 Bit integer.
  78. */
  79. #ifndef SWIG
  80. _aiLightSource_Force32Bit = INT_MAX
  81. #endif
  82. };
  83. // ---------------------------------------------------------------------------
  84. /** Helper structure to describe a light source.
  85. *
  86. * Assimp supports multiple sorts of light sources, including
  87. * directional, point and spot lights. All of them are defined with just
  88. * a single structure and distinguished by their parameters.
  89. * Note - some file formats (such as 3DS, ASE) export a "target point" -
  90. * the point a spot light is looking at (it can even be animated). Assimp
  91. * writes the target point as a subnode of a spotlights's main node,
  92. * called "<spotName>.Target". However, this is just additional information
  93. * then, the transformation tracks of the main node make the
  94. * spot light already point in the right direction.
  95. */
  96. struct aiLight
  97. {
  98. /** The name of the light source.
  99. *
  100. * There must be a node in the scenegraph with the same name.
  101. * This node specifies the position of the light in the scene
  102. * hierarchy and can be animated.
  103. */
  104. C_STRUCT aiString mName;
  105. /** The type of the light source.
  106. *
  107. * aiLightSource_UNDEFINED is not a valid value for this member.
  108. */
  109. C_ENUM aiLightSourceType mType;
  110. /** Position of the light source in space. Relative to the
  111. * transformation of the node corresponding to the light.
  112. *
  113. * The position is undefined for directional lights.
  114. */
  115. C_STRUCT aiVector3D mPosition;
  116. /** Direction of the light source in space. Relative to the
  117. * transformation of the node corresponding to the light.
  118. *
  119. * The direction is undefined for point lights. The vector
  120. * may be normalized, but it needn't.
  121. */
  122. C_STRUCT aiVector3D mDirection;
  123. /** Up direction of the light source in space. Relative to the
  124. * transformation of the node corresponding to the light.
  125. *
  126. * The direction is undefined for point lights. The vector
  127. * may be normalized, but it needn't.
  128. */
  129. C_STRUCT aiVector3D mUp;
  130. /** Constant light attenuation factor.
  131. *
  132. * The intensity of the light source at a given distance 'd' from
  133. * the light's position is
  134. * @code
  135. * Atten = 1/( att0 + att1 * d + att2 * d*d)
  136. * @endcode
  137. * This member corresponds to the att0 variable in the equation.
  138. * Naturally undefined for directional lights.
  139. */
  140. float mAttenuationConstant;
  141. /** Linear light attenuation factor.
  142. *
  143. * The intensity of the light source at a given distance 'd' from
  144. * the light's position is
  145. * @code
  146. * Atten = 1/( att0 + att1 * d + att2 * d*d)
  147. * @endcode
  148. * This member corresponds to the att1 variable in the equation.
  149. * Naturally undefined for directional lights.
  150. */
  151. float mAttenuationLinear;
  152. /** Quadratic light attenuation factor.
  153. *
  154. * The intensity of the light source at a given distance 'd' from
  155. * the light's position is
  156. * @code
  157. * Atten = 1/( att0 + att1 * d + att2 * d*d)
  158. * @endcode
  159. * This member corresponds to the att2 variable in the equation.
  160. * Naturally undefined for directional lights.
  161. */
  162. float mAttenuationQuadratic;
  163. /** Diffuse color of the light source
  164. *
  165. * The diffuse light color is multiplied with the diffuse
  166. * material color to obtain the final color that contributes
  167. * to the diffuse shading term.
  168. */
  169. C_STRUCT aiColor3D mColorDiffuse;
  170. /** Specular color of the light source
  171. *
  172. * The specular light color is multiplied with the specular
  173. * material color to obtain the final color that contributes
  174. * to the specular shading term.
  175. */
  176. C_STRUCT aiColor3D mColorSpecular;
  177. /** Ambient color of the light source
  178. *
  179. * The ambient light color is multiplied with the ambient
  180. * material color to obtain the final color that contributes
  181. * to the ambient shading term. Most renderers will ignore
  182. * this value it, is just a remaining of the fixed-function pipeline
  183. * that is still supported by quite many file formats.
  184. */
  185. C_STRUCT aiColor3D mColorAmbient;
  186. /** Inner angle of a spot light's light cone.
  187. *
  188. * The spot light has maximum influence on objects inside this
  189. * angle. The angle is given in radians. It is 2PI for point
  190. * lights and undefined for directional lights.
  191. */
  192. float mAngleInnerCone;
  193. /** Outer angle of a spot light's light cone.
  194. *
  195. * The spot light does not affect objects outside this angle.
  196. * The angle is given in radians. It is 2PI for point lights and
  197. * undefined for directional lights. The outer angle must be
  198. * greater than or equal to the inner angle.
  199. * It is assumed that the application uses a smooth
  200. * interpolation between the inner and the outer cone of the
  201. * spot light.
  202. */
  203. float mAngleOuterCone;
  204. /** Size of area light source. */
  205. C_STRUCT aiVector2D mSize;
  206. #ifdef __cplusplus
  207. aiLight() AI_NO_EXCEPT
  208. : mType (aiLightSource_UNDEFINED)
  209. , mAttenuationConstant (0.f)
  210. , mAttenuationLinear (1.f)
  211. , mAttenuationQuadratic (0.f)
  212. , mAngleInnerCone ((float)AI_MATH_TWO_PI)
  213. , mAngleOuterCone ((float)AI_MATH_TWO_PI)
  214. , mSize (0.f, 0.f)
  215. {
  216. }
  217. #endif
  218. };
  219. #ifdef __cplusplus
  220. }
  221. #endif
  222. #endif // !! AI_LIGHT_H_INC