light.h 8.2 KB

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