light.h 8.8 KB

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