[657] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://www.ogre3d.org/
|
---|
| 6 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 | #ifndef _LIGHT_H__
|
---|
| 26 | #define _LIGHT_H__
|
---|
| 27 |
|
---|
| 28 | #include "OgrePrerequisites.h"
|
---|
| 29 |
|
---|
| 30 | #include "OgreColourValue.h"
|
---|
| 31 | #include "OgreVector3.h"
|
---|
| 32 | #include "OgreVector4.h"
|
---|
| 33 | #include "OgreString.h"
|
---|
| 34 | #include "OgreMovableObject.h"
|
---|
| 35 | #include "OgrePlaneBoundedVolume.h"
|
---|
| 36 |
|
---|
| 37 | namespace Ogre {
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | /** Representation of a dynamic light source in the scene.
|
---|
| 41 | @remarks
|
---|
| 42 | Lights are added to the scene like any other object. They contain various
|
---|
| 43 | parameters like type, position, attenuation (how light intensity fades with
|
---|
| 44 | distance), colour etc.
|
---|
| 45 | @par
|
---|
| 46 | The defaults when a light is created is pure white diffues light, with no
|
---|
| 47 | attenuation (does not decrease with distance) and a range of 1000 world units.
|
---|
| 48 | @par
|
---|
| 49 | Lights are created by using the SceneManager::createLight method. They can subsequently be
|
---|
| 50 | added to a SceneNode if required to allow them to move relative to a node in the scene. A light attached
|
---|
| 51 | to a SceneNode is assumed to havea base position of (0,0,0) and a direction of (0,0,1) before modification
|
---|
| 52 | by the SceneNode's own orientation. If not attached to a SceneNode,
|
---|
| 53 | the light's position and direction is as set using setPosition and setDirection.
|
---|
| 54 | @par
|
---|
| 55 | Remember also that dynamic lights rely on modifying the colour of vertices based on the position of
|
---|
| 56 | the light compared to an object's vertex normals. Dynamic lighting will only look good if the
|
---|
| 57 | object being lit has a fair level of tesselation and the normals are properly set. This is particularly
|
---|
| 58 | true for the spotlight which will only look right on highly tesselated models. In the future OGRE may be
|
---|
| 59 | extended for certain scene types so an alternative to the standard dynamic lighting may be used, such
|
---|
| 60 | as dynamic lightmaps.
|
---|
| 61 | */
|
---|
| 62 | class _OgreExport Light : public MovableObject
|
---|
| 63 | {
|
---|
| 64 | public:
|
---|
| 65 | /// Temp tag used for sorting
|
---|
| 66 | Real tempSquareDist;
|
---|
| 67 |
|
---|
| 68 | /// Defines the type of light
|
---|
| 69 | enum LightTypes
|
---|
| 70 | {
|
---|
| 71 | /// Point light sources give off light equally in all directions, so require only position not direction
|
---|
| 72 | LT_POINT,
|
---|
| 73 | /// Directional lights simulate parallel light beams from a distant source, hence have direction but no position
|
---|
| 74 | LT_DIRECTIONAL,
|
---|
| 75 | /// Spotlights simulate a cone of light from a source so require position and direction, plus extra values for falloff
|
---|
| 76 | LT_SPOTLIGHT
|
---|
| 77 | };
|
---|
| 78 |
|
---|
| 79 | /** Default constructor (for Python mainly).
|
---|
| 80 | */
|
---|
| 81 | Light();
|
---|
| 82 |
|
---|
| 83 | /** Normal constructor. Should not be called directly, but rather the SceneManager::createLight method should be used.
|
---|
| 84 | */
|
---|
| 85 | Light(const String& name);
|
---|
| 86 |
|
---|
| 87 | /** Standard destructor.
|
---|
| 88 | */
|
---|
| 89 | ~Light();
|
---|
| 90 |
|
---|
| 91 | /** Returns the name of this light (cannot be modified).
|
---|
| 92 | */
|
---|
| 93 | const String& getName(void) const;
|
---|
| 94 |
|
---|
| 95 | /** Sets the type of light - see LightTypes for more info.
|
---|
| 96 | */
|
---|
| 97 | void setType(LightTypes type);
|
---|
| 98 |
|
---|
| 99 | /** Returns the light type.
|
---|
| 100 | */
|
---|
| 101 | LightTypes getType(void) const;
|
---|
| 102 |
|
---|
| 103 | /** Sets the colour of the diffuse light given off by this source.
|
---|
| 104 | @remarks
|
---|
| 105 | Material objects have ambient, diffuse and specular values which indicate how much of each type of
|
---|
| 106 | light an object reflects. This value denotes the amount and colour of this type of light the light
|
---|
| 107 | exudes into the scene. The actual appearance of objects is a combination of the two.
|
---|
| 108 | @par
|
---|
| 109 | Diffuse light simulates the typical light emenating from light sources and affects the base colour
|
---|
| 110 | of objects together with ambient light.
|
---|
| 111 | */
|
---|
| 112 | void setDiffuseColour(Real red, Real green, Real blue);
|
---|
| 113 |
|
---|
| 114 | /** Sets the colour of the diffuse light given off by this source.
|
---|
| 115 | @remarks
|
---|
| 116 | Material objects have ambient, diffuse and specular values which indicate how much of each type of
|
---|
| 117 | light an object reflects. This value denotes the amount and colour of this type of light the light
|
---|
| 118 | exudes into the scene. The actual appearance of objects is a combination of the two.
|
---|
| 119 | @par
|
---|
| 120 | Diffuse light simulates the typical light emenating from light sources and affects the base colour
|
---|
| 121 | of objects together with ambient light.
|
---|
| 122 | */
|
---|
| 123 | void setDiffuseColour(const ColourValue& colour);
|
---|
| 124 |
|
---|
| 125 | /** Returns the colour of the diffuse light given off by this light source (see setDiffuseColour for more info).
|
---|
| 126 | */
|
---|
| 127 | const ColourValue& getDiffuseColour(void) const;
|
---|
| 128 |
|
---|
| 129 | /** Sets the colour of the specular light given off by this source.
|
---|
| 130 | @remarks
|
---|
| 131 | Material objects have ambient, diffuse and specular values which indicate how much of each type of
|
---|
| 132 | light an object reflects. This value denotes the amount and colour of this type of light the light
|
---|
| 133 | exudes into the scene. The actual appearance of objects is a combination of the two.
|
---|
| 134 | @par
|
---|
| 135 | Specular light affects the appearance of shiny highlights on objects, and is also dependent on the
|
---|
| 136 | 'shininess' Material value.
|
---|
| 137 | */
|
---|
| 138 | void setSpecularColour(Real red, Real green, Real blue);
|
---|
| 139 |
|
---|
| 140 | /** Sets the colour of the specular light given off by this source.
|
---|
| 141 | @remarks
|
---|
| 142 | Material objects have ambient, diffuse and specular values which indicate how much of each type of
|
---|
| 143 | light an object reflects. This value denotes the amount and colour of this type of light the light
|
---|
| 144 | exudes into the scene. The actual appearance of objects is a combination of the two.
|
---|
| 145 | @par
|
---|
| 146 | Specular light affects the appearance of shiny highlights on objects, and is also dependent on the
|
---|
| 147 | 'shininess' Material value.
|
---|
| 148 | */
|
---|
| 149 | void setSpecularColour(const ColourValue& colour);
|
---|
| 150 |
|
---|
| 151 | /** Returns the colour of specular light given off by this light source.
|
---|
| 152 | */
|
---|
| 153 | const ColourValue& getSpecularColour(void) const;
|
---|
| 154 |
|
---|
| 155 | /** Sets the attenuation parameters of the light source ie how it diminishes with distance.
|
---|
| 156 | @remarks
|
---|
| 157 | Lights normally get fainter the further they are away. Also, each light is given a maximum range
|
---|
| 158 | beyond which it cannot affect any objects.
|
---|
| 159 | @par
|
---|
| 160 | Light attentuation is not applicable to directional lights since they have an infinite range and
|
---|
| 161 | constant intensity.
|
---|
| 162 | @par
|
---|
| 163 | This follows a standard attenuation approach - see any good 3D text for the details of what they mean
|
---|
| 164 | since i don't have room here!
|
---|
| 165 | @param
|
---|
| 166 | range The absolute upper range of the light in world units
|
---|
| 167 | @param
|
---|
| 168 | constant The constant factor in the attenuation formula: 1.0 means never attenuate, 0.0 is complete attenuation
|
---|
| 169 | @param
|
---|
| 170 | linear The linear factor in the attenuation formula: 1 means attenuate evenly over the distance
|
---|
| 171 | @param
|
---|
| 172 | quadratic The quadratic factor in the attenuation formula: adds a curvature to the attenuation formula.
|
---|
| 173 | */
|
---|
| 174 | void setAttenuation(Real range, Real constant, Real linear, Real quadratic);
|
---|
| 175 |
|
---|
| 176 | /** Returns the absolute upper range of the light.
|
---|
| 177 | */
|
---|
| 178 | Real getAttenuationRange(void) const;
|
---|
| 179 |
|
---|
| 180 | /** Returns the constant factor in the attenuation formula.
|
---|
| 181 | */
|
---|
| 182 | Real getAttenuationConstant(void) const;
|
---|
| 183 |
|
---|
| 184 | /** Returns the linear factor in the attenuation formula.
|
---|
| 185 | */
|
---|
| 186 | Real getAttenuationLinear(void) const;
|
---|
| 187 |
|
---|
| 188 | /** Returns the quadric factor in the attenuation formula.
|
---|
| 189 | */
|
---|
| 190 | Real getAttenuationQuadric(void) const;
|
---|
| 191 |
|
---|
| 192 | /** Sets the position of the light.
|
---|
| 193 | @remarks
|
---|
| 194 | Applicable to point lights and spotlights only.
|
---|
| 195 | @note
|
---|
| 196 | This will be overridden if the light is attached to a SceneNode.
|
---|
| 197 | */
|
---|
| 198 | void setPosition(Real x, Real y, Real z);
|
---|
| 199 |
|
---|
| 200 | /** Sets the position of the light.
|
---|
| 201 | @remarks
|
---|
| 202 | Applicable to point lights and spotlights only.
|
---|
| 203 | @note
|
---|
| 204 | This will be overridden if the light is attached to a SceneNode.
|
---|
| 205 | */
|
---|
| 206 | void setPosition(const Vector3& vec);
|
---|
| 207 |
|
---|
| 208 | /** Returns the position of the light.
|
---|
| 209 | @note
|
---|
| 210 | Applicable to point lights and spotlights only.
|
---|
| 211 | */
|
---|
| 212 | const Vector3& getPosition(void) const;
|
---|
| 213 |
|
---|
| 214 | /** Sets the direction in which a light points.
|
---|
| 215 | @remarks
|
---|
| 216 | Applicable only to the spotlight and directional light types.
|
---|
| 217 | @note
|
---|
| 218 | This will be overridden if the light is attached to a SceneNode.
|
---|
| 219 | */
|
---|
| 220 | void setDirection(Real x, Real y, Real z);
|
---|
| 221 |
|
---|
| 222 | /** Sets the direction in which a light points.
|
---|
| 223 | @remarks
|
---|
| 224 | Applicable only to the spotlight and directional light types.
|
---|
| 225 | @note
|
---|
| 226 | This will be overridden if the light is attached to a SceneNode.
|
---|
| 227 | */
|
---|
| 228 | void setDirection(const Vector3& vec);
|
---|
| 229 |
|
---|
| 230 | /** Returns the light's direction.
|
---|
| 231 | @remarks
|
---|
| 232 | Applicable only to the spotlight and directional light types.
|
---|
| 233 | */
|
---|
| 234 | const Vector3& getDirection(void) const;
|
---|
| 235 |
|
---|
| 236 | /** Sets the range of a spotlight, i.e. the angle of the inner and outer cones and the rate of falloff between them.
|
---|
| 237 | @param
|
---|
| 238 | innerAngle Angle covered by the bright inner cone
|
---|
| 239 | @node
|
---|
| 240 | The inner cone applicable only to Direct3D, it'll always treat as zero in OpenGL.
|
---|
| 241 | @param
|
---|
| 242 | outerAngle Angle covered by the outer cone
|
---|
| 243 | @param
|
---|
| 244 | falloff The rate of falloff between the inner and outer cones. 1.0 means a linear falloff, less means slower falloff, higher means faster falloff.
|
---|
| 245 | */
|
---|
| 246 | void setSpotlightRange(const Radian& innerAngle, const Radian& outerAngle, Real falloff = 1.0);
|
---|
| 247 | #ifndef OGRE_FORCE_ANGLE_TYPES
|
---|
| 248 | inline void setSpotlightRange(Real innerAngle, Real outerAngle, Real falloff = 1.0) {
|
---|
| 249 | setSpotlightRange ( Angle(innerAngle), Angle(outerAngle), falloff );
|
---|
| 250 | }
|
---|
| 251 | #endif//OGRE_FORCE_ANGLE_TYPES
|
---|
| 252 |
|
---|
| 253 | /** Returns the angle covered by the spotlights inner cone.
|
---|
| 254 | */
|
---|
| 255 | const Radian& getSpotlightInnerAngle(void) const;
|
---|
| 256 |
|
---|
| 257 | /** Returns the angle covered by the spotlights outer cone.
|
---|
| 258 | */
|
---|
| 259 | const Radian& getSpotlightOuterAngle(void) const;
|
---|
| 260 |
|
---|
| 261 | /** Returns the falloff between the inner and outer cones of the spotlight.
|
---|
| 262 | */
|
---|
| 263 | Real getSpotlightFalloff(void) const;
|
---|
| 264 |
|
---|
| 265 | /** Overridden from MovableObject */
|
---|
| 266 | void _notifyCurrentCamera(Camera* cam);
|
---|
| 267 |
|
---|
| 268 | /** Overridden from MovableObject */
|
---|
| 269 | const AxisAlignedBox& getBoundingBox(void) const;
|
---|
| 270 |
|
---|
| 271 | /** Overridden from MovableObject */
|
---|
| 272 | void _updateRenderQueue(RenderQueue* queue);
|
---|
| 273 |
|
---|
| 274 | /** Overridden from MovableObject */
|
---|
| 275 | const String& getMovableType(void) const;
|
---|
| 276 |
|
---|
| 277 | /** Retrieves the position of the light including any transform from nodes it is attached to. */
|
---|
| 278 | const Vector3& getDerivedPosition(void) const;
|
---|
| 279 |
|
---|
| 280 | /** Retrieves the direction of the light including any transform from nodes it is attached to. */
|
---|
| 281 | const Vector3& getDerivedDirection(void) const;
|
---|
| 282 |
|
---|
| 283 | /** Overridden from MovableObject.
|
---|
| 284 | @remarks
|
---|
| 285 | Although lights themselves are not 'visible', setting a light to invisible
|
---|
| 286 | means it no longer affects the scene.
|
---|
| 287 | */
|
---|
| 288 | void setVisible(bool visible);
|
---|
| 289 |
|
---|
| 290 | /** Overridden from MovableObject */
|
---|
| 291 | Real getBoundingRadius(void) const { return 0; /* not visible */ }
|
---|
| 292 |
|
---|
| 293 | /** Gets the details of this light as a 4D vector.
|
---|
| 294 | @remarks
|
---|
| 295 | Getting details of a light as a 4D vector can be useful for
|
---|
| 296 | doing general calculations between different light types; for
|
---|
| 297 | example the vector can represent both position lights (w=1.0f)
|
---|
| 298 | and directional lights (w=0.0f) and be used in the same
|
---|
| 299 | calculations.
|
---|
| 300 | */
|
---|
| 301 | Vector4 getAs4DVector(void) const;
|
---|
| 302 |
|
---|
| 303 | /** Internal method for calculating the 'near clip volume', which is
|
---|
| 304 | the volume formed between the near clip rectangle of the
|
---|
| 305 | camera and the light.
|
---|
| 306 | @remarks This volume is a pyramid for a point/spot light and
|
---|
| 307 | a cuboid for a directional light. It can used to detect whether
|
---|
| 308 | an object could be casting a shadow on the viewport. Note that
|
---|
| 309 | the reference returned is to a shared volume which will be
|
---|
| 310 | reused across calls to this method.
|
---|
| 311 | */
|
---|
| 312 | const PlaneBoundedVolume& _getNearClipVolume(const Camera* const cam) const;
|
---|
| 313 |
|
---|
| 314 | /** Internal method for calculating the clip volumes outside of the
|
---|
| 315 | frustum which can be used to determine which objects are casting
|
---|
| 316 | shadow on the frustum as a whole.
|
---|
| 317 | @remarks Each of the volumes is a pyramid for a point/spot light and
|
---|
| 318 | a cuboid for a directional light.
|
---|
| 319 | */
|
---|
| 320 | const PlaneBoundedVolumeList& _getFrustumClipVolumes(const Camera* const cam) const;
|
---|
| 321 |
|
---|
| 322 |
|
---|
| 323 |
|
---|
| 324 | private:
|
---|
| 325 | /// internal method for synchronising with parent node (if any)
|
---|
| 326 | void update(void) const;
|
---|
| 327 | String mName;
|
---|
| 328 |
|
---|
| 329 | LightTypes mLightType;
|
---|
| 330 | Vector3 mPosition;
|
---|
| 331 | ColourValue mDiffuse;
|
---|
| 332 | ColourValue mSpecular;
|
---|
| 333 |
|
---|
| 334 | Vector3 mDirection;
|
---|
| 335 |
|
---|
| 336 | Radian mSpotOuter;
|
---|
| 337 | Radian mSpotInner;
|
---|
| 338 | Real mSpotFalloff;
|
---|
| 339 | Real mRange;
|
---|
| 340 | Real mAttenuationConst;
|
---|
| 341 | Real mAttenuationLinear;
|
---|
| 342 | Real mAttenuationQuad;
|
---|
| 343 |
|
---|
| 344 | mutable Vector3 mDerivedPosition;
|
---|
| 345 | mutable Vector3 mDerivedDirection;
|
---|
| 346 | /// Stored versions of parent orientation / position
|
---|
| 347 | mutable Quaternion mLastParentOrientation;
|
---|
| 348 | mutable Vector3 mLastParentPosition;
|
---|
| 349 |
|
---|
| 350 | /// Shared class-level name for Movable type
|
---|
| 351 | static String msMovableType;
|
---|
| 352 |
|
---|
| 353 | mutable PlaneBoundedVolume mNearClipVolume;
|
---|
| 354 | mutable PlaneBoundedVolumeList mFrustumClipVolumes;
|
---|
| 355 | /// Is the local transform dirty?
|
---|
| 356 | mutable bool mLocalTransformDirty;
|
---|
| 357 |
|
---|
| 358 |
|
---|
| 359 |
|
---|
| 360 | };
|
---|
| 361 | } // Namespace
|
---|
| 362 | #endif
|
---|