2
--------------------------------------------------------------------------------
3
This source file is part of Hydrax.
6
Copyright (C) 2008 Xavier Vergu�n Gonz�lez <xavierverguin@hotmail.com>
9
This program is free software; you can redistribute it and/or modify it under
10
the terms of the GNU Lesser General Public License as published by the Free Software
11
Foundation; either version 2 of the License, or (at your option) any later
14
This program is distributed in the hope that it will be useful, but WITHOUT
15
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
You should have received a copy of the GNU Lesser General Public License along with
19
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21
http://www.gnu.org/copyleft/lesser.txt.
22
--------------------------------------------------------------------------------
25
#pragma warning(disable:4355)
32
Hydrax::Hydrax(Ogre::SceneManager *sm, Ogre::Camera *c, Ogre::Viewport *v)
37
, mPolygonMode(Ogre::PM_SOLID)
38
, mShaderMode(MaterialManager::SM_HLSL)
39
, mPosition(Ogre::Vector3(0,0,0))
41
, mFullReflectionDistance(99999997952.0)
42
, mGlobalTransparency(0.05)
43
, mWaterColor(Ogre::Vector3(0,0.1,0.172))
44
, mNormalDistortion(0.09)
45
, mSunPosition(Ogre::Vector3(5000,3000,1))
48
, mSunColor(Ogre::Vector3(1,0.75,0.25))
49
, mFoamMaxDistance(75000000.0)
52
, mFoamTransparency(1)
58
, mGodRaysExposure(Ogre::Vector3(0.76,2.46,2.29))
59
, mGodRaysIntensity(0.015)
60
, mCurrentFrameUnderwater(false)
61
, mMesh(new Mesh(this))
62
, mMaterialManager(new MaterialManager(this))
63
, mRttManager(new RttManager(this))
64
, mTextureManager(new TextureManager(this))
65
, mGodRaysManager(new GodRaysManager(this))
66
, mDecalsManager(new DecalsManager(this))
67
, mGPUNormalMapManager(new GPUNormalMapManager(this))
68
, mCfgFileManager(new CfgFileManager(this))
70
, mComponents(HYDRAX_COMPONENTS_NONE)
72
HydraxLOG("Hydrax created.");
84
delete mTextureManager;
85
delete mMaterialManager;
86
delete mGPUNormalMapManager;
87
delete mDecalsManager;
88
delete mGodRaysManager;
90
delete mCfgFileManager;
93
HydraxLOG("Hydrax object removed.");
100
HydraxLOG("Module isn't set, skipping...");
107
HydraxLOG("Hydrax is alredy created, skipping...");
112
HydraxLOG("Creating module...");
115
if (mModule->getNormalMode() == MaterialManager::NM_RTT)
117
if (!mModule->getNoise()->createGPUNormalMapResources(mGPUNormalMapManager))
119
HydraxLOG(mModule->getNoise()->getName() + " doesn't support GPU Normal map generation.");
124
if (mModule->getNoise()->areGPUNormalMapResourcesCreated())
126
mModule->getNoise()->removeGPUNormalMapResources(mGPUNormalMapManager);
129
HydraxLOG("Module created.");
131
HydraxLOG("Initializating RTT Manager...");
132
mRttManager->initialize(RttManager::RTT_REFLECTION);
133
mRttManager->initialize(RttManager::RTT_REFRACTION);
134
if (isComponent(HYDRAX_COMPONENT_DEPTH))
136
mRttManager->initialize(RttManager::RTT_DEPTH);
138
HydraxLOG("RTT manager initialized.");
140
HydraxLOG("Registring device restored listener...");
141
mDeviceRestoredListener.mHydrax = this;
142
Ogre::Root::getSingleton().getRenderSystem()->addListener(&mDeviceRestoredListener);
143
HydraxLOG("Device restored listener registred.");
145
HydraxLOG("Creating materials...");
146
mMaterialManager->createMaterials(mComponents, MaterialManager::Options(mShaderMode, mModule->getNormalMode()));
147
mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName());
148
HydraxLOG("Materials created.");
150
if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
152
HydraxLOG("Creating god rays...");
153
mGodRaysManager->create(mComponents);
154
HydraxLOG("God rays created.");
157
HydraxLOG("Creating water mesh...");
158
mMesh->setOptions(mModule->getMeshOptions());
160
HydraxLOG("Water mesh created.");
165
void Hydrax::remove()
173
mDecalsManager->removeAll();
174
mMaterialManager->removeMaterials();
175
mRttManager->removeAll();
176
mGodRaysManager->remove();
178
mTextureManager->remove();
183
void Hydrax::DeviceRestoredListener::eventOccurred(const Ogre::String& eventName, const Ogre::NameValuePairList *parameters)
185
if (eventName == "DeviceRestored")
188
HydraxLOG("Restoring water mesh...");
189
if (mHydrax->mMesh->isCreated())
191
Ogre::String MaterialNameTmp = mHydrax->mMesh->getMaterialName();
192
Mesh::Options MeshOptionsTmp = mHydrax->mMesh->getOptions();
194
HydraxLOG("Updating water mesh...");
196
HydraxLOG("Deleting water mesh...");
197
delete mHydrax->mMesh;
198
HydraxLOG("Water mesh deleted.");
200
HydraxLOG("Creating water mesh...");
201
mHydrax->mMesh = new Mesh(mHydrax);
202
mHydrax->mMesh->setOptions(MeshOptionsTmp);
203
mHydrax->mMesh->setMaterialName(MaterialNameTmp);
204
mHydrax->mMesh->create();
205
mHydrax->setPosition(mHydrax->mPosition);
206
mHydrax->mModule->update(0); // ???
207
HydraxLOG("Water mesh created.");
209
HydraxLOG("Water mesh restored.");
213
void Hydrax::setPolygonMode(const Ogre::PolygonMode& PM)
220
mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getTechnique(0)->getPass(0)->setPolygonMode(PM);
222
if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
224
mMaterialManager->getMaterial(MaterialManager::MAT_UNDERWATER)->getTechnique(0)->getPass(0)->setPolygonMode(PM);
230
void Hydrax::setShaderMode(const MaterialManager::ShaderMode& ShaderMode)
232
mShaderMode = ShaderMode;
234
if (mCreated && mModule)
236
mMaterialManager->createMaterials(mComponents, MaterialManager::Options(mShaderMode, mModule->getNormalMode()));
238
mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName());
242
void Hydrax::update(const Ogre::Real &timeSinceLastFrame)
244
if (mCreated && mModule)
246
mModule->update(timeSinceLastFrame);
247
mDecalsManager->update();
248
_checkUnderwater(timeSinceLastFrame);
252
void Hydrax::setComponents(const HydraxComponent &Components)
254
mComponents = Components;
256
if (isComponent(HYDRAX_COMPONENT_SMOOTH) || isComponent(HYDRAX_COMPONENT_CAUSTICS) || isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
258
// Delete smooth and/or caustics components wich needs depth component
259
if (!isComponent(HYDRAX_COMPONENT_DEPTH))
261
HydraxComponent s = HYDRAX_COMPONENTS_NONE,
262
f = HYDRAX_COMPONENTS_NONE,
263
u = HYDRAX_COMPONENTS_NONE,
264
ur = HYDRAX_COMPONENTS_NONE;
266
if (isComponent(HYDRAX_COMPONENT_SUN))
268
s = HYDRAX_COMPONENT_SUN;
270
if (isComponent(HYDRAX_COMPONENT_FOAM))
272
f = HYDRAX_COMPONENT_FOAM;
274
if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
276
u = HYDRAX_COMPONENT_UNDERWATER;
278
if (isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS))
280
ur = HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS;
283
if (isComponent(HYDRAX_COMPONENT_SMOOTH))
285
HydraxLOG("Smooth component needs depth component... smooth component desactivated.");
287
if (isComponent(HYDRAX_COMPONENT_CAUSTICS))
289
HydraxLOG("Caustics component needs depth component... caustics component desactivated.");
291
if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
293
HydraxLOG("God rays component needs depth component... god rays component desactivated.");
296
mComponents = static_cast<HydraxComponent>(s|f|u|ur);
300
if (isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS) || isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
302
// Delete underwater reflections components wich needs underwater component
303
if (!isComponent(HYDRAX_COMPONENT_UNDERWATER))
305
HydraxComponent s = HYDRAX_COMPONENTS_NONE,
306
f = HYDRAX_COMPONENTS_NONE,
307
d = HYDRAX_COMPONENTS_NONE,
308
sm = HYDRAX_COMPONENTS_NONE,
309
c = HYDRAX_COMPONENTS_NONE;
311
if (isComponent(HYDRAX_COMPONENT_SUN))
313
s = HYDRAX_COMPONENT_SUN;
315
if (isComponent(HYDRAX_COMPONENT_FOAM))
317
f = HYDRAX_COMPONENT_FOAM;
319
if (isComponent(HYDRAX_COMPONENT_DEPTH))
321
d = HYDRAX_COMPONENT_DEPTH;
323
if (isComponent(HYDRAX_COMPONENT_SMOOTH))
325
sm = HYDRAX_COMPONENT_SMOOTH;
327
if (isComponent(HYDRAX_COMPONENT_CAUSTICS))
329
c = HYDRAX_COMPONENT_CAUSTICS;
332
if (isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS))
334
HydraxLOG("Underwater reflections component needs underwater component... underwater reflections component desactivated.");
336
if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
338
HydraxLOG("God rays component needs underwater component... god rays component desactivated.");
341
mComponents = static_cast<HydraxComponent>(s|f|d|sm|c);
344
if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS) && !isComponent(HYDRAX_COMPONENT_SUN))
346
HydraxLOG("God rays component needs sun component... god rays component desactivated.");
348
HydraxComponent f = HYDRAX_COMPONENTS_NONE,
349
d = HYDRAX_COMPONENTS_NONE,
350
c = HYDRAX_COMPONENTS_NONE,
351
sm = HYDRAX_COMPONENTS_NONE,
352
u = HYDRAX_COMPONENTS_NONE,
353
ur = HYDRAX_COMPONENTS_NONE;
355
if (isComponent(HYDRAX_COMPONENT_FOAM))
357
f = HYDRAX_COMPONENT_FOAM;
359
if (isComponent(HYDRAX_COMPONENT_DEPTH))
361
d = HYDRAX_COMPONENT_DEPTH;
363
if (isComponent(HYDRAX_COMPONENT_SMOOTH))
365
sm = HYDRAX_COMPONENT_SMOOTH;
367
if (isComponent(HYDRAX_COMPONENT_CAUSTICS))
369
c = HYDRAX_COMPONENT_CAUSTICS;
371
if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
373
u = HYDRAX_COMPONENT_UNDERWATER;
375
if (isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS))
377
ur = HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS;
380
mComponents = static_cast<HydraxComponent>(f|d|sm|c|u|ur);
384
int NumberOfDepthChannels = 0;
386
if (isComponent(HYDRAX_COMPONENT_DEPTH))
388
NumberOfDepthChannels++;
390
if (isComponent(HYDRAX_COMPONENT_CAUSTICS))
392
NumberOfDepthChannels++;
395
if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
397
NumberOfDepthChannels++;
401
if (NumberOfDepthChannels > 0)
403
mRttManager->setNumberOfChannels(RttManager::RTT_DEPTH, static_cast<RttManager::NumberOfChannels>(NumberOfDepthChannels));
406
if (!mCreated || !mModule)
411
if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
413
mGodRaysManager->create(mComponents);
417
mGodRaysManager->remove();
423
if (!isComponent(HYDRAX_COMPONENT_DEPTH))
425
mRttManager->remove(RttManager::RTT_DEPTH);
426
mRttManager->remove(RttManager::RTT_DEPTH_REFLECTION);
430
mRttManager->initialize(RttManager::RTT_DEPTH);
432
if (isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS))
434
mRttManager->initialize(RttManager::RTT_DEPTH_REFLECTION);
439
mMaterialManager->createMaterials(mComponents, MaterialManager::Options(mShaderMode, mModule->getNormalMode()));
441
mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName());
444
void Hydrax::setModule(Module::Module* Module, const bool& DeleteOldModule)
448
if (mModule->getNormalMode() != Module->getNormalMode())
450
mMaterialManager->createMaterials(mComponents, MaterialManager::Options(mShaderMode, Module->getNormalMode()));
452
mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName());
455
if (mModule->getNormalMode() == MaterialManager::NM_RTT && mModule->isCreated() && mModule->getNoise()->areGPUNormalMapResourcesCreated())
457
mModule->getNoise()->removeGPUNormalMapResources(mGPUNormalMapManager);
469
// Due to modules can change -internally- scene nodes position,
470
// just reset them to the original position.
471
setPosition(mPosition);
478
if (!mModule->isCreated())
482
if (mModule->getNormalMode() == MaterialManager::NM_RTT)
484
if (!mModule->getNoise()->createGPUNormalMapResources(mGPUNormalMapManager))
486
HydraxLOG(mModule->getNoise()->getName() + " doesn't support GPU Normal map generation.");
492
if (mModule->getNormalMode() == MaterialManager::NM_RTT)
494
if (!mModule->getNoise()->areGPUNormalMapResourcesCreated())
496
if (!mModule->getNoise()->createGPUNormalMapResources(mGPUNormalMapManager))
498
HydraxLOG(mModule->getNoise()->getName() + " doesn't support GPU Normal map generation.");
504
if (mModule->getNoise()->areGPUNormalMapResourcesCreated())
506
mModule->getNoise()->removeGPUNormalMapResources(mGPUNormalMapManager);
511
HydraxLOG("Updating water mesh...");
512
Ogre::String MaterialNameTmp = mMesh->getMaterialName();
514
HydraxLOG("Deleting water mesh...");
516
HydraxLOG("Water mesh deleted.");
518
HydraxLOG("Creating water mesh...");
519
mMesh->setOptions(mModule->getMeshOptions());
520
mMesh->setMaterialName(MaterialNameTmp);
522
setPosition(mPosition);
523
HydraxLOG("Water mesh created.");
525
HydraxLOG("Module set.");
529
bool Hydrax::isComponent(const HydraxComponent &Component)
531
if (mComponents & Component)
536
if (Component == HYDRAX_COMPONENTS_NONE && mComponents == HYDRAX_COMPONENTS_NONE)
541
if (Component == HYDRAX_COMPONENTS_ALL && mComponents == HYDRAX_COMPONENTS_ALL)
549
void Hydrax::_checkUnderwater(const Ogre::Real& timeSinceLastFrame)
551
if (!isComponent(HYDRAX_COMPONENT_UNDERWATER))
553
mCurrentFrameUnderwater = false;
558
// If the camera is under the current water x/z position
559
if (getHeigth(mCamera->getDerivedPosition()) > mCamera->getDerivedPosition().y-1.25f) // <--- TODO
561
mCurrentFrameUnderwater = true;
563
if (mMesh->getMaterialName() != mMaterialManager->getMaterial(MaterialManager::MAT_UNDERWATER)->getName())
565
mRttManager->getTexture(RttManager::RTT_REFRACTION)->
566
getBuffer()->getRenderTarget()->getViewport(0)->
567
setSkiesEnabled(true);
569
if (isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS))
571
mRttManager->getTexture(RttManager::RTT_REFLECTION)->
572
getBuffer()->getRenderTarget()->getViewport(0)->
573
setSkiesEnabled(false);
575
if (isComponent(HYDRAX_COMPONENT_DEPTH))
577
mRttManager->initialize(RttManager::RTT_DEPTH_REFLECTION);
582
mRttManager->remove(RttManager::RTT_REFLECTION);
585
if (isComponent(HYDRAX_COMPONENT_DEPTH) && isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS))
587
mRttManager->initialize(RttManager::RTT_DEPTH_REFLECTION);
590
mMaterialManager->reload(MaterialManager::MAT_UNDERWATER);
592
mMaterialManager->setCompositorEnable(MaterialManager::COMP_UNDERWATER, true);
594
mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_UNDERWATER)->getName());
598
if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
600
mGodRaysManager->update(timeSinceLastFrame);
605
mCurrentFrameUnderwater = false;
607
if (mMesh->getMaterialName() != mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName())
609
// We asume that RefractionRtt/ReflectionRtt are initialized
610
mRttManager->getTexture(RttManager::RTT_REFRACTION)->
611
getBuffer()->getRenderTarget()->getViewport(0)->
612
setSkiesEnabled(false);
614
if (!isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS))
616
mRttManager->initialize(RttManager::RTT_REFLECTION);
617
mMaterialManager->reload(MaterialManager::MAT_WATER);
620
mRttManager->getTexture(RttManager::RTT_REFLECTION)->
621
getBuffer()->getRenderTarget()->getViewport(0)->
622
setSkiesEnabled(true);
624
if (isComponent(HYDRAX_COMPONENT_DEPTH) && isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS))
626
mRttManager->remove(RttManager::RTT_DEPTH_REFLECTION);
629
mMaterialManager->setCompositorEnable(MaterialManager::COMP_UNDERWATER, false);
631
mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName());
637
void Hydrax::setPosition(const Ogre::Vector3 &Position)
639
mPosition = Position;
646
if (isComponent(HYDRAX_COMPONENT_DEPTH))
648
mMaterialManager->setGpuProgramParameter(
649
MaterialManager::GPUP_VERTEX, MaterialManager::MAT_DEPTH,
650
"uPlaneYPos", Position.y);
653
mMesh->getSceneNode()->setPosition(Position);
654
mRttManager->getPlanesSceneNode()->setPosition(Position);
656
// For world-space -> object-space conversion
657
setSunPosition(mSunPosition);
660
void Hydrax::rotate(const Ogre::Quaternion &q)
664
HydraxLOG("Hydrax::rotate(...) must be called after Hydrax::create(), skipping...");
669
mMesh->getSceneNode()->rotate(q);
670
mRttManager->getPlanesSceneNode()->rotate(q);
672
// For world-space -> object-space conversion
673
setSunPosition(mSunPosition);
676
void Hydrax::setPlanesError(const Ogre::Real &PlanesError)
678
mPlanesError = PlanesError;
681
void Hydrax::_setStrength(const Ogre::Real &Strength)
683
if (isComponent(HYDRAX_COMPONENT_FOAM))
685
mMaterialManager->setGpuProgramParameter(
686
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_WATER,
687
"uFoamRange", Strength);
689
if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
691
mMaterialManager->setGpuProgramParameter(
692
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_UNDERWATER,
693
"uFoamRange", Strength);
697
mDecalsManager->_setWaterStrength(Strength);
700
void Hydrax::setFullReflectionDistance(const Ogre::Real &FullReflectionDistance)
702
mFullReflectionDistance = FullReflectionDistance;
704
mMaterialManager->setGpuProgramParameter(
705
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_WATER,
706
"uFullReflectionDistance", FullReflectionDistance);
708
if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
710
mMaterialManager->setGpuProgramParameter(
711
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_UNDERWATER,
712
"uFullReflectionDistance", FullReflectionDistance);
716
void Hydrax::setGlobalTransparency(const Ogre::Real &GlobalTransparency)
718
mGlobalTransparency = GlobalTransparency;
720
mMaterialManager->setGpuProgramParameter(
721
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_WATER,
722
"uGlobalTransparency", GlobalTransparency);
724
if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
726
mMaterialManager->setGpuProgramParameter(
727
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_UNDERWATER,
728
"uGlobalTransparency", GlobalTransparency);
732
void Hydrax::setWaterColor(const Ogre::Vector3 &WaterColor)
734
mWaterColor = WaterColor;
741
Ogre::ColourValue WC = Ogre::ColourValue(WaterColor.x, WaterColor.y, WaterColor.z);
743
mRttManager->getTexture(RttManager::RTT_REFLECTION)->
744
getBuffer()->getRenderTarget()->getViewport(0)->
745
setBackgroundColour(WC);
746
mRttManager->getTexture(RttManager::RTT_REFRACTION)->
747
getBuffer()->getRenderTarget()->getViewport(0)->
748
setBackgroundColour(WC);
750
if (!isComponent(HYDRAX_COMPONENT_DEPTH))
755
mMaterialManager->setGpuProgramParameter(
756
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_WATER,
757
"uWaterColor", WaterColor);
759
if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
761
mMaterialManager->setGpuProgramParameter(
762
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_UNDERWATER,
763
"uWaterColor", WaterColor);
765
//mMaterialManager->getCompositor(MaterialManager::COMP_UNDERWATER)->
766
// getTechnique(0)->getTargetPass(0)->getPass(0)->setClearColour(WC);
768
if (getHeigth(mCamera->getDerivedPosition()) > mCamera->getDerivedPosition().y-1.25f)
770
if (mMaterialManager->isCompositorEnable(MaterialManager::COMP_UNDERWATER))
772
mMaterialManager->setCompositorEnable(MaterialManager::COMP_UNDERWATER, false);
773
mMaterialManager->setCompositorEnable(MaterialManager::COMP_UNDERWATER, true);
780
void Hydrax::setNormalDistortion(const Ogre::Real &NormalDistortion)
782
mNormalDistortion = NormalDistortion;
784
mMaterialManager->setGpuProgramParameter(
785
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_WATER,
786
"uNormalDistortion", NormalDistortion);
788
if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
790
mMaterialManager->setGpuProgramParameter(
791
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_UNDERWATER,
792
"uNormalDistortion", NormalDistortion);
796
void Hydrax::setSunPosition(const Ogre::Vector3 &SunPosition)
798
if (!isComponent(HYDRAX_COMPONENT_SUN))
803
mSunPosition = SunPosition;
805
mMaterialManager->setGpuProgramParameter(
806
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_WATER,
807
"uSunPosition", mMesh->getObjectSpacePosition(SunPosition));
809
if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
811
mMaterialManager->setGpuProgramParameter(
812
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_UNDERWATER,
813
"uSunPosition", mMesh->getObjectSpacePosition(SunPosition));
817
void Hydrax::setSunStrength(const Ogre::Real &SunStrength)
819
if (!isComponent(HYDRAX_COMPONENT_SUN))
824
mSunStrength = SunStrength;
826
mMaterialManager->setGpuProgramParameter(
827
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_WATER,
828
"uSunStrength", SunStrength);
830
if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
832
mMaterialManager->setGpuProgramParameter(
833
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_UNDERWATER,
834
"uSunStrength", SunStrength);
838
void Hydrax::setSunArea(const Ogre::Real &SunArea)
840
if (!isComponent(HYDRAX_COMPONENT_SUN))
847
mMaterialManager->setGpuProgramParameter(
848
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_WATER,
849
"uSunArea", SunArea);
851
if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
853
mMaterialManager->setGpuProgramParameter(
854
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_UNDERWATER,
855
"uSunArea", SunArea);
859
void Hydrax::setSunColor(const Ogre::Vector3 &SunColor)
861
if (!isComponent(HYDRAX_COMPONENT_SUN))
866
mSunColor = SunColor;
868
mMaterialManager->setGpuProgramParameter(
869
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_WATER,
870
"uSunColor", SunColor);
872
if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
874
mMaterialManager->setGpuProgramParameter(
875
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_UNDERWATER,
876
"uSunColor", SunColor);
880
void Hydrax::setFoamMaxDistance(const Ogre::Real &FoamMaxDistance)
882
if (!isComponent(HYDRAX_COMPONENT_FOAM))
887
mFoamMaxDistance = FoamMaxDistance;
889
mMaterialManager->setGpuProgramParameter(
890
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_WATER,
891
"uFoamMaxDistance", FoamMaxDistance);
893
if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
895
mMaterialManager->setGpuProgramParameter(
896
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_UNDERWATER,
897
"uFoamMaxDistance", FoamMaxDistance);
901
void Hydrax::setFoamScale(const Ogre::Real &FoamScale)
903
if (!isComponent(HYDRAX_COMPONENT_FOAM))
908
mFoamScale = FoamScale;
910
mMaterialManager->setGpuProgramParameter(
911
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_WATER,
912
"uFoamScale", FoamScale);
914
if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
916
mMaterialManager->setGpuProgramParameter(
917
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_UNDERWATER,
918
"uFoamScale", FoamScale);
922
void Hydrax::setFoamStart(const Ogre::Real &FoamStart)
924
if (!isComponent(HYDRAX_COMPONENT_FOAM))
929
mFoamStart = FoamStart;
931
mMaterialManager->setGpuProgramParameter(
932
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_WATER,
933
"uFoamStart", FoamStart);
935
if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
937
mMaterialManager->setGpuProgramParameter(
938
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_UNDERWATER,
939
"uFoamStart", FoamStart);
943
void Hydrax::setFoamTransparency(const Ogre::Real &FoamTransparency)
945
if (!isComponent(HYDRAX_COMPONENT_FOAM))
950
mFoamTransparency = FoamTransparency;
952
mMaterialManager->setGpuProgramParameter(
953
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_WATER,
954
"uFoamTransparency", FoamTransparency);
956
if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
958
mMaterialManager->setGpuProgramParameter(
959
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_UNDERWATER,
960
"uFoamTransparency", FoamTransparency);
964
void Hydrax::setDepthLimit(const Ogre::Real &DepthLimit)
966
if (!isComponent(HYDRAX_COMPONENT_DEPTH))
971
mDepthLimit = DepthLimit;
973
if (mDepthLimit <= 0)
978
mMaterialManager->setGpuProgramParameter(
979
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_DEPTH,
980
"uDepthLimit", 1/mDepthLimit);
983
void Hydrax::setSmoothPower(const Ogre::Real &SmoothPower)
985
if (!isComponent(HYDRAX_COMPONENT_SMOOTH))
990
mSmoothPower = SmoothPower;
992
mMaterialManager->setGpuProgramParameter(
993
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_WATER,
994
"uSmoothPower", SmoothPower);
997
void Hydrax::setCausticsScale(const Ogre::Real &CausticsScale)
999
if (!isComponent(HYDRAX_COMPONENT_CAUSTICS))
1004
mCausticsScale = CausticsScale;
1006
mMaterialManager->setGpuProgramParameter(
1007
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_DEPTH,
1008
"uCausticsScale", CausticsScale);
1011
void Hydrax::setCausticsPower(const Ogre::Real &CausticsPower)
1013
if (!isComponent(HYDRAX_COMPONENT_CAUSTICS))
1018
mCausticsPower = CausticsPower;
1020
mMaterialManager->setGpuProgramParameter(
1021
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_WATER,
1022
"uCausticsPower", CausticsPower);
1024
if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
1026
mMaterialManager->setGpuProgramParameter(
1027
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_UNDERWATER,
1028
"uCausticsPower", CausticsPower);
1030
mMaterialManager->setGpuProgramParameter(
1031
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_UNDERWATER_COMPOSITOR,
1032
"uCausticsPower", CausticsPower);
1036
void Hydrax::setCausticsEnd(const Ogre::Real &CausticsEnd)
1038
if (!isComponent(HYDRAX_COMPONENT_CAUSTICS))
1043
mCausticsEnd = CausticsEnd;
1045
mMaterialManager->setGpuProgramParameter(
1046
MaterialManager::GPUP_FRAGMENT, MaterialManager::MAT_DEPTH,
1047
"uCausticsEnd", CausticsEnd);