lightInfo.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _LIGHTINFO_H_
  23. #define _LIGHTINFO_H_
  24. #ifndef _GFXSTRUCTS_H_
  25. #include "gfx/gfxStructs.h"
  26. #endif
  27. #ifndef _TVECTOR_H_
  28. #include "core/util/tVector.h"
  29. #endif
  30. #ifndef _TDICTIONARY_H_
  31. #include "core/util/tDictionary.h"
  32. #endif
  33. struct SceneData;
  34. class LightManager;
  35. class SimObject;
  36. class BitStream;
  37. /// The extended light info type wrapper object.
  38. class LightInfoExType
  39. {
  40. protected:
  41. typedef HashTable<String,U32> TypeMap;
  42. /// Returns the map of all the info types. We create
  43. /// it as a method static so that its available to other
  44. /// statics regardless of initialization order.
  45. static inline TypeMap& getTypeMap()
  46. {
  47. static TypeMap smTypeMap;
  48. return smTypeMap;
  49. }
  50. /// The info type index for this type.
  51. U32 mTypeIndex;
  52. public:
  53. LightInfoExType( const char *type );
  54. inline LightInfoExType( const LightInfoExType &type )
  55. : mTypeIndex( type.mTypeIndex )
  56. {
  57. }
  58. inline operator U32 () const { return mTypeIndex; }
  59. };
  60. /// This is the base class for extended lighting info
  61. /// that lies outside of the normal info stored in LightInfo.
  62. class LightInfoEx
  63. {
  64. public:
  65. /// Basic destructor so we can delete the extended info
  66. /// without knowing the concrete type.
  67. virtual ~LightInfoEx() { }
  68. ///
  69. virtual const LightInfoExType& getType() const = 0;
  70. /// Copy the values from the other LightInfoEx.
  71. virtual void set( const LightInfoEx *ex ) {}
  72. ///
  73. virtual void packUpdate( BitStream *stream ) const {}
  74. ///
  75. virtual void unpackUpdate( BitStream *stream ) {}
  76. };
  77. /// This is the base light information class that will be tracked by the
  78. /// engine. Should basically contain a bounding volume and methods to interact
  79. /// with the rest of the system (for example, setting GFX fixed function lights).
  80. class LightInfo
  81. {
  82. public:
  83. enum Type
  84. {
  85. Point = 0,
  86. Spot = 1,
  87. Vector = 2,
  88. Ambient = 3,
  89. Count = 4,
  90. };
  91. protected:
  92. Type mType;
  93. /// The primary light color.
  94. ColorF mColor;
  95. F32 mBrightness;
  96. ColorF mAmbient;
  97. MatrixF mTransform;
  98. Point3F mRange;
  99. F32 mInnerConeAngle;
  100. F32 mOuterConeAngle;
  101. bool mCastShadows;
  102. S32 mStaticRefreshFreq;
  103. S32 mDynamicRefreshFreq;
  104. ::Vector<LightInfoEx*> mExtended;
  105. /// The priority of this light used for
  106. /// light and shadow scoring.
  107. F32 mPriority;
  108. /// A temporary which holds the score used
  109. /// when prioritizing lights for rendering.
  110. F32 mScore;
  111. /// Whether to render debugging visualizations
  112. /// for this light.
  113. bool mDebugRender;
  114. public:
  115. LightInfo();
  116. ~LightInfo();
  117. // Copies data passed in from light
  118. void set( const LightInfo *light );
  119. // Sets a fixed function GFXLight with our properties
  120. void setGFXLight( GFXLightInfo *light );
  121. // Accessors
  122. Type getType() const { return mType; }
  123. void setType( Type val ) { mType = val; }
  124. const MatrixF& getTransform() const { return mTransform; }
  125. void setTransform( const MatrixF &xfm ) { mTransform = xfm; }
  126. Point3F getPosition() const { return mTransform.getPosition(); }
  127. void setPosition( const Point3F &pos ) { mTransform.setPosition( pos ); }
  128. VectorF getDirection() const { return mTransform.getForwardVector(); }
  129. void setDirection( const VectorF &val );
  130. const ColorF& getColor() const { return mColor; }
  131. void setColor( const ColorF &val ) { mColor = val; }
  132. F32 getBrightness() const { return mBrightness; }
  133. void setBrightness( F32 val ) { mBrightness = val; }
  134. const ColorF& getAmbient() const { return mAmbient; }
  135. void setAmbient( const ColorF &val ) { mAmbient = val; }
  136. const Point3F& getRange() const { return mRange; }
  137. void setRange( const Point3F &range ) { mRange = range; }
  138. void setRange( F32 range ) { mRange.set( range, range, range ); }
  139. F32 getInnerConeAngle() const { return mInnerConeAngle; }
  140. void setInnerConeAngle( F32 val ) { mInnerConeAngle = val; }
  141. F32 getOuterConeAngle() const { return mOuterConeAngle; }
  142. void setOuterConeAngle( F32 val ) { mOuterConeAngle = val; }
  143. bool getCastShadows() const { return mCastShadows; }
  144. void setCastShadows( bool castShadows ) { mCastShadows = castShadows; }
  145. S32 getStaticRefreshFreq() const { return mStaticRefreshFreq; }
  146. void setStaticRefreshFreq(S32 _staticRefreshFreq) { mStaticRefreshFreq = _staticRefreshFreq; }
  147. S32 getDynamicRefreshFreq() const { return mDynamicRefreshFreq; }
  148. void setDynamicRefreshFreq(S32 _dynamicRefreshFreq) { mDynamicRefreshFreq = _dynamicRefreshFreq; }
  149. void setPriority( F32 priority ) { mPriority = priority; }
  150. F32 getPriority() const { return mPriority; }
  151. void setScore( F32 score ) { mScore = score; }
  152. F32 getScore() const { return mScore; }
  153. bool isDebugRenderingEnabled() const { return mDebugRender; }
  154. void enableDebugRendering( bool value ) { mDebugRender = value; }
  155. /// Helper function for getting the extended light info.
  156. /// @see getExtended
  157. template <class ExClass>
  158. inline ExClass* getExtended() const { return (ExClass*)getExtended( ExClass::Type ); }
  159. /// Returns the extended light info for the selected type.
  160. LightInfoEx* getExtended( const LightInfoExType &type ) const;
  161. /// Adds the extended info to the light deleting the
  162. /// existing extended info if it has one.
  163. void addExtended( LightInfoEx *lightInfoEx );
  164. /// Delete all registered LightInfoEx instances of the given
  165. /// type.
  166. void deleteExtended( const LightInfoExType& type );
  167. ///
  168. void deleteAllLightInfoEx();
  169. // Builds the world to light view projection used for
  170. // shadow texture and cookie lookups.
  171. void getWorldToLightProj( MatrixF *outMatrix ) const;
  172. ///
  173. void packExtended( BitStream *stream ) const;
  174. ///
  175. void unpackExtended( BitStream *stream );
  176. };
  177. ///
  178. class LightInfoList : public Vector<LightInfo*>
  179. {
  180. public:
  181. void registerLight( LightInfo *light );
  182. void unregisterLight( LightInfo *light );
  183. };
  184. /// When the scene is queried for lights, the light manager will get
  185. /// this interface to trigger a register light call.
  186. class ISceneLight
  187. {
  188. public:
  189. virtual ~ISceneLight() {}
  190. /// Submit lights to the light manager passed in.
  191. virtual void submitLights( LightManager *lm, bool staticLighting ) = 0;
  192. ///
  193. virtual LightInfo* getLight() = 0;
  194. };
  195. #endif // _LIGHTINFO_H_