/src/ogre/OgreMain/include/OgreLight.h
Line | Count | Source (jump to first uncovered line) |
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-2014 Torus Knot Software Ltd |
8 | | |
9 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
10 | | of this software and associated documentation files (the "Software"), to deal |
11 | | in the Software without restriction, including without limitation the rights |
12 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13 | | copies of the Software, and to permit persons to whom the Software is |
14 | | furnished to do so, subject to the following conditions: |
15 | | |
16 | | The above copyright notice and this permission notice shall be included in |
17 | | all copies or substantial portions of the Software. |
18 | | |
19 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25 | | THE SOFTWARE. |
26 | | ----------------------------------------------------------------------------- |
27 | | */ |
28 | | #ifndef _LIGHT_H__ |
29 | | #define _LIGHT_H__ |
30 | | |
31 | | #include "OgrePrerequisites.h" |
32 | | |
33 | | #include "OgreColourValue.h" |
34 | | #include "OgreVector.h" |
35 | | #include "OgreMovableObject.h" |
36 | | #include "OgrePlaneBoundedVolume.h" |
37 | | #include "OgreNode.h" |
38 | | #include "OgreCamera.h" |
39 | | #include "OgreHeaderPrefix.h" |
40 | | |
41 | | namespace Ogre { |
42 | | |
43 | | |
44 | | /** \addtogroup Core |
45 | | * @{ |
46 | | */ |
47 | | /** \addtogroup Scene |
48 | | * @{ |
49 | | */ |
50 | | /** Representation of a dynamic light source in the scene. |
51 | | |
52 | | Lights are added to the scene like any other object. They contain various |
53 | | parameters like type, attenuation (how light intensity fades with |
54 | | distance), colour etc. |
55 | | |
56 | | The light colour is computed based on the |
57 | | [Direct3D Light Model](https://docs.microsoft.com/en-us/windows/win32/direct3d9/mathematics-of-lighting) as: |
58 | | |
59 | | \f[ L_d = C_d \cdot p \cdot ( N \cdot L_{dir}) \cdot A \cdot S \f] |
60 | | \f[ L_s = C_s \cdot p \cdot ( N \cdot H)^s \cdot A \cdot S \f] |
61 | | |
62 | | where |
63 | | \f[ A = \frac{1}{c + l \cdot d + q \cdot d^2} \f] |
64 | | and only computed when attenuation is enabled, |
65 | | |
66 | | \f[ S = \left[ \frac{\rho - cos(0.5 \cdot \phi)}{cos(0.5 \cdot \theta) - cos(0.5 \cdot \phi)} \right]^f \f] |
67 | | and only computed with spotlights |
68 | | |
69 | | - \f$C_d\f$ is the light diffuse colour |
70 | | - \f$C_s\f$ is the light specular colour |
71 | | - \f$p\f$ is the light power scale factor |
72 | | - \f$s\f$ is the surface shininess |
73 | | - \f$N\f$ is the current surface normal |
74 | | - \f$L_{dir}\f$ is vector from the vertex position to the light (constant for directional lights) |
75 | | - \f$H = normalised(L_{dir} + V)\f$, where V is the vector from the vertex position to the camera |
76 | | - \f$c, l, q\f$ are the constant, linear and quadratic attenuation factors |
77 | | - \f$d = |L_{dir}|\f$ |
78 | | - \f$\theta, \phi, f\f$ are the spotlight inner angle, outer angle and falloff |
79 | | - \f$\rho = \langle L_{dir} , L_{dcs} \rangle \f$ where \f$L_{dcs}\f$ is the light direction in camera space |
80 | | |
81 | | The defaults when a light is created is pure white diffuse light, with no |
82 | | attenuation (does not decrease with distance) and a range of 1000 world units. |
83 | | |
84 | | Lights are created by using the SceneManager::createLight method. They subsequently must be |
85 | | added to a SceneNode to orient them in the scene and to allow moving them. |
86 | | |
87 | | Remember also that dynamic lights rely on modifying the colour of vertices based on the position of |
88 | | the light compared to an object's vertex normals. Dynamic lighting will only look good if the |
89 | | object being lit has a fair level of tessellation and the normals are properly set. This is particularly |
90 | | true for the spotlight which will only look right on highly tessellated models. In the future OGRE may be |
91 | | extended for certain scene types so an alternative to the standard dynamic lighting may be used, such |
92 | | as dynamic lightmaps. |
93 | | */ |
94 | | class _OgreExport Light : public MovableObject |
95 | | { |
96 | | public: |
97 | | /// Temp tag used for sorting |
98 | | Real tempSquareDist; |
99 | | /// internal method for calculating current squared distance from some world position |
100 | | void _calcTempSquareDist(const Vector3& worldPos); |
101 | | |
102 | | /// Defines the type of light |
103 | | enum LightTypes : uint8 |
104 | | { |
105 | | /// Point light sources give off light equally in all directions, so require only position not direction |
106 | | LT_POINT = 0, |
107 | | /// Directional lights simulate parallel light beams from a distant source, hence have direction but no position |
108 | | LT_DIRECTIONAL = 1, |
109 | | /// Spotlights simulate a cone of light from a source so require position and direction, plus extra values for falloff |
110 | | LT_SPOTLIGHT = 2, |
111 | | /// A rectangular area light, requires position, direction, width and height |
112 | | LT_RECTLIGHT = 3 |
113 | | }; |
114 | | |
115 | | /** Default constructor (for Python mainly). |
116 | | */ |
117 | | Light(); |
118 | | |
119 | | /** Normal constructor. Should not be called directly, but rather the SceneManager::createLight method should be used. |
120 | | */ |
121 | | Light(const String& name); |
122 | | |
123 | | /** Standard destructor. |
124 | | */ |
125 | | ~Light(); |
126 | | |
127 | | /** Sets the type of light - see LightTypes for more info. |
128 | | */ |
129 | | void setType(LightTypes type); |
130 | | |
131 | | /** Returns the light type. |
132 | | */ |
133 | | LightTypes getType(void) const; |
134 | | |
135 | | /** Sets the colour of the diffuse light given off by this source. |
136 | | |
137 | | Material objects have ambient, diffuse and specular values which indicate how much of each type of |
138 | | light an object reflects. This value denotes the amount and colour of this type of light the light |
139 | | exudes into the scene. The actual appearance of objects is a combination of the two. |
140 | | @par |
141 | | Diffuse light simulates the typical light emanating from light sources and affects the base colour |
142 | | of objects together with ambient light. |
143 | | */ |
144 | | void setDiffuseColour(float red, float green, float blue); |
145 | | |
146 | | /// @overload |
147 | | void setDiffuseColour(const ColourValue& colour); |
148 | | |
149 | | /** Returns the colour of the diffuse light given off by this light source (see setDiffuseColour for more info). |
150 | | */ |
151 | | const ColourValue& getDiffuseColour(void) const; |
152 | | |
153 | | /** Sets the colour of the specular light given off by this source. |
154 | | |
155 | | Material objects have ambient, diffuse and specular values which indicate how much of each type of |
156 | | light an object reflects. This value denotes the amount and colour of this type of light the light |
157 | | exudes into the scene. The actual appearance of objects is a combination of the two. |
158 | | @par |
159 | | Specular light affects the appearance of shiny highlights on objects, and is also dependent on the |
160 | | 'shininess' Material value. |
161 | | */ |
162 | | void setSpecularColour(float red, float green, float blue); |
163 | | |
164 | | /// @overload |
165 | | void setSpecularColour(const ColourValue& colour); |
166 | | |
167 | | /** Returns the colour of specular light given off by this light source. |
168 | | */ |
169 | | const ColourValue& getSpecularColour(void) const; |
170 | | |
171 | | /** Sets the attenuation parameters of the light source i.e. how it diminishes with distance. |
172 | | |
173 | | Lights normally get fainter the further they are away. Also, each light is given a maximum range |
174 | | beyond which it cannot affect any objects. |
175 | | @par |
176 | | Light attenuation is not applicable to directional lights since they have an infinite range and |
177 | | constant intensity. |
178 | | @par |
179 | | This follows a standard attenuation approach - see any good 3D text for the details of what they mean |
180 | | since i don't have room here! |
181 | | @param range |
182 | | The absolute upper range of the light in world units. |
183 | | @param constant |
184 | | The constant factor in the attenuation formula: 1.0 means never attenuate, 0.0 is complete attenuation. |
185 | | @param linear |
186 | | The linear factor in the attenuation formula: 1 means attenuate evenly over the distance. |
187 | | @param quadratic |
188 | | The quadratic factor in the attenuation formula: adds a curvature to the attenuation formula. |
189 | | */ |
190 | | void setAttenuation(float range, float constant, float linear, float quadratic) |
191 | 0 | { |
192 | 0 | mAttenuation = {range, constant, linear, quadratic}; |
193 | 0 | } |
194 | | |
195 | | /** Returns the absolute upper range of the light. |
196 | | */ |
197 | 0 | float getAttenuationRange(void) const { return mAttenuation[0]; } |
198 | | |
199 | | /** Returns the constant factor in the attenuation formula. |
200 | | */ |
201 | 0 | float getAttenuationConstant(void) const { return mAttenuation[1]; } |
202 | | |
203 | | /** Returns the linear factor in the attenuation formula. |
204 | | */ |
205 | 0 | float getAttenuationLinear(void) const { return mAttenuation[2]; } |
206 | | |
207 | | /** Returns the quadric factor in the attenuation formula. |
208 | | */ |
209 | 0 | float getAttenuationQuadric(void) const { return mAttenuation[3]; } |
210 | | |
211 | | /// Returns all the attenuation params as (range, constant, linear, quadratic) |
212 | 0 | const Vector4f& getAttenuation() const { return mAttenuation; } |
213 | | |
214 | | #ifdef OGRE_NODELESS_POSITIONING |
215 | | /** Sets the position of the light. |
216 | | |
217 | | Applicable to point lights and spotlights only. |
218 | | @note |
219 | | This will be overridden if the light is attached to a SceneNode. |
220 | | @deprecated attach to SceneNode and use SceneNode::setPosition |
221 | | */ |
222 | | OGRE_DEPRECATED void setPosition(Real x, Real y, Real z); |
223 | | |
224 | | /// @overload |
225 | | /// @deprecated attach to SceneNode and use SceneNode::setPosition |
226 | | OGRE_DEPRECATED void setPosition(const Vector3& vec); |
227 | | |
228 | | /** Returns the position of the light. |
229 | | @note |
230 | | Applicable to point lights and spotlights only. |
231 | | @deprecated attach to SceneNode and use SceneNode::getPosition |
232 | | */ |
233 | | OGRE_DEPRECATED const Vector3& getPosition(void) const; |
234 | | |
235 | | /// @deprecated attach to SceneNode and use SceneNode::setDirection |
236 | | OGRE_DEPRECATED void setDirection(Real x, Real y, Real z); |
237 | | |
238 | | /// @overload |
239 | | /// @deprecated attach to SceneNode and use SceneNode::setDirection |
240 | | OGRE_DEPRECATED void setDirection(const Vector3& vec); |
241 | | |
242 | | /** |
243 | | @deprecated attach to SceneNode and use SceneNode::getLocalAxes |
244 | | */ |
245 | | OGRE_DEPRECATED const Vector3& getDirection(void) const; |
246 | | |
247 | | void _notifyAttached(Node* parent, bool isTagPoint = false) override; |
248 | | void _notifyMoved(void) override; |
249 | | #endif |
250 | | /** Sets the range of a spotlight, i.e. the angle of the inner and outer cones |
251 | | and the rate of falloff between them. |
252 | | @param innerAngle |
253 | | Angle covered by the bright inner cone |
254 | | @note |
255 | | The inner cone applicable only to Direct3D, it'll always treat as zero in OpenGL. |
256 | | @param outerAngle |
257 | | Angle covered by the outer cone |
258 | | @param falloff |
259 | | The rate of falloff between the inner and outer cones. 1.0 means a linear falloff, |
260 | | less means slower falloff, higher means faster falloff. |
261 | | */ |
262 | | void setSpotlightRange(const Radian& innerAngle, const Radian& outerAngle, Real falloff = 1.0); |
263 | | |
264 | | /** Returns the angle covered by the spotlights inner cone. |
265 | | */ |
266 | | const Radian& getSpotlightInnerAngle(void) const; |
267 | | |
268 | | /** Returns the angle covered by the spotlights outer cone. |
269 | | */ |
270 | | const Radian& getSpotlightOuterAngle(void) const; |
271 | | |
272 | | /** Returns the falloff between the inner and outer cones of the spotlight. |
273 | | */ |
274 | | Real getSpotlightFalloff(void) const; |
275 | | |
276 | | /** Sets the angle covered by the spotlights inner cone. |
277 | | */ |
278 | | void setSpotlightInnerAngle(const Radian& val); |
279 | | |
280 | | /** Sets the angle covered by the spotlights outer cone. |
281 | | */ |
282 | | void setSpotlightOuterAngle(const Radian& val); |
283 | | |
284 | | /** Sets the falloff between the inner and outer cones of the spotlight. |
285 | | */ |
286 | | void setSpotlightFalloff(Real val); |
287 | | |
288 | | /** Set the near clip plane distance to be used by spotlights that use light |
289 | | clipping, allowing you to render spots as if they start from further |
290 | | down their frustum. |
291 | | @param nearClip |
292 | | The near distance. |
293 | | */ |
294 | 0 | void setSpotlightNearClipDistance(Real nearClip) { mSpotNearClip = nearClip; } |
295 | | |
296 | | /** Returns the near clip plane distance to be used by spotlights that use light |
297 | | clipping. |
298 | | */ |
299 | 0 | Real getSpotlightNearClipDistance() const { return mSpotNearClip; } |
300 | | |
301 | | /** Sets the size of the area covered by a area light. */ |
302 | 0 | void setSourceSize(float width, float height) { mSourceSize = {width, height}; } |
303 | 0 | Vector2f getSourceSize() const { return mSourceSize; } |
304 | | |
305 | | /// The width half vector of the source in world space |
306 | | Vector3f getDerivedSourceHalfWidth() const; |
307 | | |
308 | | /// The height half vector of the source in world space |
309 | | Vector3f getDerivedSourceHalfHeight() const; |
310 | | |
311 | | /** Set a scaling factor to indicate the relative power of a light. |
312 | | |
313 | | This factor is only useful in High Dynamic Range (HDR) rendering. |
314 | | You can bind it to a shader variable to take it into account, |
315 | | @see GpuProgramParameters |
316 | | @param power |
317 | | The power rating of this light, default is 1.0. |
318 | | */ |
319 | | void setPowerScale(Real power); |
320 | | |
321 | | /** Returns the scaling factor which indicates the relative power of a |
322 | | light. |
323 | | */ |
324 | | Real getPowerScale(void) const; |
325 | | |
326 | 0 | Real getBoundingRadius(void) const override { return 0; } |
327 | | const AxisAlignedBox& getBoundingBox(void) const override; |
328 | | |
329 | 0 | void _updateRenderQueue(RenderQueue* queue) override {} // No rendering |
330 | | |
331 | | /** @copydoc MovableObject::getMovableType */ |
332 | | const String& getMovableType(void) const override; |
333 | | |
334 | | /** Retrieves the position of the light including any transform from nodes it is attached to. |
335 | | @param cameraRelativeIfSet If set to true, returns data in camera-relative units if that's been set up (render use) |
336 | | */ |
337 | | #ifdef OGRE_NODELESS_POSITIONING |
338 | | const Vector3& getDerivedPosition(bool cameraRelativeIfSet = false) const; |
339 | | #else |
340 | | Vector3 getDerivedPosition(bool cameraRelativeIfSet = false) const |
341 | 0 | { |
342 | 0 | assert(mParentNode && "Light must be attached to a SceneNode"); |
343 | 0 | auto ret = mParentNode->_getDerivedPosition(); |
344 | 0 | if (cameraRelativeIfSet && mCameraToBeRelativeTo) |
345 | 0 | ret -= mCameraToBeRelativeTo->getDerivedPosition(); |
346 | 0 | return ret; |
347 | 0 | } |
348 | | #endif |
349 | | |
350 | | /** Retrieves the direction of the light including any transform from nodes it is attached to. */ |
351 | | #ifdef OGRE_NODELESS_POSITIONING |
352 | | const Vector3& getDerivedDirection(void) const; |
353 | | #else |
354 | | Vector3 getDerivedDirection(void) const |
355 | 0 | { |
356 | 0 | assert(mParentNode && "Light must be attached to a SceneNode"); |
357 | 0 | return -mParentNode->_getDerivedOrientation().zAxis(); |
358 | 0 | } |
359 | | #endif |
360 | | |
361 | | /** @copydoc MovableObject::setVisible |
362 | | |
363 | | Although lights themselves are not 'visible', setting a light to invisible |
364 | | means it no longer affects the scene. |
365 | | */ |
366 | 0 | void setVisible(bool visible) { MovableObject::setVisible(visible); } |
367 | | |
368 | | /** Returns the details of this light as a 4D vector. |
369 | | |
370 | | Getting details of a light as a 4D vector can be useful for |
371 | | doing general calculations between different light types; for |
372 | | example the vector can represent both position lights (w=1.0f) |
373 | | and directional lights (w=0.0f) and be used in the same |
374 | | calculations. |
375 | | @param cameraRelativeIfSet |
376 | | If set to @c true, returns data in camera-relative units if that's been set up (render use). |
377 | | */ |
378 | | Vector4 getAs4DVector(bool cameraRelativeIfSet = false) const; |
379 | | |
380 | | /** Internal method for calculating the 'near clip volume', which is |
381 | | the volume formed between the near clip rectangle of the |
382 | | camera and the light. |
383 | | |
384 | | This volume is a pyramid for a point/spot light and |
385 | | a cuboid for a directional light. It can used to detect whether |
386 | | an object could be casting a shadow on the viewport. Note that |
387 | | the reference returned is to a shared volume which will be |
388 | | reused across calls to this method. |
389 | | */ |
390 | | virtual const PlaneBoundedVolume& _getNearClipVolume(const Camera* const cam) const; |
391 | | |
392 | | /** Internal method for calculating the clip volumes outside of the |
393 | | frustum which can be used to determine which objects are casting |
394 | | shadow on the frustum as a whole. |
395 | | |
396 | | Each of the volumes is a pyramid for a point/spot light and |
397 | | a cuboid for a directional light. |
398 | | */ |
399 | | virtual const PlaneBoundedVolumeList& _getFrustumClipVolumes(const Camera* const cam) const; |
400 | | |
401 | | /// Override to return specific type flag |
402 | | uint32 getTypeFlags(void) const override; |
403 | | |
404 | | /// @copydoc AnimableObject::createAnimableValue |
405 | | AnimableValuePtr createAnimableValue(const String& valueName) override; |
406 | | |
407 | | /** Set this light to use a custom shadow camera when rendering texture shadows. |
408 | | |
409 | | This changes the shadow camera setup for just this light, you can set |
410 | | the shadow camera setup globally using SceneManager::setShadowCameraSetup |
411 | | @see ShadowCameraSetup |
412 | | */ |
413 | | void setCustomShadowCameraSetup(const ShadowCameraSetupPtr& customShadowSetup); |
414 | | |
415 | | /** Reset the shadow camera setup to the default. |
416 | | @see ShadowCameraSetup |
417 | | */ |
418 | | void resetCustomShadowCameraSetup(void); |
419 | | |
420 | | /** Return a pointer to the custom shadow camera setup (null means use SceneManager global version). */ |
421 | | const ShadowCameraSetupPtr& getCustomShadowCameraSetup(void) const; |
422 | | |
423 | | void visitRenderables(Renderable::Visitor* visitor, |
424 | | bool debugRenderables = false) override; |
425 | | |
426 | | /** Returns the index at which this light is in the current render. |
427 | | |
428 | | Lights will be present in the in a list for every renderable, |
429 | | detected and sorted appropriately, and sometimes it's useful to know |
430 | | what position in that list a given light occupies. This can vary |
431 | | from frame to frame (and object to object) so you should not use this |
432 | | value unless you're sure the context is correct. |
433 | | */ |
434 | 0 | size_t _getIndexInFrame() const { return mIndexInFrame; } |
435 | 0 | void _notifyIndexInFrame(size_t i) { mIndexInFrame = i; } |
436 | | |
437 | | /** Sets the maximum distance away from the camera that shadows |
438 | | by this light will be visible. |
439 | | |
440 | | Shadow techniques can be expensive, therefore it is a good idea |
441 | | to limit them to being rendered close to the camera if possible, |
442 | | and to skip the expense of rendering shadows for distance objects. |
443 | | This method allows you to set the distance at which shadows casters |
444 | | will be culled. |
445 | | */ |
446 | | void setShadowFarDistance(Real distance); |
447 | | /** Tells the light to use the shadow far distance of the SceneManager |
448 | | */ |
449 | | void resetShadowFarDistance(void); |
450 | | /** Returns the maximum distance away from the camera that shadows |
451 | | by this light will be visible. |
452 | | */ |
453 | | Real getShadowFarDistance(void) const; |
454 | | Real getShadowFarDistanceSquared(void) const; |
455 | | |
456 | | /** Set the near clip plane distance to be used by the shadow camera, if |
457 | | this light casts texture shadows. |
458 | | @param nearClip |
459 | | The distance, or -1 to use the main camera setting. |
460 | | */ |
461 | 0 | void setShadowNearClipDistance(Real nearClip) { mShadowNearClipDist = nearClip; } |
462 | | |
463 | | /** Returns the near clip plane distance to be used by the shadow camera, if |
464 | | this light casts texture shadows. |
465 | | |
466 | | May be zero if the light doesn't have it's own near distance set; |
467 | | use _deriveShadowNearDistance for a version guaranteed to give a result. |
468 | | */ |
469 | 0 | Real getShadowNearClipDistance() const { return mShadowNearClipDist; } |
470 | | |
471 | | /** Derive a shadow camera near distance from either the light, or |
472 | | from the main camera if the light doesn't have its own setting. |
473 | | */ |
474 | | Real _deriveShadowNearClipDistance(const Camera* maincam) const; |
475 | | |
476 | | /** Set the far clip plane distance to be used by the shadow camera, if |
477 | | this light casts texture shadows. |
478 | | |
479 | | This is different from the 'shadow far distance', which is |
480 | | always measured from the main camera. This distance is the far clip plane |
481 | | of the light camera. |
482 | | @param farClip |
483 | | The distance, or -1 to use the main camera setting. |
484 | | */ |
485 | 0 | void setShadowFarClipDistance(Real farClip) { mShadowFarClipDist = farClip; } |
486 | | |
487 | | /** Returns the far clip plane distance to be used by the shadow camera, if |
488 | | this light casts texture shadows. |
489 | | |
490 | | May be zero if the light doesn't have it's own far distance set; |
491 | | use _deriveShadowfarDistance for a version guaranteed to give a result. |
492 | | */ |
493 | 0 | Real getShadowFarClipDistance() const { return mShadowFarClipDist; } |
494 | | |
495 | | /** Derive a shadow camera far distance |
496 | | */ |
497 | | Real _deriveShadowFarClipDistance() const; |
498 | | /// @deprecated use _deriveShadowFarClipDistance() |
499 | | OGRE_DEPRECATED Real _deriveShadowFarClipDistance(const Camera*) const |
500 | 0 | { |
501 | 0 | return _deriveShadowFarClipDistance(); |
502 | 0 | } |
503 | | |
504 | | /// Set the camera which this light should be relative to, for camera-relative rendering |
505 | | void _setCameraRelative(Camera* cam); |
506 | | |
507 | | /** Sets a custom parameter for this Light, which may be used to |
508 | | drive calculations for this specific Renderable, like GPU program parameters. |
509 | | |
510 | | Calling this method simply associates a numeric index with a 4-dimensional |
511 | | value for this specific Light. This is most useful if the material |
512 | | which this Renderable uses a vertex or fragment program, and has an |
513 | | ACT_LIGHT_CUSTOM parameter entry. This parameter entry can refer to the |
514 | | index you specify as part of this call, thereby mapping a custom |
515 | | parameter for this renderable to a program parameter. |
516 | | @param index |
517 | | The index with which to associate the value. Note that this |
518 | | does not have to start at 0, and can include gaps. It also has no direct |
519 | | correlation with a GPU program parameter index - the mapping between the |
520 | | two is performed by the ACT_LIGHT_CUSTOM entry, if that is used. |
521 | | @param value |
522 | | The value to associate. |
523 | | */ |
524 | | void setCustomParameter(uint16 index, const Vector4f& value); |
525 | | |
526 | | /** Returns the custom value associated with this Light at the given index. |
527 | | @param index Index of the parameter to retrieve |
528 | | @see setCustomParameter for full details. |
529 | | */ |
530 | | const Vector4f& getCustomParameter(uint16 index) const; |
531 | | |
532 | | /** Update a custom GpuProgramParameters constant which is derived from |
533 | | information only this Light knows. |
534 | | |
535 | | This method allows a Light to map in a custom GPU program parameter |
536 | | based on it's own data. This is represented by a GPU auto parameter |
537 | | of ACT_LIGHT_CUSTOM, and to allow there to be more than one of these per |
538 | | Light, the 'data' field on the auto parameter will identify |
539 | | which parameter is being updated and on which light. The implementation |
540 | | of this method must identify the parameter being updated, and call a 'setConstant' |
541 | | method on the passed in GpuProgramParameters object. |
542 | | @par |
543 | | You do not need to override this method if you're using the standard |
544 | | sets of data associated with the Renderable as provided by setCustomParameter |
545 | | and getCustomParameter. By default, the implementation will map from the |
546 | | value indexed by the 'constantEntry.data' parameter to a value previously |
547 | | set by setCustomParameter. But custom Renderables are free to override |
548 | | this if they want, in any case. |
549 | | @param paramIndex |
550 | | The index of the constant being updated |
551 | | @param constantEntry |
552 | | The auto constant entry from the program parameters |
553 | | @param params |
554 | | The parameters object which this method should call to |
555 | | set the updated parameters. |
556 | | */ |
557 | | virtual void _updateCustomGpuParameter(uint16 paramIndex, |
558 | | const GpuProgramParameters::AutoConstantEntry& constantEntry, |
559 | | GpuProgramParameters* params) const; |
560 | | |
561 | | /** Check whether a sphere is included in the lighted area of the light |
562 | | @note |
563 | | The function trades accuracy for efficiency. As a result you may get |
564 | | false-positives (The function should not return any false-negatives). |
565 | | */ |
566 | | bool isInLightRange(const Ogre::Sphere& sphere) const; |
567 | | |
568 | | /** Check whether a bounding box is included in the lighted area of the light |
569 | | @note |
570 | | The function trades accuracy for efficiency. As a result you may get |
571 | | false-positives (The function should not return any false-negatives). |
572 | | */ |
573 | | bool isInLightRange(const Ogre::AxisAlignedBox& container) const; |
574 | | |
575 | | private: |
576 | | #ifdef OGRE_NODELESS_POSITIONING |
577 | | Vector3 mPosition; |
578 | | Vector3 mDirection; |
579 | | mutable Vector3 mDerivedPosition; |
580 | | mutable Vector3 mDerivedDirection; |
581 | | // Slightly hacky but unless we separate observed light render state from main Light... |
582 | | mutable Vector3 mDerivedCamRelativePosition; |
583 | | mutable bool mDerivedCamRelativeDirty; |
584 | | /// Is the derived transform dirty? |
585 | | mutable bool mDerivedTransformDirty; |
586 | | |
587 | | /// Internal method for synchronising with parent node (if any) |
588 | | virtual void update(void) const; |
589 | | #endif |
590 | | ColourValue mDiffuse; |
591 | | ColourValue mSpecular; |
592 | | |
593 | | Radian mSpotOuter; |
594 | | Radian mSpotInner; |
595 | | Real mSpotFalloff; |
596 | | Real mSpotNearClip; |
597 | | // range, const, linear, quad coeffs |
598 | | Vector4f mAttenuation; |
599 | | Real mShadowFarDist; |
600 | | Real mShadowFarDistSquared; |
601 | | size_t mIndexInFrame; |
602 | | |
603 | | Real mShadowNearClipDist; |
604 | | Real mShadowFarClipDist; |
605 | | |
606 | | Camera* mCameraToBeRelativeTo; |
607 | | |
608 | | mutable PlaneBoundedVolume mNearClipVolume; |
609 | | mutable PlaneBoundedVolumeList mFrustumClipVolumes; |
610 | | |
611 | | /// Pointer to a custom shadow camera setup. |
612 | | mutable ShadowCameraSetupPtr mCustomShadowCameraSetup; |
613 | | |
614 | | typedef std::map<uint16, Vector4f> CustomParameterMap; |
615 | | /// Stores the custom parameters for the light. |
616 | | CustomParameterMap mCustomParameters; |
617 | | Real mPowerScale; |
618 | | Vector2f mSourceSize; |
619 | | LightTypes mLightType; |
620 | | bool mOwnShadowFarDist; |
621 | | }; |
622 | | /** @} */ |
623 | | /** @} */ |
624 | | |
625 | | #include "OgreHeaderSuffix.h" |
626 | | |
627 | | } // namespace Ogre |
628 | | #endif // _LIGHT_H__ |