Coverage Report

Created: 2026-07-25 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ogre/OgreMain/src/OgreAutoParamDataSource.cpp
Line
Count
Source
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
#include "OgreStableHeaders.h"
29
30
#include "OgreAutoParamDataSource.h"
31
#include "OgreRenderable.h"
32
#include "OgreControllerManager.h"
33
#include "OgreViewport.h"
34
35
namespace Ogre {
36
    //-----------------------------------------------------------------------------
37
    AutoParamDataSource::AutoParamDataSource()
38
0
        : mWorldMatrixCount(0),
39
0
         mWorldMatrixArray(0),
40
0
         mWorldMatrixDirty(true),
41
0
         mViewMatrixDirty(true),
42
0
         mProjMatrixDirty(true),
43
0
         mWorldViewMatrixDirty(true),
44
0
         mViewProjMatrixDirty(true),
45
0
         mWorldViewProjMatrixDirty(true),
46
0
         mInverseWorldMatrixDirty(true),
47
0
         mInverseWorldViewMatrixDirty(true),
48
0
         mInverseViewMatrixDirty(true),
49
0
         mInverseTransposeWorldMatrixDirty(true),
50
0
         mInverseTransposeWorldViewMatrixDirty(true),
51
0
         mCameraPositionDirty(true),
52
0
         mCameraPositionObjectSpaceDirty(true),
53
0
         mAmbientLight(ColourValue::Black),
54
0
         mShadowColour(ColourValue(0.25, 0.25, 0.25)),
55
0
         mPassNumber(0),
56
0
         mSceneDepthRangeDirty(true),
57
0
         mLodCameraPositionDirty(true),
58
0
         mLodCameraPositionObjectSpaceDirty(true),
59
0
         mCurrentRenderable(0),
60
0
         mCurrentCamera(0),
61
0
         mCameraRelativeRendering(false),
62
0
         mCurrentLightList(0),
63
0
         mCurrentRenderTarget(0),
64
0
         mCurrentViewport(0), 
65
0
         mCurrentSceneManager(0),
66
0
         mMainCamBoundsInfo(0),
67
0
         mCurrentPass(0),
68
0
         mDummyNode(NULL),
69
0
         mLastLightHash(1),
70
0
         mGpuParamsDirty(GPV_ALL),
71
0
         mCurrentUseIdentityView(false),
72
0
         mCurrentUseIdentityProj(false)
73
0
    {
74
0
        mBlankLight.setDiffuseColour(ColourValue::Black);
75
0
        mBlankLight.setSpecularColour(ColourValue::Black);
76
0
        mBlankLight.setAttenuation(0,1,0,0);
77
0
        mDummyNode.attachObject(&mBlankLight);
78
0
        for(size_t i = 0; i < OGRE_MAX_SIMULTANEOUS_LIGHTS; ++i)
79
0
        {
80
0
            mTextureViewProjMatrixDirty[i] = true;
81
0
            mTextureWorldViewProjMatrixDirty[i] = true;
82
0
            mSpotlightViewProjMatrixDirty[i] = true;
83
0
            mSpotlightWorldViewProjMatrixDirty[i] = true;
84
0
            mCurrentTextureProjector[i] = 0;
85
0
            mShadowCamDepthRangesDirty[i] = false;
86
0
        }
87
88
0
    }
89
    //-----------------------------------------------------------------------------
90
  const Camera* AutoParamDataSource::getCurrentCamera() const
91
0
  {
92
0
    return mCurrentCamera;
93
0
  }
94
  //-----------------------------------------------------------------------------
95
    const Light& AutoParamDataSource::getLight(size_t index) const
96
0
    {
97
        // If outside light range, return a blank light to ensure zeroised for program
98
0
        if (mCurrentLightList && index < mCurrentLightList->size())
99
0
        {
100
0
            return *((*mCurrentLightList)[index]);
101
0
        }
102
0
        else
103
0
        {
104
0
            return mBlankLight;
105
0
        }        
106
0
    }
107
    //-----------------------------------------------------------------------------
108
    void AutoParamDataSource::setCurrentRenderable(const Renderable* rend)
109
0
    {
110
0
        mGpuParamsDirty |= GPV_PER_OBJECT;
111
112
0
        bool useIdentityView = rend && rend->getUseIdentityView();
113
0
        if (mCurrentUseIdentityView != useIdentityView)
114
0
        {
115
0
            mCurrentUseIdentityView = useIdentityView;
116
0
            mViewMatrixDirty = true;
117
0
            mInverseViewMatrixDirty = true;
118
0
            mViewProjMatrixDirty = true;
119
0
            mGpuParamsDirty |= GPV_GLOBAL;
120
0
        }
121
122
0
        bool useIdentityProj = rend && rend->getUseIdentityProjection();
123
0
        if (mCurrentUseIdentityProj != useIdentityProj)
124
0
        {
125
0
            mCurrentUseIdentityProj = useIdentityProj;
126
0
            mProjMatrixDirty = true;
127
0
            mViewProjMatrixDirty = true;
128
0
            mGpuParamsDirty |= GPV_GLOBAL;
129
0
        }
130
131
0
        mCurrentRenderable = rend;
132
0
        mWorldMatrixDirty = true;
133
0
        mWorldViewMatrixDirty = true;
134
0
        mWorldViewProjMatrixDirty = true;
135
0
        mInverseWorldMatrixDirty = true;
136
0
        mInverseWorldViewMatrixDirty = true;
137
0
        mInverseTransposeWorldMatrixDirty = true;
138
0
        mInverseTransposeWorldViewMatrixDirty = true;
139
0
        mCameraPositionObjectSpaceDirty = true;
140
0
        mLodCameraPositionObjectSpaceDirty = true;
141
0
        for(size_t i = 0; i < OGRE_MAX_SIMULTANEOUS_LIGHTS; ++i)
142
0
        {
143
0
            mTextureWorldViewProjMatrixDirty[i] = true;
144
0
            mSpotlightWorldViewProjMatrixDirty[i] = true;
145
0
        }
146
147
0
    }
148
    //-----------------------------------------------------------------------------
149
    void AutoParamDataSource::setCurrentCamera(const Camera* cam, bool useCameraRelative)
150
0
    {
151
0
        mCurrentCamera = cam;
152
0
        mCameraRelativeRendering = useCameraRelative;
153
0
        mCameraRelativePosition = cam->getDerivedPosition();
154
0
        mViewMatrixDirty = true;
155
0
        mProjMatrixDirty = true;
156
0
        mWorldViewMatrixDirty = true;
157
0
        mViewProjMatrixDirty = true;
158
0
        mWorldViewProjMatrixDirty = true;
159
0
        mInverseViewMatrixDirty = true;
160
0
        mInverseWorldViewMatrixDirty = true;
161
0
        mInverseTransposeWorldViewMatrixDirty = true;
162
0
        mCameraPositionObjectSpaceDirty = true;
163
0
        mCameraPositionDirty = true;
164
0
        mLodCameraPositionObjectSpaceDirty = true;
165
0
        mLodCameraPositionDirty = true;
166
0
    }
167
    void AutoParamDataSource::setCameraArray(const std::vector<const Camera*> cameras)
168
0
    {
169
0
        mCameraArray = cameras;
170
0
    }
171
    //-----------------------------------------------------------------------------
172
    void AutoParamDataSource::setCurrentLightList(const LightList* ll)
173
0
    {
174
0
        static LightList NULL_LIGHTS;
175
0
        ll = ll ? ll : &NULL_LIGHTS;
176
177
0
        uint32 hash = FastHash((const char*)ll->data(), ll->size() * sizeof(Light*));
178
0
        if (hash == mLastLightHash)
179
0
            return;
180
181
0
        mLastLightHash = hash;
182
0
        mGpuParamsDirty |= GPV_LIGHTS;
183
0
        mCurrentLightList = ll;
184
185
0
        mLightPosViewSpaceArray.clear();
186
0
        mLightAttenuationArray.clear();
187
0
        mSpotlightParamsArray.clear();
188
0
        mLightDirViewSpaceArray.clear();
189
0
        mLightDiffuseColourPowerScaledArray.clear();
190
191
0
        for(size_t i = 0; i < ll->size() && i < OGRE_MAX_SIMULTANEOUS_LIGHTS; ++i)
192
0
        {
193
0
            mSpotlightViewProjMatrixDirty[i] = true;
194
0
            mSpotlightWorldViewProjMatrixDirty[i] = true;
195
0
        }
196
197
0
    }
198
    //---------------------------------------------------------------------
199
    float AutoParamDataSource::getLightNumber(size_t index) const
200
0
    {
201
0
        return static_cast<float>(getLight(index)._getIndexInFrame());
202
0
    }
203
    //-----------------------------------------------------------------------------
204
    const ColourValue& AutoParamDataSource::getLightDiffuseColour(size_t index) const
205
0
    {
206
0
        return getLight(index).getDiffuseColour();
207
0
    }
208
    //-----------------------------------------------------------------------------
209
    const ColourValue& AutoParamDataSource::getLightSpecularColour(size_t index) const
210
0
    {
211
0
        return getLight(index).getSpecularColour();
212
0
    }
213
    //-----------------------------------------------------------------------------
214
    const ColourValue AutoParamDataSource::getLightDiffuseColourWithPower(size_t index) const
215
0
    {
216
0
        const Light& l = getLight(index);
217
0
        ColourValue scaled(l.getDiffuseColour());
218
0
        Real power = l.getPowerScale();
219
        // scale, but not alpha
220
0
        scaled.r *= power;
221
0
        scaled.g *= power;
222
0
        scaled.b *= power;
223
0
        return scaled;
224
0
    }
225
    //-----------------------------------------------------------------------------
226
    const ColourValue AutoParamDataSource::getLightSpecularColourWithPower(size_t index) const
227
0
    {
228
0
        const Light& l = getLight(index);
229
0
        ColourValue scaled(l.getSpecularColour());
230
0
        Real power = l.getPowerScale();
231
        // scale, but not alpha
232
0
        scaled.r *= power;
233
0
        scaled.g *= power;
234
0
        scaled.b *= power;
235
0
        return scaled;
236
0
    }
237
    //-----------------------------------------------------------------------------
238
    Vector3 AutoParamDataSource::getLightPosition(size_t index) const
239
0
    {
240
0
        return getLight(index).getDerivedPosition(true);
241
0
    }
242
    //-----------------------------------------------------------------------------
243
    Vector4 AutoParamDataSource::getLightAs4DVector(size_t index) const
244
0
    {
245
0
        return getLight(index).getAs4DVector(true);
246
0
    }
247
    //-----------------------------------------------------------------------------
248
    Vector3 AutoParamDataSource::getLightDirection(size_t index) const
249
0
    {
250
0
        return getLight(index).getDerivedDirection();
251
0
    }
252
    //-----------------------------------------------------------------------------
253
    Real AutoParamDataSource::getLightPowerScale(size_t index) const
254
0
    {
255
0
        return getLight(index).getPowerScale();
256
0
    }
257
    //-----------------------------------------------------------------------------
258
    Vector4f AutoParamDataSource::getLightAttenuation(size_t index) const
259
0
    {
260
0
        const Light& l = getLight(index);
261
0
        if(l.getType() == Light::LT_RECTLIGHT)
262
0
        {
263
0
            auto rot = getViewMatrix().linear();
264
0
            return Vector4f(Vector3f(rot * Vector3(l.getDerivedSourceHalfHeight())), 0.0);
265
0
        }
266
        // range, const, linear, quad
267
0
        return l.getAttenuation();
268
0
    }
269
    //-----------------------------------------------------------------------------
270
    Vector4f AutoParamDataSource::getSpotlightParams(size_t index) const
271
0
    {
272
        // inner, outer, fallof, isSpot
273
0
        const Light& l = getLight(index);
274
0
        if (l.getType() == Light::LT_SPOTLIGHT)
275
0
        {
276
0
            return Vector4f(Math::Cos(l.getSpotlightInnerAngle().valueRadians() * 0.5f),
277
0
                           Math::Cos(l.getSpotlightOuterAngle().valueRadians() * 0.5f),
278
0
                           l.getSpotlightFalloff(),
279
0
                           1.0);
280
0
        }
281
0
        else if(l.getType() == Light::LT_RECTLIGHT)
282
0
        {
283
0
            auto rot = getViewMatrix().linear();
284
0
            return Vector4f(Vector3f(rot * Vector3(l.getDerivedSourceHalfWidth())), 2.0);
285
0
        }
286
0
        else
287
0
        {
288
            // Use safe values which result in no change to point & dir light calcs
289
            // The spot factor applied to the usual lighting calc is 
290
            // pow((dot(spotDir, lightDir) - y) / (x - y), z)
291
            // Therefore if we set z to 0.0f then the factor will always be 1
292
            // since pow(anything, 0) == 1
293
            // However we also need to ensure we don't overflow because of the division
294
            // therefore set x = 1 and y = 0 so divisor doesn't change scale
295
0
            return Vector4f(1.0, 0.0, 0.0, 0.0); // since the main op is pow(.., vec4.z), this will result in 1.0
296
0
        }
297
0
    }
298
    const Vector4f* AutoParamDataSource::getLightPositionViewSpaceArray(size_t size) const
299
0
    {
300
0
        if (size > mLightPosViewSpaceArray.size())
301
0
        {
302
0
            getViewMatrix(); // refresh view matrix
303
0
            mLightPosViewSpaceArray.resize(size);
304
0
            for (size_t i = 0; i < size; ++i)
305
0
            {
306
0
                mLightPosViewSpaceArray[i] = Vector4f(mViewMatrix * getLightAs4DVector(i));
307
0
            }
308
0
        }
309
310
0
        return mLightPosViewSpaceArray.data();
311
0
    }
312
    const Vector4f* AutoParamDataSource::getLightAttenuationArray(size_t size) const
313
0
    {
314
0
        if (size > mLightAttenuationArray.size())
315
0
        {
316
0
            mLightAttenuationArray.resize(size);
317
0
            for (size_t i = 0; i < size; ++i)
318
0
            {
319
0
                mLightAttenuationArray[i] = getLightAttenuation(i);
320
0
            }
321
0
        }
322
323
0
        return mLightAttenuationArray.data();
324
0
    }
325
    const Vector4f* AutoParamDataSource::getSpotlightParamsArray(size_t size) const
326
0
    {
327
0
        if (size > mSpotlightParamsArray.size())
328
0
        {
329
0
            mSpotlightParamsArray.resize(size);
330
0
            for (size_t i = 0; i < size; ++i)
331
0
            {
332
0
                mSpotlightParamsArray[i] = getSpotlightParams(i);
333
0
            }
334
0
        }
335
336
0
        return mSpotlightParamsArray.data();
337
0
    }
338
    const Vector4f* AutoParamDataSource::getLightDirectionViewSpaceArray(size_t size) const
339
0
    {
340
0
        if (size > mLightDirViewSpaceArray.size())
341
0
        {
342
0
            auto invTransViewMatrix = getInverseTransposeViewMatrix().linear();
343
0
            mLightDirViewSpaceArray.resize(size);
344
0
            for (size_t i = 0; i < size; ++i)
345
0
            {
346
0
                Vector3 dirView = invTransViewMatrix * getLightDirection(i);
347
0
                mLightDirViewSpaceArray[i] = Vector4f(dirView.x, dirView.y, dirView.z, 0.0f);
348
0
            }
349
0
        }
350
351
0
        return mLightDirViewSpaceArray.data();
352
0
    }
353
    const ColourValue* AutoParamDataSource::getLightDiffuseColourPowerScaledArray(size_t size) const
354
0
    {
355
0
        if (size > mLightDiffuseColourPowerScaledArray.size())
356
0
        {
357
0
            mLightDiffuseColourPowerScaledArray.resize(size);
358
0
            for (size_t i = 0; i < size; ++i)
359
0
            {
360
0
                mLightDiffuseColourPowerScaledArray[i] = getLightDiffuseColourWithPower(i);
361
0
            }
362
0
        }
363
364
0
        return mLightDiffuseColourPowerScaledArray.data();
365
0
    }
366
    //-----------------------------------------------------------------------------
367
    void AutoParamDataSource::setMainCamBoundsInfo(VisibleObjectsBoundsInfo* info)
368
0
    {
369
0
        mMainCamBoundsInfo = info;
370
0
        mSceneDepthRangeDirty = true;
371
0
    }
372
    //-----------------------------------------------------------------------------
373
    void AutoParamDataSource::setCurrentSceneManager(const SceneManager* sm)
374
0
    {
375
0
        mCurrentSceneManager = sm;
376
0
    }
377
    //-----------------------------------------------------------------------------
378
    void AutoParamDataSource::setWorldMatrices(const Affine3* m, size_t count)
379
0
    {
380
0
        mWorldMatrixArray = m;
381
0
        mWorldMatrixCount = count;
382
0
        mWorldMatrixDirty = false;
383
0
    }
384
    //-----------------------------------------------------------------------------
385
    const Affine3& AutoParamDataSource::getWorldMatrix(void) const
386
0
    {
387
0
        if (mWorldMatrixDirty)
388
0
        {
389
0
            mWorldMatrixArray = mWorldMatrix;
390
0
            mCurrentRenderable->getWorldTransforms(reinterpret_cast<Matrix4*>(mWorldMatrix));
391
0
            mWorldMatrixCount = mCurrentRenderable->getNumWorldTransforms();
392
0
            if (mCameraRelativeRendering && !mCurrentRenderable->getUseIdentityView())
393
0
            {
394
0
                size_t worldMatrixCount = MeshManager::getBonesUseObjectSpace() ? 1 : mWorldMatrixCount;
395
0
                for (size_t i = 0; i < worldMatrixCount; ++i)
396
0
                {
397
0
                    mWorldMatrix[i].setTrans(mWorldMatrix[i].getTrans() - mCameraRelativePosition);
398
0
                }
399
0
            }
400
0
            mWorldMatrixDirty = false;
401
0
        }
402
0
        return mWorldMatrixArray[0];
403
0
    }
404
    //-----------------------------------------------------------------------------
405
    size_t AutoParamDataSource::getBoneMatrixCount(void) const
406
0
    {
407
        // trigger derivation
408
0
        getWorldMatrix();
409
0
        return mWorldMatrixCount == 1 ? 1 : mWorldMatrixCount - int(MeshManager::getBonesUseObjectSpace());
410
0
    }
411
    //-----------------------------------------------------------------------------
412
    const Affine3* AutoParamDataSource::getBoneMatrixArray(void) const
413
0
    {
414
        // trigger derivation
415
0
        getWorldMatrix();
416
0
        return mWorldMatrixArray + int(MeshManager::getBonesUseObjectSpace());
417
0
    }
418
    //-----------------------------------------------------------------------------
419
    Affine3 AutoParamDataSource::getViewMatrix(const Camera* cam) const
420
0
    {
421
0
        Affine3 view;
422
0
        if (mCurrentUseIdentityView)
423
0
            view = Affine3::IDENTITY;
424
0
        else
425
0
        {
426
0
            view = cam->getViewMatrix(true);
427
0
            if (mCameraRelativeRendering)
428
0
            {
429
0
                view.setTrans(Vector3::ZERO);
430
0
            }
431
0
        }
432
0
        return view;
433
0
    }
434
    const Affine3& AutoParamDataSource::getViewMatrix(void) const
435
0
    {
436
0
        if (mViewMatrixDirty)
437
0
        {
438
0
            mViewMatrix = getViewMatrix(mCurrentCamera);
439
0
            mViewMatrixDirty = false;
440
0
        }
441
0
        return mViewMatrix;
442
0
    }
443
    //-----------------------------------------------------------------------------
444
    const Matrix4& AutoParamDataSource::getViewProjectionMatrix(void) const
445
0
    {
446
0
        if (mViewProjMatrixDirty)
447
0
        {
448
0
            mViewProjMatrix = getProjectionMatrix() * getViewMatrix();
449
0
            mViewProjMatrixDirty = false;
450
0
        }
451
0
        return mViewProjMatrix;
452
0
    }
453
    //-----------------------------------------------------------------------------
454
    Matrix4 AutoParamDataSource::getProjectionMatrix(const Camera* cam) const
455
0
    {
456
0
        Matrix4 proj;
457
458
        // NB use API-independent projection matrix since GPU programs
459
        // bypass the API-specific handedness and use right-handed coords
460
0
        if (mCurrentUseIdentityProj)
461
0
        {
462
            // Use identity projection matrix, still need to take RS depth into account.
463
0
            RenderSystem* rs = Root::getSingleton().getRenderSystem();
464
0
            rs->_convertProjectionMatrix(Matrix4::IDENTITY, proj, true);
465
0
        }
466
0
        else
467
0
        {
468
0
            proj = cam->getProjectionMatrixWithRSDepth();
469
0
        }
470
471
0
        if (mCurrentRenderTarget && mCurrentRenderTarget->requiresTextureFlipping())
472
0
        {
473
            // Because we're not using setProjectionMatrix, this needs to be done here
474
            // Invert transformed y
475
0
            proj[1][0] = -proj[1][0];
476
0
            proj[1][1] = -proj[1][1];
477
0
            proj[1][2] = -proj[1][2];
478
0
            proj[1][3] = -proj[1][3];
479
0
        }
480
481
0
        return proj;
482
0
    }
483
    const Matrix4& AutoParamDataSource::getProjectionMatrix(void) const
484
0
    {
485
0
        if (mProjMatrixDirty)
486
0
        {
487
0
            mProjectionMatrix = getProjectionMatrix(mCurrentCamera);
488
0
            mProjMatrixDirty = false;
489
0
        }
490
0
        return mProjectionMatrix;
491
0
    }
492
    //-----------------------------------------------------------------------------
493
    const Affine3& AutoParamDataSource::getWorldViewMatrix(void) const
494
0
    {
495
0
        if (mWorldViewMatrixDirty)
496
0
        {
497
0
            mWorldViewMatrix = getViewMatrix() * getWorldMatrix();
498
0
            mWorldViewMatrixDirty = false;
499
0
        }
500
0
        return mWorldViewMatrix;
501
0
    }
502
    //-----------------------------------------------------------------------------
503
    const Matrix4& AutoParamDataSource::getWorldViewProjMatrix(void) const
504
0
    {
505
0
        if (mWorldViewProjMatrixDirty)
506
0
        {
507
0
            mWorldViewProjMatrix = getProjectionMatrix() * getWorldViewMatrix();
508
0
            mWorldViewProjMatrixDirty = false;
509
0
        }
510
0
        return mWorldViewProjMatrix;
511
0
    }
512
    Matrix4 AutoParamDataSource::getWorldViewProjMatrix(size_t index) const
513
0
    {
514
0
        if (index >= mCameraArray.size())
515
0
        {
516
0
            return Matrix4::IDENTITY;
517
0
        }
518
519
        // dont bother caching this, as it invalidates per object
520
0
        const auto& projectionMatrix = getProjectionMatrix(mCameraArray[index]);
521
0
        const auto& viewMatrix = getViewMatrix(mCameraArray[index]);
522
0
        return projectionMatrix * viewMatrix * getWorldMatrix();
523
0
    }
524
    //-----------------------------------------------------------------------------
525
    const Affine3& AutoParamDataSource::getInverseWorldMatrix(void) const
526
0
    {
527
0
        if (mInverseWorldMatrixDirty)
528
0
        {
529
0
            mInverseWorldMatrix = getWorldMatrix().inverse();
530
0
            mInverseWorldMatrixDirty = false;
531
0
        }
532
0
        return mInverseWorldMatrix;
533
0
    }
534
    //-----------------------------------------------------------------------------
535
    const Affine3& AutoParamDataSource::getInverseWorldViewMatrix(void) const
536
0
    {
537
0
        if (mInverseWorldViewMatrixDirty)
538
0
        {
539
0
            mInverseWorldViewMatrix = getWorldViewMatrix().inverse();
540
0
            mInverseWorldViewMatrixDirty = false;
541
0
        }
542
0
        return mInverseWorldViewMatrix;
543
0
    }
544
    //-----------------------------------------------------------------------------
545
    const Affine3& AutoParamDataSource::getInverseViewMatrix(void) const
546
0
    {
547
0
        if (mInverseViewMatrixDirty)
548
0
        {
549
0
            mInverseViewMatrix = getViewMatrix().inverse();
550
0
            mInverseViewMatrixDirty = false;
551
0
        }
552
0
        return mInverseViewMatrix;
553
0
    }
554
    //-----------------------------------------------------------------------------
555
    const Matrix4& AutoParamDataSource::getInverseTransposeWorldMatrix(void) const
556
0
    {
557
0
        if (mInverseTransposeWorldMatrixDirty)
558
0
        {
559
0
            mInverseTransposeWorldMatrix = getInverseWorldMatrix().transpose();
560
0
            mInverseTransposeWorldMatrixDirty = false;
561
0
        }
562
0
        return mInverseTransposeWorldMatrix;
563
0
    }
564
    //-----------------------------------------------------------------------------
565
    const Matrix4& AutoParamDataSource::getInverseTransposeWorldViewMatrix(void) const
566
0
    {
567
0
        if (mInverseTransposeWorldViewMatrixDirty)
568
0
        {
569
0
            mInverseTransposeWorldViewMatrix = getInverseWorldViewMatrix().transpose();
570
0
            mInverseTransposeWorldViewMatrixDirty = false;
571
0
        }
572
0
        return mInverseTransposeWorldViewMatrix;
573
0
    }
574
    //-----------------------------------------------------------------------------
575
    const Vector4& AutoParamDataSource::getCameraPosition(void) const
576
0
    {
577
0
        if(mCameraPositionDirty)
578
0
        {
579
0
            Vector3 vec3 = mCurrentCamera->getDerivedPosition();
580
0
            if (mCameraRelativeRendering)
581
0
            {
582
0
                vec3 -= mCameraRelativePosition;
583
0
            }
584
0
            mCameraPosition[0] = vec3[0];
585
0
            mCameraPosition[1] = vec3[1];
586
0
            mCameraPosition[2] = vec3[2];
587
0
            mCameraPosition[3] = 1.0;
588
0
            mCameraPositionDirty = false;
589
0
        }
590
0
        return mCameraPosition;
591
0
    }    
592
    //-----------------------------------------------------------------------------
593
    const Vector4& AutoParamDataSource::getCameraPositionObjectSpace(void) const
594
0
    {
595
0
        if (mCameraPositionObjectSpaceDirty)
596
0
        {
597
0
            if (mCameraRelativeRendering)
598
0
            {
599
0
                mCameraPositionObjectSpace = Vector4(getInverseWorldMatrix() * Vector3::ZERO);
600
0
            }
601
0
            else
602
0
            {
603
0
                mCameraPositionObjectSpace =
604
0
                    Vector4(getInverseWorldMatrix() * mCurrentCamera->getDerivedPosition());
605
0
            }
606
0
            mCameraPositionObjectSpaceDirty = false;
607
0
        }
608
0
        return mCameraPositionObjectSpace;
609
0
    }
610
    //-----------------------------------------------------------------------------
611
    const Vector4 AutoParamDataSource::getCameraRelativePosition (void) const
612
0
    {
613
0
        return Ogre::Vector4 (mCameraRelativePosition.x, mCameraRelativePosition.y, mCameraRelativePosition.z, 1);
614
0
    }
615
    //-----------------------------------------------------------------------------
616
    const Vector4& AutoParamDataSource::getLodCameraPosition(void) const
617
0
    {
618
0
        if(mLodCameraPositionDirty)
619
0
        {
620
0
            Vector3 vec3 = mCurrentCamera->getLodCamera()->getDerivedPosition();
621
0
            if (mCameraRelativeRendering)
622
0
            {
623
0
                vec3 -= mCameraRelativePosition;
624
0
            }
625
0
            mLodCameraPosition[0] = vec3[0];
626
0
            mLodCameraPosition[1] = vec3[1];
627
0
            mLodCameraPosition[2] = vec3[2];
628
0
            mLodCameraPosition[3] = 1.0;
629
0
            mLodCameraPositionDirty = false;
630
0
        }
631
0
        return mLodCameraPosition;
632
0
    }
633
    //-----------------------------------------------------------------------------
634
    const Vector4& AutoParamDataSource::getLodCameraPositionObjectSpace(void) const
635
0
    {
636
0
        if (mLodCameraPositionObjectSpaceDirty)
637
0
        {
638
0
            if (mCameraRelativeRendering)
639
0
            {
640
0
                mLodCameraPositionObjectSpace =
641
0
                    Vector4(getInverseWorldMatrix() *
642
0
                            (mCurrentCamera->getLodCamera()->getDerivedPosition() -
643
0
                             mCameraRelativePosition));
644
0
            }
645
0
            else
646
0
            {
647
0
                mLodCameraPositionObjectSpace =
648
0
                    Vector4(getInverseWorldMatrix() *
649
0
                            (mCurrentCamera->getLodCamera()->getDerivedPosition()));
650
0
            }
651
0
            mLodCameraPositionObjectSpaceDirty = false;
652
0
        }
653
0
        return mLodCameraPositionObjectSpace;
654
0
    }
655
    //-----------------------------------------------------------------------------
656
    void AutoParamDataSource::setAmbientLightColour(const ColourValue& ambient)
657
0
    {
658
0
        mGpuParamsDirty |= GPV_GLOBAL;
659
0
        mAmbientLight = ambient;
660
0
    }
661
    //---------------------------------------------------------------------
662
    float AutoParamDataSource::getLightCount() const
663
0
    {
664
0
        return static_cast<float>(mCurrentLightList->size());
665
0
    }
666
    //---------------------------------------------------------------------
667
    float AutoParamDataSource::getLightCastsShadows(size_t index) const
668
0
    {
669
0
        return getLight(index).getCastShadows() ? 1.0f : 0.0f;
670
0
    }
671
    //-----------------------------------------------------------------------------
672
    const ColourValue& AutoParamDataSource::getAmbientLightColour(void) const
673
0
    {
674
0
        return mAmbientLight;
675
        
676
0
    }
677
    //-----------------------------------------------------------------------------
678
    void AutoParamDataSource::setCurrentPass(const Pass* pass)
679
0
    {
680
0
        mGpuParamsDirty |= GPV_GLOBAL;
681
0
        mCurrentPass = pass;
682
0
    }
683
    //-----------------------------------------------------------------------------
684
    const Pass* AutoParamDataSource::getCurrentPass(void) const
685
0
    {
686
0
        return mCurrentPass;
687
0
    }
688
    //-----------------------------------------------------------------------------
689
    Vector4f AutoParamDataSource::getTextureSize(size_t index) const
690
0
    {
691
0
        Vector4f size = Vector4f(1,1,1,1);
692
693
0
        if (index < mCurrentPass->getNumTextureUnitStates())
694
0
        {
695
0
            const TexturePtr& tex = mCurrentPass->getTextureUnitState(
696
0
                static_cast<unsigned short>(index))->_getTexturePtr();
697
0
            if (tex)
698
0
            {
699
0
                size[0] = static_cast<float>(tex->getWidth());
700
0
                size[1] = static_cast<float>(tex->getHeight());
701
0
                size[2] = static_cast<float>(tex->getDepth());
702
0
                size[3] = static_cast<float>(tex->getNumMipmaps());
703
0
            }
704
0
        }
705
706
0
        return size;
707
0
    }
708
    //-----------------------------------------------------------------------------
709
    Vector4f AutoParamDataSource::getInverseTextureSize(size_t index) const
710
0
    {
711
0
        Vector4f size = getTextureSize(index);
712
0
        return 1 / size;
713
0
    }
714
    //-----------------------------------------------------------------------------
715
    Vector4f AutoParamDataSource::getPackedTextureSize(size_t index) const
716
0
    {
717
0
        Vector4f size = getTextureSize(index);
718
0
        return Vector4f(size[0], size[1], 1 / size[0], 1 / size[1]);
719
0
    }
720
    //-----------------------------------------------------------------------------
721
    const ColourValue& AutoParamDataSource::getSurfaceAmbientColour(void) const
722
0
    {
723
0
        return mCurrentPass->getAmbient();
724
0
    }
725
    //-----------------------------------------------------------------------------
726
    const ColourValue& AutoParamDataSource::getSurfaceDiffuseColour(void) const
727
0
    {
728
0
        return mCurrentPass->getDiffuse();
729
0
    }
730
    //-----------------------------------------------------------------------------
731
    const ColourValue& AutoParamDataSource::getSurfaceSpecularColour(void) const
732
0
    {
733
0
        return mCurrentPass->getSpecular();
734
0
    }
735
    //-----------------------------------------------------------------------------
736
    const ColourValue& AutoParamDataSource::getSurfaceEmissiveColour(void) const
737
0
    {
738
0
        return mCurrentPass->getSelfIllumination();
739
0
    }
740
    //-----------------------------------------------------------------------------
741
    Real AutoParamDataSource::getSurfaceShininess(void) const
742
0
    {
743
0
        return mCurrentPass->getShininess();
744
0
    }
745
    //-----------------------------------------------------------------------------
746
    Real AutoParamDataSource::getSurfaceAlphaRejectionValue(void) const
747
0
    {
748
0
        return static_cast<Real>(static_cast<unsigned int>(mCurrentPass->getAlphaRejectValue())) / 255.0f;
749
0
    }
750
    //-----------------------------------------------------------------------------
751
    ColourValue AutoParamDataSource::getDerivedAmbientLightColour(void) const
752
0
    {
753
0
        auto result = getAmbientLightColour() * getSurfaceAmbientColour();
754
0
        result.a = getSurfaceDiffuseColour().a;
755
0
        return result;
756
0
    }
757
    //-----------------------------------------------------------------------------
758
    ColourValue AutoParamDataSource::getDerivedSceneColour(void) const
759
0
    {
760
0
        ColourValue result = getDerivedAmbientLightColour() + getSurfaceEmissiveColour();
761
0
        result.a = getSurfaceDiffuseColour().a;
762
0
        return result;
763
0
    }
764
    //-----------------------------------------------------------------------------
765
    void AutoParamDataSource::setFog(FogMode mode, const ColourValue& colour,
766
        Real expDensity, Real linearStart, Real linearEnd)
767
0
    {
768
0
        (void)mode; // ignored
769
0
        mFogColour = colour;
770
0
        mFogParams[0] = expDensity;
771
0
        mFogParams[1] = linearStart;
772
0
        mFogParams[2] = linearEnd;
773
0
        mFogParams[3] = linearEnd != linearStart ? 1 / (linearEnd - linearStart) : 0;
774
0
    }
775
    //-----------------------------------------------------------------------------
776
    const ColourValue& AutoParamDataSource::getFogColour(void) const
777
0
    {
778
0
        return mFogColour;
779
0
    }
780
    //-----------------------------------------------------------------------------
781
    const Vector4f& AutoParamDataSource::getFogParams(void) const
782
0
    {
783
0
        return mFogParams;
784
0
    }
785
786
    void AutoParamDataSource::setPointParameters(bool attenuation, const Vector4f& params)
787
0
    {
788
0
        mPointParams = params;
789
0
        if(attenuation)
790
0
            mPointParams[0] *= getViewportHeight();
791
0
    }
792
793
    const Vector4f& AutoParamDataSource::getPointParams() const
794
0
    {
795
0
        return mPointParams;
796
0
    }
797
    //-----------------------------------------------------------------------------
798
    void AutoParamDataSource::setTextureProjector(const Frustum* frust, size_t index = 0)
799
0
    {
800
0
        if (index < OGRE_MAX_SIMULTANEOUS_LIGHTS)
801
0
        {
802
0
            mCurrentTextureProjector[index] = frust;
803
0
            mTextureViewProjMatrixDirty[index] = true;
804
0
            mTextureWorldViewProjMatrixDirty[index] = true;
805
0
            mShadowCamDepthRangesDirty[index] = true;
806
0
        }
807
808
0
    }
809
    //-----------------------------------------------------------------------------
810
    const Matrix4& AutoParamDataSource::getTextureViewProjMatrix(size_t index) const
811
0
    {
812
0
        if (index < OGRE_MAX_SIMULTANEOUS_LIGHTS && mCurrentTextureProjector[index])
813
0
        {
814
0
            if (mTextureViewProjMatrixDirty[index])
815
0
            {
816
0
                if (mCameraRelativeRendering)
817
0
                {
818
                    // World positions are now going to be relative to the camera position
819
                    // so we need to alter the projector view matrix to compensate
820
0
                    Matrix4 viewMatrix;
821
0
                    mCurrentTextureProjector[index]->calcViewMatrixRelative(
822
0
                        mCurrentCamera->getDerivedPosition(), viewMatrix);
823
0
                    mTextureViewProjMatrix[index] = 
824
0
                        Matrix4::CLIPSPACE2DTOIMAGESPACE *
825
0
                        mCurrentTextureProjector[index]->getProjectionMatrixWithRSDepth() * 
826
0
                        viewMatrix;
827
0
                }
828
0
                else
829
0
                {
830
0
                    mTextureViewProjMatrix[index] = 
831
0
                        Matrix4::CLIPSPACE2DTOIMAGESPACE *
832
0
                        mCurrentTextureProjector[index]->getProjectionMatrixWithRSDepth() * 
833
0
                        mCurrentTextureProjector[index]->Frustum::getViewMatrix();
834
0
                }
835
0
                mTextureViewProjMatrixDirty[index] = false;
836
0
            }
837
0
            return mTextureViewProjMatrix[index];
838
0
        }
839
0
        else
840
0
            return Matrix4::IDENTITY;
841
0
    }
842
    //-----------------------------------------------------------------------------
843
    const Matrix4& AutoParamDataSource::getTextureWorldViewProjMatrix(size_t index) const
844
0
    {
845
0
        if (index < OGRE_MAX_SIMULTANEOUS_LIGHTS && mCurrentTextureProjector[index])
846
0
        {
847
0
            if (mTextureWorldViewProjMatrixDirty[index])
848
0
            {
849
0
                mTextureWorldViewProjMatrix[index] = 
850
0
                    getTextureViewProjMatrix(index) * getWorldMatrix();
851
0
                mTextureWorldViewProjMatrixDirty[index] = false;
852
0
            }
853
0
            return mTextureWorldViewProjMatrix[index];
854
0
        }
855
0
        else
856
0
            return Matrix4::IDENTITY;
857
0
    }
858
    //-----------------------------------------------------------------------------
859
    const Matrix4& AutoParamDataSource::getSpotlightViewProjMatrix(size_t index) const
860
0
    {
861
0
        if (index < OGRE_MAX_SIMULTANEOUS_LIGHTS)
862
0
        {
863
0
            const Light& l = getLight(index);
864
865
0
            if (&l != &mBlankLight && 
866
0
                l.getType() == Light::LT_SPOTLIGHT &&
867
0
                mSpotlightViewProjMatrixDirty[index])
868
0
            {
869
0
                Frustum frust;
870
0
                SceneNode dummyNode(0);
871
0
                dummyNode.attachObject(&frust);
872
873
0
                frust.setProjectionType(PT_PERSPECTIVE);
874
0
                frust.setFOVy(l.getSpotlightOuterAngle());
875
0
                frust.setAspectRatio(1.0f);
876
                // set near clip the same as main camera, since they are likely
877
                // to both reflect the nature of the scene
878
0
                frust.setNearClipDistance(mCurrentCamera->getNearClipDistance());
879
                // Calculate position, which same as spotlight position, in camera-relative coords if required
880
0
                dummyNode.setPosition(l.getDerivedPosition(true));
881
                // Calculate direction, which same as spotlight direction
882
0
                Vector3 dir = - l.getDerivedDirection(); // backwards since point down -z
883
0
                dir.normalise();
884
0
                Vector3 up = Vector3::UNIT_Y;
885
                // Check it's not coincident with dir
886
0
                if (Math::Abs(up.dotProduct(dir)) >= 1.0f)
887
0
                {
888
                    // Use camera up
889
0
                    up = Vector3::UNIT_Z;
890
0
                }
891
0
                dummyNode.setOrientation(Math::lookRotation(dir, up));
892
893
                // The view matrix here already includes camera-relative changes if necessary
894
                // since they are built into the frustum position
895
0
                mSpotlightViewProjMatrix[index] = 
896
0
                    Matrix4::CLIPSPACE2DTOIMAGESPACE *
897
0
                    frust.getProjectionMatrixWithRSDepth() * 
898
0
                    frust.getViewMatrix();
899
900
0
                mSpotlightViewProjMatrixDirty[index] = false;
901
0
            }
902
0
            return mSpotlightViewProjMatrix[index];
903
0
        }
904
0
        else
905
0
            return Matrix4::IDENTITY;
906
0
    }
907
    //-----------------------------------------------------------------------------
908
    const Matrix4& AutoParamDataSource::getSpotlightWorldViewProjMatrix(size_t index) const
909
0
    {
910
0
        if (index < OGRE_MAX_SIMULTANEOUS_LIGHTS)
911
0
        {
912
0
            const Light& l = getLight(index);
913
914
0
            if (&l != &mBlankLight && 
915
0
                l.getType() == Light::LT_SPOTLIGHT &&
916
0
                mSpotlightWorldViewProjMatrixDirty[index])
917
0
            {
918
0
                mSpotlightWorldViewProjMatrix[index] = 
919
0
                    getSpotlightViewProjMatrix(index) * getWorldMatrix();
920
0
                mSpotlightWorldViewProjMatrixDirty[index] = false;
921
0
            }
922
0
            return mSpotlightWorldViewProjMatrix[index];
923
0
        }
924
0
        else
925
0
            return Matrix4::IDENTITY;
926
0
    }
927
//-----------------------------------------------------------------------------
928
  const Matrix4& AutoParamDataSource::getTextureTransformMatrix(size_t index) const
929
0
  {
930
    // make sure the current pass is set
931
0
    assert(mCurrentPass && "current pass is NULL!");
932
    // check if there is a texture unit with the given index in the current pass
933
0
    if(index < mCurrentPass->getNumTextureUnitStates())
934
0
    {
935
      // texture unit existent, return its currently set transform
936
0
      return mCurrentPass->getTextureUnitState(static_cast<unsigned short>(index))->getTextureTransform();
937
0
    }
938
0
    else
939
0
    {
940
      // no such texture unit, return unity
941
0
      return Matrix4::IDENTITY;
942
0
    }
943
0
  }
944
    //-----------------------------------------------------------------------------
945
    void AutoParamDataSource::setCurrentRenderTarget(const RenderTarget* target)
946
0
    {
947
0
        mCurrentRenderTarget = target;
948
0
    }
949
    //-----------------------------------------------------------------------------
950
    const RenderTarget* AutoParamDataSource::getCurrentRenderTarget(void) const
951
0
    {
952
0
        return mCurrentRenderTarget;
953
0
    }
954
    //-----------------------------------------------------------------------------
955
    void AutoParamDataSource::setCurrentViewport(const Viewport* viewport)
956
0
    {
957
0
        mCurrentViewport = viewport;
958
0
    }
959
    //-----------------------------------------------------------------------------
960
    void AutoParamDataSource::setShadowDirLightExtrusionDistance(Real dist)
961
0
    {
962
0
        mDirLightExtrusionDistance = dist;
963
0
    }
964
    //-----------------------------------------------------------------------------
965
    void AutoParamDataSource::setShadowPointLightExtrusionDistance(Real dist)
966
0
    {
967
0
        mPointLightExtrusionDistance = dist;
968
0
    }
969
    //-----------------------------------------------------------------------------
970
    Real AutoParamDataSource::getShadowExtrusionDistance(void) const
971
0
    {
972
0
        const Light& l = getLight(0); // only ever applies to one light at once
973
0
        return (l.getType() == Light::LT_DIRECTIONAL) ?
974
0
            mDirLightExtrusionDistance : mPointLightExtrusionDistance;
975
0
    }
976
    //-----------------------------------------------------------------------------
977
    const Renderable* AutoParamDataSource::getCurrentRenderable(void) const
978
0
    {
979
0
        return mCurrentRenderable;
980
0
    }
981
    //-----------------------------------------------------------------------------
982
    Matrix4 AutoParamDataSource::getInverseViewProjMatrix(void) const
983
0
    {
984
0
        return this->getViewProjectionMatrix().inverse();
985
0
    }
986
    //-----------------------------------------------------------------------------
987
    Matrix4 AutoParamDataSource::getInverseTransposeViewProjMatrix(void) const
988
0
    {
989
0
        return this->getInverseViewProjMatrix().transpose();
990
0
    }
991
    //-----------------------------------------------------------------------------
992
    Matrix4 AutoParamDataSource::getTransposeViewProjMatrix(void) const
993
0
    {
994
0
        return this->getViewProjectionMatrix().transpose();
995
0
    }
996
    //-----------------------------------------------------------------------------
997
    Matrix4 AutoParamDataSource::getTransposeViewMatrix(void) const
998
0
    {
999
0
        return this->getViewMatrix().transpose();
1000
0
    }
1001
    //-----------------------------------------------------------------------------
1002
    Matrix4 AutoParamDataSource::getInverseTransposeViewMatrix(void) const
1003
0
    {
1004
0
        return this->getInverseViewMatrix().transpose();
1005
0
    }
1006
    //-----------------------------------------------------------------------------
1007
    Matrix4 AutoParamDataSource::getTransposeProjectionMatrix(void) const
1008
0
    {
1009
0
        return this->getProjectionMatrix().transpose();
1010
0
    }
1011
    //-----------------------------------------------------------------------------
1012
    Matrix4 AutoParamDataSource::getInverseProjectionMatrix(void) const 
1013
0
    {
1014
0
        return this->getProjectionMatrix().inverse();
1015
0
    }
1016
    //-----------------------------------------------------------------------------
1017
    Matrix4 AutoParamDataSource::getInverseTransposeProjectionMatrix(void) const
1018
0
    {
1019
0
        return this->getInverseProjectionMatrix().transpose();
1020
0
    }
1021
    //-----------------------------------------------------------------------------
1022
    Matrix4 AutoParamDataSource::getTransposeWorldViewProjMatrix(void) const
1023
0
    {
1024
0
        return this->getWorldViewProjMatrix().transpose();
1025
0
    }
1026
    //-----------------------------------------------------------------------------
1027
    Matrix4 AutoParamDataSource::getInverseWorldViewProjMatrix(void) const
1028
0
    {
1029
0
        return this->getWorldViewProjMatrix().inverse();
1030
0
    }
1031
    //-----------------------------------------------------------------------------
1032
    Matrix4 AutoParamDataSource::getInverseTransposeWorldViewProjMatrix(void) const
1033
0
    {
1034
0
        return this->getInverseWorldViewProjMatrix().transpose();
1035
0
    }
1036
    //-----------------------------------------------------------------------------
1037
    Matrix4 AutoParamDataSource::getTransposeWorldViewMatrix(void) const
1038
0
    {
1039
0
        return this->getWorldViewMatrix().transpose();
1040
0
    }
1041
    //-----------------------------------------------------------------------------
1042
    Matrix4 AutoParamDataSource::getTransposeWorldMatrix(void) const
1043
0
    {
1044
0
        return this->getWorldMatrix().transpose();
1045
0
    }
1046
    //-----------------------------------------------------------------------------
1047
    Real AutoParamDataSource::getTime(void) const
1048
0
    {
1049
0
        return ControllerManager::getSingleton().getElapsedTime();
1050
0
    }
1051
    //-----------------------------------------------------------------------------
1052
    Real AutoParamDataSource::getTime_0_X(Real x) const
1053
0
    {
1054
0
        return std::fmod(this->getTime(), x);
1055
0
    }
1056
    //-----------------------------------------------------------------------------
1057
    Real AutoParamDataSource::getCosTime_0_X(Real x) const
1058
0
    { 
1059
0
        return std::cos(this->getTime_0_X(x));
1060
0
    }
1061
    //-----------------------------------------------------------------------------
1062
    Real AutoParamDataSource::getSinTime_0_X(Real x) const
1063
0
    { 
1064
0
        return std::sin(this->getTime_0_X(x));
1065
0
    }
1066
    //-----------------------------------------------------------------------------
1067
    Real AutoParamDataSource::getTanTime_0_X(Real x) const
1068
0
    { 
1069
0
        return std::tan(this->getTime_0_X(x));
1070
0
    }
1071
    //-----------------------------------------------------------------------------
1072
    Vector4f AutoParamDataSource::getTime_0_X_packed(Real x) const
1073
0
    {
1074
0
        float t = this->getTime_0_X(x);
1075
0
        return Vector4f(t, std::sin(t), std::cos(t), std::tan(t));
1076
0
    }
1077
    //-----------------------------------------------------------------------------
1078
    Real AutoParamDataSource::getTime_0_1(Real x) const
1079
0
    { 
1080
0
        return this->getTime_0_X(x)/x; 
1081
0
    }
1082
    //-----------------------------------------------------------------------------
1083
    Real AutoParamDataSource::getCosTime_0_1(Real x) const
1084
0
    { 
1085
0
        return std::cos(this->getTime_0_1(x));
1086
0
    }
1087
    //-----------------------------------------------------------------------------
1088
    Real AutoParamDataSource::getSinTime_0_1(Real x) const
1089
0
    { 
1090
0
        return std::sin(this->getTime_0_1(x));
1091
0
    }
1092
    //-----------------------------------------------------------------------------
1093
    Real AutoParamDataSource::getTanTime_0_1(Real x) const
1094
0
    { 
1095
0
        return std::tan(this->getTime_0_1(x));
1096
0
    }
1097
    //-----------------------------------------------------------------------------
1098
    Vector4f AutoParamDataSource::getTime_0_1_packed(Real x) const
1099
0
    {
1100
0
        float t = this->getTime_0_1(x);
1101
0
        return Vector4f(t, std::sin(t), std::cos(t), std::tan(t));
1102
0
    }
1103
    //-----------------------------------------------------------------------------
1104
    Real AutoParamDataSource::getTime_0_2Pi(Real x) const
1105
0
    { 
1106
0
        return this->getTime_0_X(x)/x*2*Math::PI; 
1107
0
    }
1108
    //-----------------------------------------------------------------------------
1109
    Real AutoParamDataSource::getCosTime_0_2Pi(Real x) const
1110
0
    { 
1111
0
        return std::cos(this->getTime_0_2Pi(x));
1112
0
    }
1113
    //-----------------------------------------------------------------------------
1114
    Real AutoParamDataSource::getSinTime_0_2Pi(Real x) const
1115
0
    { 
1116
0
        return std::sin(this->getTime_0_2Pi(x));
1117
0
    }
1118
    //-----------------------------------------------------------------------------
1119
    Real AutoParamDataSource::getTanTime_0_2Pi(Real x) const
1120
0
    { 
1121
0
        return std::tan(this->getTime_0_2Pi(x));
1122
0
    }
1123
    //-----------------------------------------------------------------------------
1124
    Vector4f AutoParamDataSource::getTime_0_2Pi_packed(Real x) const
1125
0
    {
1126
0
        float t = this->getTime_0_2Pi(x);
1127
0
        return Vector4f(t, std::sin(t), std::cos(t), std::tan(t));
1128
0
    }
1129
    //-----------------------------------------------------------------------------
1130
    Real AutoParamDataSource::getFrameTime(void) const
1131
0
    {
1132
0
        return ControllerManager::getSingleton().getFrameTimeSource()->getValue();
1133
0
    }
1134
    //-----------------------------------------------------------------------------
1135
    Real AutoParamDataSource::getFPS() const
1136
0
    {
1137
0
        return mCurrentRenderTarget->getStatistics().lastFPS;
1138
0
    }
1139
    //-----------------------------------------------------------------------------
1140
    Real AutoParamDataSource::getViewportWidth() const
1141
0
    { 
1142
0
        return static_cast<Real>(mCurrentViewport->getActualWidth()); 
1143
0
    }
1144
    //-----------------------------------------------------------------------------
1145
    Real AutoParamDataSource::getViewportHeight() const
1146
0
    { 
1147
0
        return static_cast<Real>(mCurrentViewport->getActualHeight()); 
1148
0
    }
1149
    //-----------------------------------------------------------------------------
1150
    Real AutoParamDataSource::getInverseViewportWidth() const
1151
0
    { 
1152
0
        return 1.0f/mCurrentViewport->getActualWidth(); 
1153
0
    }
1154
    //-----------------------------------------------------------------------------
1155
    Real AutoParamDataSource::getInverseViewportHeight() const
1156
0
    { 
1157
0
        return 1.0f/mCurrentViewport->getActualHeight(); 
1158
0
    }
1159
    //-----------------------------------------------------------------------------
1160
    Vector3 AutoParamDataSource::getViewDirection() const
1161
0
    {
1162
0
        return mCurrentCamera->getDerivedDirection();
1163
0
    }
1164
    //-----------------------------------------------------------------------------
1165
    Vector3 AutoParamDataSource::getViewSideVector() const
1166
0
    { 
1167
0
        return mCurrentCamera->getDerivedRight();
1168
0
    }
1169
    //-----------------------------------------------------------------------------
1170
    Vector3 AutoParamDataSource::getViewUpVector() const
1171
0
    { 
1172
0
        return mCurrentCamera->getDerivedUp();
1173
0
    }
1174
    //-----------------------------------------------------------------------------
1175
    float AutoParamDataSource::getFOV() const
1176
0
    { 
1177
0
        return mCurrentCamera->getFOVy().valueRadians(); 
1178
0
    }
1179
    //-----------------------------------------------------------------------------
1180
    float AutoParamDataSource::getNearClipDistance() const
1181
0
    { 
1182
0
        return mCurrentCamera->getNearClipDistance(); 
1183
0
    }
1184
    //-----------------------------------------------------------------------------
1185
    float AutoParamDataSource::getFarClipDistance() const
1186
0
    { 
1187
0
        return mCurrentCamera->getFarClipDistance(); 
1188
0
    }
1189
    //-----------------------------------------------------------------------------
1190
    int AutoParamDataSource::getPassNumber(void) const
1191
0
    {
1192
0
        return mPassNumber;
1193
0
    }
1194
    //-----------------------------------------------------------------------------
1195
    void AutoParamDataSource::setPassNumber(const int passNumber)
1196
0
    {
1197
0
        mPassNumber = passNumber;
1198
0
    }
1199
    //-----------------------------------------------------------------------------
1200
    void AutoParamDataSource::incPassNumber(void)
1201
0
    {
1202
0
        ++mPassNumber;
1203
0
    }
1204
    int AutoParamDataSource::getMaterialLodIndex() const
1205
0
    {
1206
0
        return mCurrentRenderable->_getMaterialLodIndex();
1207
0
    }
1208
    //-----------------------------------------------------------------------------
1209
    const Vector4& AutoParamDataSource::getSceneDepthRange() const
1210
0
    {
1211
0
        static Vector4 dummy(0, 100000, 100000, 1.f/100000);
1212
1213
0
        if (mSceneDepthRangeDirty)
1214
0
        {
1215
            // calculate depth information
1216
0
            Real depthRange = mMainCamBoundsInfo->maxDistanceInFrustum - mMainCamBoundsInfo->minDistanceInFrustum;
1217
0
            if (depthRange > std::numeric_limits<Real>::epsilon())
1218
0
            {
1219
0
                mSceneDepthRange = Vector4(
1220
0
                    mMainCamBoundsInfo->minDistanceInFrustum,
1221
0
                    mMainCamBoundsInfo->maxDistanceInFrustum,
1222
0
                    depthRange,
1223
0
                    1.0f / depthRange);
1224
0
            }
1225
0
            else
1226
0
            {
1227
0
                mSceneDepthRange = dummy;
1228
0
            }
1229
0
            mSceneDepthRangeDirty = false;
1230
0
        }
1231
1232
0
        return mSceneDepthRange;
1233
1234
0
    }
1235
    //-----------------------------------------------------------------------------
1236
    const Vector4& AutoParamDataSource::getShadowSceneDepthRange(size_t index) const
1237
0
    {
1238
0
        static Vector4 dummy(0, 100000, 100000, 1.0f/100000);
1239
1240
0
        if (!mCurrentSceneManager->isShadowTechniqueTextureBased())
1241
0
            return dummy;
1242
1243
0
        if (index < OGRE_MAX_SIMULTANEOUS_LIGHTS)
1244
0
        {
1245
0
            if (mShadowCamDepthRangesDirty[index] && mCurrentTextureProjector[index])
1246
0
            {
1247
0
                const VisibleObjectsBoundsInfo& info = 
1248
0
                    mCurrentSceneManager->getVisibleObjectsBoundsInfo(
1249
0
                        (const Camera*)mCurrentTextureProjector[index]);
1250
1251
0
                Real depthRange = info.maxDistanceInFrustum - info.minDistanceInFrustum;
1252
0
                if (depthRange > std::numeric_limits<Real>::epsilon())
1253
0
                {
1254
0
                    mShadowCamDepthRanges[index] = Vector4(
1255
0
                        info.minDistanceInFrustum,
1256
0
                        info.maxDistanceInFrustum,
1257
0
                        depthRange,
1258
0
                        1.0f / depthRange);
1259
0
                }
1260
0
                else
1261
0
                {
1262
0
                    mShadowCamDepthRanges[index] = dummy;
1263
0
                }
1264
1265
0
                mShadowCamDepthRangesDirty[index] = false;
1266
0
            }
1267
0
            return mShadowCamDepthRanges[index];
1268
0
        }
1269
0
        else
1270
0
            return dummy;
1271
0
    }
1272
    //---------------------------------------------------------------------
1273
    void AutoParamDataSource::setShadowColour(const ColourValue& colour)
1274
0
    {
1275
0
        mShadowColour = colour;
1276
0
    }
1277
    const ColourValue& AutoParamDataSource::getShadowColour() const
1278
0
    {
1279
0
        return mShadowColour;
1280
0
    }
1281
    //-------------------------------------------------------------------------
1282
    void AutoParamDataSource::updateLightCustomGpuParameter(const GpuProgramParameters::AutoConstantEntry& constantEntry, GpuProgramParameters *params) const
1283
0
    {
1284
0
        uint16 lightIndex = static_cast<uint16>(constantEntry.data & 0xFFFF),
1285
0
            paramIndex = static_cast<uint16>((constantEntry.data >> 16) & 0xFFFF);
1286
0
        if(mCurrentLightList && lightIndex < mCurrentLightList->size())
1287
0
        {
1288
0
            const Light &light = getLight(lightIndex);
1289
0
            light._updateCustomGpuParameter(paramIndex, constantEntry, params);
1290
0
        }
1291
0
    }
1292
1293
}
1294