30 #pragma warning(disable:4355)
43 , mPolygonMode(
Ogre::PM_SOLID)
45 , mPosition(
Ogre::Vector3(0,0,0))
47 , mFullReflectionDistance(99999997952.0)
48 , mGlobalTransparency(0.05)
49 , mWaterColor(
Ogre::Vector3(0,0.1,0.172))
50 , mNormalDistortion(0.09)
51 , mSunPosition(
Ogre::Vector3(5000,3000,1))
54 , mSunColor(
Ogre::Vector3(1,0.75,0.25))
55 , mFoamMaxDistance(75000000.0)
58 , mFoamTransparency(1)
64 , mGodRaysExposure(
Ogre::Vector3(0.76,2.46,2.29))
65 , mGodRaysIntensity(0.015)
66 , mUnderwaterCameraSwitchDelta(0.1f)
67 , mCurrentFrameUnderwater(false)
68 , mMesh(new
Mesh(this))
91 delete mTextureManager;
92 delete mMaterialManager;
93 delete mGPUNormalMapManager;
94 delete mDecalsManager;
95 delete mGodRaysManager;
97 delete mCfgFileManager;
103 void Hydrax::create()
107 HydraxLOG(
"Module isn't set, skipping...");
114 HydraxLOG(
"Hydrax is alredy created, skipping...");
124 if (!mModule->getNoise()->createGPUNormalMapResources(mGPUNormalMapManager))
126 HydraxLOG(mModule->getNoise()->getName() +
" doesn't support GPU Normal map generation.");
131 if (mModule->getNoise()->areGPUNormalMapResourcesCreated())
133 mModule->getNoise()->removeGPUNormalMapResources(mGPUNormalMapManager);
138 HydraxLOG(
"Initializating RTT Manager...");
147 HydraxLOG(
"Registring device restored listener...");
148 mDeviceListener.mHydrax =
this;
149 Ogre::Root::getSingleton().getRenderSystem()->addListener(&mDeviceListener);
150 HydraxLOG(
"Device restored listener registred.");
160 mGodRaysManager->create(mComponents);
165 mMesh->setOptions(mModule->getMeshOptions());
177 void Hydrax::remove()
184 Ogre::Root::getSingleton().getRenderSystem()->removeListener(&mDeviceListener);
187 mDecalsManager->removeAll();
188 mMaterialManager->removeMaterials();
189 mRttManager->removeAll();
190 mGodRaysManager->remove();
192 mTextureManager->remove();
197 void Hydrax::setVisible(
const bool& Visible)
204 void Hydrax::_checkVisible()
214 mRttManager->removeAll();
217 mMesh->getSceneNode()->setVisible(
false);
237 mGPUNormalMapManager->create();
247 mMesh->getSceneNode()->setVisible(
true);
255 if (eventName ==
"DeviceLost")
258 if (eventName ==
"DeviceRestored")
262 void Hydrax::setPolygonMode(
const Ogre::PolygonMode& PM)
281 mShaderMode = ShaderMode;
283 if (mCreated && mModule)
291 void Hydrax::update(
const Ogre::Real &timeSinceLastFrame)
293 if (mCreated && mModule && mVisible)
295 mModule->update(timeSinceLastFrame);
296 mDecalsManager->update();
297 _checkUnderwater(timeSinceLastFrame);
303 mComponents = Components;
334 HydraxLOG(
"Smooth component needs depth component... smooth component desactivated.");
338 HydraxLOG(
"Caustics component needs depth component... caustics component desactivated.");
342 HydraxLOG(
"God rays component needs depth component... god rays component desactivated.");
383 HydraxLOG(
"Underwater reflections component needs underwater component... underwater reflections component desactivated.");
387 HydraxLOG(
"God rays component needs underwater component... god rays component desactivated.");
395 HydraxLOG(
"God rays component needs sun component... god rays component desactivated.");
433 int NumberOfDepthChannels = 0;
437 NumberOfDepthChannels++;
441 NumberOfDepthChannels++;
446 NumberOfDepthChannels++;
450 if (NumberOfDepthChannels > 0)
455 if (!mCreated || !mModule)
462 mGodRaysManager->create(mComponents);
466 mGodRaysManager->remove();
500 getBuffer()->getRenderTarget()->getViewport(0)->
501 setSkiesEnabled(
false);
504 getBuffer()->getRenderTarget()->getViewport(0)->
505 setSkiesEnabled(
true);
508 mMesh->setMaterialName(
"BaseWhiteNoLighting");
513 mCurrentFrameUnderwater =
false;
516 mMesh->setMaterialName(mCurrentFrameUnderwater ?
520 if (mCurrentFrameUnderwater)
537 if (mModule->getNormalMode() ==
MaterialManager::NM_RTT && mModule->isCreated() && mModule->getNoise()->areGPUNormalMapResourcesCreated())
539 mModule->getNoise()->removeGPUNormalMapResources(mGPUNormalMapManager);
553 setPosition(mPosition);
560 if (!mModule->isCreated())
566 if (!mModule->getNoise()->createGPUNormalMapResources(mGPUNormalMapManager))
568 HydraxLOG(mModule->getNoise()->getName() +
" doesn't support GPU Normal map generation.");
576 if (!mModule->getNoise()->areGPUNormalMapResourcesCreated())
578 if (!mModule->getNoise()->createGPUNormalMapResources(mGPUNormalMapManager))
580 HydraxLOG(mModule->getNoise()->getName() +
" doesn't support GPU Normal map generation.");
586 if (mModule->getNoise()->areGPUNormalMapResourcesCreated())
588 mModule->getNoise()->removeGPUNormalMapResources(mGPUNormalMapManager);
594 Ogre::String MaterialNameTmp = mMesh->getMaterialName();
601 mMesh->setOptions(mModule->getMeshOptions());
602 mMesh->setMaterialName(MaterialNameTmp);
604 setPosition(mPosition);
613 if (mComponents & Component)
631 void Hydrax::_checkUnderwater(
const Ogre::Real& timeSinceLastFrame)
635 mCurrentFrameUnderwater =
false;
641 if (getHeigth(mCamera->getDerivedPosition()) > mCamera->getDerivedPosition().y-mUnderwaterCameraSwitchDelta)
643 mCurrentFrameUnderwater =
true;
648 getBuffer()->getRenderTarget()->getViewport(0)->
649 setSkiesEnabled(
true);
654 getBuffer()->getRenderTarget()->getViewport(0)->
655 setSkiesEnabled(
false);
682 mGodRaysManager->update(timeSinceLastFrame);
687 mCurrentFrameUnderwater =
false;
693 getBuffer()->getRenderTarget()->getViewport(0)->
694 setSkiesEnabled(
false);
703 getBuffer()->getRenderTarget()->getViewport(0)->
704 setSkiesEnabled(
true);
719 void Hydrax::setPosition(
const Ogre::Vector3 &Position)
721 mPosition = Position;
730 mMaterialManager->setGpuProgramParameter(
732 "uPlaneYPos", Position.y);
735 mMesh->getSceneNode()->setPosition(Position.x-mMesh->getSize().Width/2, Position.y, Position.z-mMesh->getSize().Height/2);
736 mRttManager->getPlanesSceneNode()->setPosition(Position);
739 setSunPosition(mSunPosition);
742 void Hydrax::rotate(
const Ogre::Quaternion &q)
746 HydraxLOG(
"Hydrax::rotate(...) must be called after Hydrax::create(), skipping...");
751 mMesh->getSceneNode()->rotate(q);
752 mRttManager->getPlanesSceneNode()->rotate(q);
755 setSunPosition(mSunPosition);
758 void Hydrax::setPlanesError(
const Ogre::Real &PlanesError)
760 mPlanesError = PlanesError;
763 void Hydrax::_setStrength(
const Ogre::Real &Strength)
767 mMaterialManager->setGpuProgramParameter(
769 "uFoamRange", Strength);
773 mMaterialManager->setGpuProgramParameter(
775 "uFoamRange", Strength);
779 mDecalsManager->_setWaterStrength(Strength);
782 void Hydrax::setFullReflectionDistance(
const Ogre::Real &FullReflectionDistance)
784 mFullReflectionDistance = FullReflectionDistance;
786 mMaterialManager->setGpuProgramParameter(
788 "uFullReflectionDistance", FullReflectionDistance);
792 mMaterialManager->setGpuProgramParameter(
794 "uFullReflectionDistance", FullReflectionDistance);
798 void Hydrax::setGlobalTransparency(
const Ogre::Real &GlobalTransparency)
800 mGlobalTransparency = GlobalTransparency;
802 mMaterialManager->setGpuProgramParameter(
804 "uGlobalTransparency", GlobalTransparency);
808 mMaterialManager->setGpuProgramParameter(
810 "uGlobalTransparency", GlobalTransparency);
814 void Hydrax::setWaterColor(
const Ogre::Vector3 &WaterColor)
816 mWaterColor = WaterColor;
823 Ogre::ColourValue WC = Ogre::ColourValue(WaterColor.x, WaterColor.y, WaterColor.z);
828 getBuffer()->getRenderTarget()->getViewport(0)->
829 setBackgroundColour(WC);
832 getBuffer()->getRenderTarget()->getViewport(0)->
833 setBackgroundColour(WC);
840 mMaterialManager->setGpuProgramParameter(
842 "uWaterColor", WaterColor);
846 mMaterialManager->setGpuProgramParameter(
848 "uWaterColor", WaterColor);
867 void Hydrax::setNormalDistortion(
const Ogre::Real &NormalDistortion)
869 mNormalDistortion = NormalDistortion;
871 mMaterialManager->setGpuProgramParameter(
873 "uNormalDistortion", NormalDistortion);
877 mMaterialManager->setGpuProgramParameter(
879 "uNormalDistortion", NormalDistortion);
883 void Hydrax::setSunPosition(
const Ogre::Vector3 &SunPosition)
890 mSunPosition = SunPosition;
892 mMaterialManager->setGpuProgramParameter(
894 "uSunPosition", mMesh->getObjectSpacePosition(SunPosition));
898 mMaterialManager->setGpuProgramParameter(
900 "uSunPosition", mMesh->getObjectSpacePosition(SunPosition));
904 void Hydrax::setSunStrength(
const Ogre::Real &SunStrength)
911 mSunStrength = SunStrength;
913 mMaterialManager->setGpuProgramParameter(
915 "uSunStrength", SunStrength);
919 mMaterialManager->setGpuProgramParameter(
921 "uSunStrength", SunStrength);
925 void Hydrax::setSunArea(
const Ogre::Real &SunArea)
934 mMaterialManager->setGpuProgramParameter(
936 "uSunArea", SunArea);
940 mMaterialManager->setGpuProgramParameter(
942 "uSunArea", SunArea);
946 void Hydrax::setSunColor(
const Ogre::Vector3 &SunColor)
953 mSunColor = SunColor;
955 mMaterialManager->setGpuProgramParameter(
957 "uSunColor", SunColor);
961 mMaterialManager->setGpuProgramParameter(
963 "uSunColor", SunColor);
967 void Hydrax::setFoamMaxDistance(
const Ogre::Real &FoamMaxDistance)
974 mFoamMaxDistance = FoamMaxDistance;
976 mMaterialManager->setGpuProgramParameter(
978 "uFoamMaxDistance", FoamMaxDistance);
982 mMaterialManager->setGpuProgramParameter(
984 "uFoamMaxDistance", FoamMaxDistance);
988 void Hydrax::setFoamScale(
const Ogre::Real &FoamScale)
995 mFoamScale = FoamScale;
997 mMaterialManager->setGpuProgramParameter(
999 "uFoamScale", FoamScale);
1003 mMaterialManager->setGpuProgramParameter(
1005 "uFoamScale", FoamScale);
1009 void Hydrax::setFoamStart(
const Ogre::Real &FoamStart)
1016 mFoamStart = FoamStart;
1018 mMaterialManager->setGpuProgramParameter(
1020 "uFoamStart", FoamStart);
1024 mMaterialManager->setGpuProgramParameter(
1026 "uFoamStart", FoamStart);
1030 void Hydrax::setFoamTransparency(
const Ogre::Real &FoamTransparency)
1037 mFoamTransparency = FoamTransparency;
1039 mMaterialManager->setGpuProgramParameter(
1041 "uFoamTransparency", FoamTransparency);
1045 mMaterialManager->setGpuProgramParameter(
1047 "uFoamTransparency", FoamTransparency);
1051 void Hydrax::setDepthLimit(
const Ogre::Real &DepthLimit)
1058 mDepthLimit = DepthLimit;
1060 if (mDepthLimit <= 0)
1065 mMaterialManager->setGpuProgramParameter(
1067 "uDepthLimit", 1/mDepthLimit);
1070 void Hydrax::setDistLimit(
const Ogre::Real &DistLimit)
1077 mDistLimit = DistLimit;
1079 if (mDistLimit <= 0)
1084 mMaterialManager->setGpuProgramParameter(
1086 "uDistLimit", 1/mDistLimit);
1089 void Hydrax::setSmoothPower(
const Ogre::Real &SmoothPower)
1096 mSmoothPower = SmoothPower;
1098 mMaterialManager->setGpuProgramParameter(
1100 "uSmoothPower", SmoothPower);
1103 void Hydrax::setCausticsScale(
const Ogre::Real &CausticsScale)
1110 mCausticsScale = CausticsScale;
1112 mMaterialManager->setGpuProgramParameter(
1114 "uCausticsScale", CausticsScale);
1117 void Hydrax::setCausticsPower(
const Ogre::Real &CausticsPower)
1124 mCausticsPower = CausticsPower;
1126 mMaterialManager->setGpuProgramParameter(
1128 "uCausticsPower", CausticsPower);
1134 mMaterialManager->setGpuProgramParameter(
1136 "uCausticsPower", CausticsPower);
1139 mMaterialManager->setGpuProgramParameter(
1141 "uCausticsPower", CausticsPower);
1145 void Hydrax::setCausticsEnd(
const Ogre::Real &CausticsEnd)
1152 mCausticsEnd = CausticsEnd;
1154 mMaterialManager->setGpuProgramParameter(
1156 "uCausticsEnd", CausticsEnd);