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 mMaterialManager->updateAnimatedTextures(timeSinceLastFrame);
296 mModule->update(timeSinceLastFrame);
297 mDecalsManager->update();
298 _checkUnderwater(timeSinceLastFrame);
304 mComponents = Components;
335 HydraxLOG(
"Smooth component needs depth component... smooth component desactivated.");
339 HydraxLOG(
"Caustics component needs depth component... caustics component desactivated.");
343 HydraxLOG(
"God rays component needs depth component... god rays component desactivated.");
384 HydraxLOG(
"Underwater reflections component needs underwater component... underwater reflections component desactivated.");
388 HydraxLOG(
"God rays component needs underwater component... god rays component desactivated.");
396 HydraxLOG(
"God rays component needs sun component... god rays component desactivated.");
434 int NumberOfDepthChannels = 0;
438 NumberOfDepthChannels++;
442 NumberOfDepthChannels++;
447 NumberOfDepthChannels++;
451 if (NumberOfDepthChannels > 0)
456 if (!mCreated || !mModule)
463 mGodRaysManager->create(mComponents);
467 mGodRaysManager->remove();
501 getBuffer()->getRenderTarget()->getViewport(0)->
502 setSkiesEnabled(
false);
505 getBuffer()->getRenderTarget()->getViewport(0)->
506 setSkiesEnabled(
true);
509 mMesh->setMaterialName(
"BaseWhiteNoLighting");
514 mCurrentFrameUnderwater =
false;
517 mMesh->setMaterialName(mCurrentFrameUnderwater ?
521 if (mCurrentFrameUnderwater)
538 if (mModule->getNormalMode() ==
MaterialManager::NM_RTT && mModule->isCreated() && mModule->getNoise()->areGPUNormalMapResourcesCreated())
540 mModule->getNoise()->removeGPUNormalMapResources(mGPUNormalMapManager);
561 if (!mModule->isCreated())
567 if (!mModule->getNoise()->createGPUNormalMapResources(mGPUNormalMapManager))
569 HydraxLOG(mModule->getNoise()->getName() +
" doesn't support GPU Normal map generation.");
577 if (!mModule->getNoise()->areGPUNormalMapResourcesCreated())
579 if (!mModule->getNoise()->createGPUNormalMapResources(mGPUNormalMapManager))
581 HydraxLOG(mModule->getNoise()->getName() +
" doesn't support GPU Normal map generation.");
587 if (mModule->getNoise()->areGPUNormalMapResourcesCreated())
589 mModule->getNoise()->removeGPUNormalMapResources(mGPUNormalMapManager);
595 Ogre::String MaterialNameTmp = mMesh->getMaterialName();
602 mMesh->setOptions(mModule->getMeshOptions());
603 mMesh->setMaterialName(MaterialNameTmp);
614 if (mComponents & Component)
632 void Hydrax::_checkUnderwater(
const Ogre::Real& timeSinceLastFrame)
636 mCurrentFrameUnderwater =
false;
642 if (getHeigth(mCamera->getDerivedPosition()) > mCamera->getDerivedPosition().y-mUnderwaterCameraSwitchDelta)
644 mCurrentFrameUnderwater =
true;
649 getBuffer()->getRenderTarget()->getViewport(0)->
650 setSkiesEnabled(
true);
655 getBuffer()->getRenderTarget()->getViewport(0)->
656 setSkiesEnabled(
false);
683 mGodRaysManager->update(timeSinceLastFrame);
688 mCurrentFrameUnderwater =
false;
694 getBuffer()->getRenderTarget()->getViewport(0)->
695 setSkiesEnabled(
false);
704 getBuffer()->getRenderTarget()->getViewport(0)->
705 setSkiesEnabled(
true);
722 mPosition = Position;
731 mMaterialManager->setGpuProgramParameter(
733 "uPlaneYPos", Position.y);
736 mMesh->getSceneNode()->setPosition(Position.x-mMesh->getSize().Width/2, Position.y, Position.z-mMesh->getSize().Height/2);
737 mRttManager->getPlanesSceneNode()->setPosition(Position);
740 setSunPosition(mSunPosition);
743 void Hydrax::rotate(
const Ogre::Quaternion &q)
747 HydraxLOG(
"Hydrax::rotate(...) must be called after Hydrax::create(), skipping...");
752 mMesh->getSceneNode()->rotate(q);
753 mRttManager->getPlanesSceneNode()->rotate(q);
756 setSunPosition(mSunPosition);
759 void Hydrax::setPlanesError(
const Ogre::Real &PlanesError)
761 mPlanesError = PlanesError;
764 void Hydrax::_setStrength(
const Ogre::Real &Strength)
768 mMaterialManager->setGpuProgramParameter(
770 "uFoamRange", Strength);
774 mMaterialManager->setGpuProgramParameter(
776 "uFoamRange", Strength);
780 mDecalsManager->_setWaterStrength(Strength);
783 void Hydrax::setFullReflectionDistance(
const Ogre::Real &FullReflectionDistance)
785 mFullReflectionDistance = FullReflectionDistance;
787 mMaterialManager->setGpuProgramParameter(
789 "uFullReflectionDistance", FullReflectionDistance);
793 mMaterialManager->setGpuProgramParameter(
795 "uFullReflectionDistance", FullReflectionDistance);
799 void Hydrax::setGlobalTransparency(
const Ogre::Real &GlobalTransparency)
801 mGlobalTransparency = GlobalTransparency;
803 mMaterialManager->setGpuProgramParameter(
805 "uGlobalTransparency", GlobalTransparency);
809 mMaterialManager->setGpuProgramParameter(
811 "uGlobalTransparency", GlobalTransparency);
815 void Hydrax::setWaterColor(
const Ogre::Vector3 &WaterColor)
817 mWaterColor = WaterColor;
824 Ogre::ColourValue WC = Ogre::ColourValue(WaterColor.x, WaterColor.y, WaterColor.z);
829 getBuffer()->getRenderTarget()->getViewport(0)->
830 setBackgroundColour(WC);
833 getBuffer()->getRenderTarget()->getViewport(0)->
834 setBackgroundColour(WC);
841 mMaterialManager->setGpuProgramParameter(
843 "uWaterColor", WaterColor);
847 mMaterialManager->setGpuProgramParameter(
849 "uWaterColor", WaterColor);
868 void Hydrax::setNormalDistortion(
const Ogre::Real &NormalDistortion)
870 mNormalDistortion = NormalDistortion;
872 mMaterialManager->setGpuProgramParameter(
874 "uNormalDistortion", NormalDistortion);
878 mMaterialManager->setGpuProgramParameter(
880 "uNormalDistortion", NormalDistortion);
884 void Hydrax::setSunPosition(
const Ogre::Vector3 &SunPosition)
891 mSunPosition = SunPosition;
893 mMaterialManager->setGpuProgramParameter(
895 "uSunPosition", mMesh->getObjectSpacePosition(SunPosition));
899 mMaterialManager->setGpuProgramParameter(
901 "uSunPosition", mMesh->getObjectSpacePosition(SunPosition));
905 void Hydrax::setSunStrength(
const Ogre::Real &SunStrength)
912 mSunStrength = SunStrength;
914 mMaterialManager->setGpuProgramParameter(
916 "uSunStrength", SunStrength);
920 mMaterialManager->setGpuProgramParameter(
922 "uSunStrength", SunStrength);
926 void Hydrax::setSunArea(
const Ogre::Real &SunArea)
935 mMaterialManager->setGpuProgramParameter(
937 "uSunArea", SunArea);
941 mMaterialManager->setGpuProgramParameter(
943 "uSunArea", SunArea);
947 void Hydrax::setSunColor(
const Ogre::Vector3 &SunColor)
954 mSunColor = SunColor;
956 mMaterialManager->setGpuProgramParameter(
958 "uSunColor", SunColor);
962 mMaterialManager->setGpuProgramParameter(
964 "uSunColor", SunColor);
968 void Hydrax::setFoamMaxDistance(
const Ogre::Real &FoamMaxDistance)
975 mFoamMaxDistance = FoamMaxDistance;
977 mMaterialManager->setGpuProgramParameter(
979 "uFoamMaxDistance", FoamMaxDistance);
983 mMaterialManager->setGpuProgramParameter(
985 "uFoamMaxDistance", FoamMaxDistance);
989 void Hydrax::setFoamScale(
const Ogre::Real &FoamScale)
996 mFoamScale = FoamScale;
998 mMaterialManager->setGpuProgramParameter(
1000 "uFoamScale", FoamScale);
1004 mMaterialManager->setGpuProgramParameter(
1006 "uFoamScale", FoamScale);
1010 void Hydrax::setFoamStart(
const Ogre::Real &FoamStart)
1017 mFoamStart = FoamStart;
1019 mMaterialManager->setGpuProgramParameter(
1021 "uFoamStart", FoamStart);
1025 mMaterialManager->setGpuProgramParameter(
1027 "uFoamStart", FoamStart);
1031 void Hydrax::setFoamTransparency(
const Ogre::Real &FoamTransparency)
1038 mFoamTransparency = FoamTransparency;
1040 mMaterialManager->setGpuProgramParameter(
1042 "uFoamTransparency", FoamTransparency);
1046 mMaterialManager->setGpuProgramParameter(
1048 "uFoamTransparency", FoamTransparency);
1052 void Hydrax::setDepthLimit(
const Ogre::Real &DepthLimit)
1059 mDepthLimit = DepthLimit;
1061 if (mDepthLimit <= 0)
1066 mMaterialManager->setGpuProgramParameter(
1068 "uDepthLimit", 1/mDepthLimit);
1071 void Hydrax::setDistLimit(
const Ogre::Real &DistLimit)
1078 mDistLimit = DistLimit;
1080 if (mDistLimit <= 0)
1085 mMaterialManager->setGpuProgramParameter(
1087 "uDistLimit", 1/mDistLimit);
1090 void Hydrax::setSmoothPower(
const Ogre::Real &SmoothPower)
1097 mSmoothPower = SmoothPower;
1099 mMaterialManager->setGpuProgramParameter(
1101 "uSmoothPower", SmoothPower);
1104 void Hydrax::setCausticsScale(
const Ogre::Real &CausticsScale)
1111 mCausticsScale = CausticsScale;
1113 mMaterialManager->setGpuProgramParameter(
1115 "uCausticsScale", CausticsScale);
1118 void Hydrax::setCausticsPower(
const Ogre::Real &CausticsPower)
1125 mCausticsPower = CausticsPower;
1127 mMaterialManager->setGpuProgramParameter(
1129 "uCausticsPower", CausticsPower);
1135 mMaterialManager->setGpuProgramParameter(
1137 "uCausticsPower", CausticsPower);
1140 mMaterialManager->setGpuProgramParameter(
1142 "uCausticsPower", CausticsPower);
1146 void Hydrax::setCausticsEnd(
const Ogre::Real &CausticsEnd)
1153 mCausticsEnd = CausticsEnd;
1155 mMaterialManager->setGpuProgramParameter(
1157 "uCausticsEnd", CausticsEnd);