lightInfo.h

Engine/source/lighting/lightInfo.h

More...

Classes:

class

When the scene is queried for lights, the light manager will get this interface to trigger a register light call.

class

This is the base light information class that will be tracked by the engine.

class

This is the base class for extended lighting info that lies outside of the normal info stored in LightInfo.

class

The extended light info type wrapper object.

Detailed Description

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