Coverage Report

Created: 2026-04-12 06:41

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