RigsofRods
Soft-body Physics Simulation
Hydrax.cpp
Go to the documentation of this file.
1 /*
2 --------------------------------------------------------------------------------
3 This source file is part of Hydrax.
4 Visit ---
5 
6 Copyright (C) 2008 Xavier Verguín González <xavierverguin@hotmail.com>
7  <xavyiy@gmail.com>
8 
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
12 version.
13 
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.
17 
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 --------------------------------------------------------------------------------
23 
24 --------------------------------------------------------------------------------
25 Contributors:
26  Jose Luis Cercós Pita <jlcercos@alumnos.upm.es>
27 --------------------------------------------------------------------------------
28 */
29 
30 #pragma warning(disable:4355)
31 
32 #include <Hydrax.h>
33 
34 namespace Hydrax
35 {
36 
37  Hydrax::Hydrax(Ogre::SceneManager *sm, Ogre::Camera *c, Ogre::Viewport *v)
38  : mSceneManager(sm)
39  , mCamera(c)
40  , mViewport(v)
41  , mCreated(false)
42  , mVisible(true)
43  , mPolygonMode(Ogre::PM_SOLID)
44  , mShaderMode(MaterialManager::SM_HLSL)
45  , mPosition(Ogre::Vector3(0,0,0))
46  , mPlanesError(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))
52  , mSunStrength(1.75)
53  , mSunArea(150)
54  , mSunColor(Ogre::Vector3(1,0.75,0.25))
55  , mFoamMaxDistance(75000000.0)
56  , mFoamScale(0.0075)
57  , mFoamStart(0)
58  , mFoamTransparency(1)
59  , mDepthLimit(0)
60  , mSmoothPower(30)
61  , mCausticsScale(20)
62  , mCausticsPower(15)
63  , mCausticsEnd(0.55)
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))
69  , mMaterialManager(new MaterialManager(this))
70  , mRttManager(new RttManager(this))
71  , mTextureManager(new TextureManager(this))
72  , mGodRaysManager(new GodRaysManager(this))
73  , mDecalsManager(new DecalsManager(this))
74  , mGPUNormalMapManager(new GPUNormalMapManager(this))
75  , mCfgFileManager(new CfgFileManager(this))
76  , mModule(0)
77  , mComponents(HYDRAX_COMPONENTS_NONE)
78  {
79  HydraxLOG("Hydrax created.");
80  }
81 
82  Hydrax::~Hydrax()
83  {
84  remove();
85 
86  if (mModule)
87  {
88  delete mModule;
89  }
90 
91  delete mTextureManager;
92  delete mMaterialManager;
93  delete mGPUNormalMapManager;
94  delete mDecalsManager;
95  delete mGodRaysManager;
96  delete mRttManager;
97  delete mCfgFileManager;
98  delete mMesh;
99 
100  HydraxLOG("Hydrax object removed.");
101  }
102 
103  void Hydrax::create()
104  {
105  if (!mModule)
106  {
107  HydraxLOG("Module isn't set, skipping...");
108 
109  return;
110  }
111 
112  if (mCreated)
113  {
114  HydraxLOG("Hydrax is alredy created, skipping...");
115 
116  return;
117  }
118 
119  HydraxLOG("Creating module...");
120  mModule->create();
121 
122  if (mModule->getNormalMode() == MaterialManager::NM_RTT)
123  {
124  if (!mModule->getNoise()->createGPUNormalMapResources(mGPUNormalMapManager))
125  {
126  HydraxLOG(mModule->getNoise()->getName() + " doesn't support GPU Normal map generation.");
127  }
128  }
129  else
130  {
131  if (mModule->getNoise()->areGPUNormalMapResourcesCreated())
132  {
133  mModule->getNoise()->removeGPUNormalMapResources(mGPUNormalMapManager);
134  }
135  }
136  HydraxLOG("Module created.");
137 
138  HydraxLOG("Initializating RTT Manager...");
139  mRttManager->initialize(RttManager::RTT_REFLECTION);
140  mRttManager->initialize(RttManager::RTT_REFRACTION);
141  if (isComponent(HYDRAX_COMPONENT_DEPTH))
142  {
143  mRttManager->initialize(RttManager::RTT_DEPTH);
144  }
145  HydraxLOG("RTT manager initialized.");
146 
147  HydraxLOG("Registring device restored listener...");
148  mDeviceListener.mHydrax = this;
149  Ogre::Root::getSingleton().getRenderSystem()->addListener(&mDeviceListener);
150  HydraxLOG("Device restored listener registred.");
151 
152  HydraxLOG("Creating materials...");
153  mMaterialManager->createMaterials(mComponents, MaterialManager::Options(mShaderMode, mModule->getNormalMode()));
154  mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName());
155  HydraxLOG("Materials created.");
156 
157  if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
158  {
159  HydraxLOG("Creating god rays...");
160  mGodRaysManager->create(mComponents);
161  HydraxLOG("God rays created.");
162  }
163 
164  HydraxLOG("Creating water mesh...");
165  mMesh->setOptions(mModule->getMeshOptions());
166  mMesh->create();
167  HydraxLOG("Water mesh created.");
168 
169  mCreated = true;
170 
171  // Hide if !mVisible
172  _checkVisible();
173  // Check for underwater
174  _checkUnderwater(0);
175  }
176 
177  void Hydrax::remove()
178  {
179  if (!mCreated)
180  {
181  return;
182  }
183 
184  Ogre::Root::getSingleton().getRenderSystem()->removeListener(&mDeviceListener);
185 
186  mMesh->remove();
187  mDecalsManager->removeAll();
188  mMaterialManager->removeMaterials();
189  mRttManager->removeAll();
190  mGodRaysManager->remove();
191  mModule->remove();
192  mTextureManager->remove();
193 
194  mCreated = false;
195  }
196 
197  void Hydrax::setVisible(const bool& Visible)
198  {
199  mVisible = Visible;
200 
201  _checkVisible();
202  }
203 
204  void Hydrax::_checkVisible()
205  {
206  if (!mCreated)
207  {
208  return;
209  }
210 
211  if (!mVisible)
212  {
213  // Stop RTTs:
214  mRttManager->removeAll();
215 
216  // Hide hydrax mesh
217  mMesh->getSceneNode()->setVisible(false);
218 
219  // Stop compositor (MaterialManager::setCompositorEnable(...) checks if underwater compositor exists)
220  mMaterialManager->setCompositorEnable(MaterialManager::COMP_UNDERWATER, false);
221  }
222  else
223  {
224  // Start reflection and refraction RTTs:
225  mRttManager->initialize(RttManager::RTT_REFLECTION);
226  mRttManager->initialize(RttManager::RTT_REFRACTION);
227 
228  // Start depth rtt if needed:
229  if (isComponent(HYDRAX_COMPONENT_DEPTH))
230  {
231  mRttManager->initialize(RttManager::RTT_DEPTH);
232  }
233 
234  // Start GPU normals rtt if needed:
235  if (mModule->getNormalMode() == MaterialManager::NM_RTT)
236  {
237  mGPUNormalMapManager->create();
238  }
239 
240  // Set over-water material and check for underwater:
241  mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName());
242  mMaterialManager->reload(MaterialManager::MAT_WATER);
243 
244  _checkUnderwater(0);
245 
246  // Set hydrax mesh node visible
247  mMesh->getSceneNode()->setVisible(true);
248  }
249  }
250 
251  void Hydrax::DeviceListener::eventOccurred(const Ogre::String& eventName, const Ogre::NameValuePairList *parameters)
252  {
253  // If needed...
254 
255  if (eventName == "DeviceLost")
256  {}
257 
258  if (eventName == "DeviceRestored")
259  {}
260  }
261 
262  void Hydrax::setPolygonMode(const Ogre::PolygonMode& PM)
263  {
264  if (!mCreated)
265  {
266  return;
267  }
268 
269  mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getTechnique(0)->getPass(0)->setPolygonMode(PM);
270 
271  if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
272  {
273  mMaterialManager->getMaterial(MaterialManager::MAT_UNDERWATER)->getTechnique(0)->getPass(0)->setPolygonMode(PM);
274  }
275 
276  mPolygonMode = PM;
277  }
278 
279  void Hydrax::setShaderMode(const MaterialManager::ShaderMode& ShaderMode)
280  {
281  mShaderMode = ShaderMode;
282 
283  if (mCreated && mModule)
284  {
285  mMaterialManager->createMaterials(mComponents, MaterialManager::Options(mShaderMode, mModule->getNormalMode()));
286 
287  mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName());
288  }
289  }
290 
291  void Hydrax::update(const Ogre::Real &timeSinceLastFrame)
292  {
293  if (mCreated && mModule && mVisible)
294  {
295  mModule->update(timeSinceLastFrame);
296  mDecalsManager->update();
297  _checkUnderwater(timeSinceLastFrame);
298  }
299  }
300 
301  void Hydrax::setComponents(const HydraxComponent &Components)
302  {
303  mComponents = Components;
304 
305  if (isComponent(HYDRAX_COMPONENT_SMOOTH) || isComponent(HYDRAX_COMPONENT_CAUSTICS) || isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
306  {
307  // Delete smooth and/or caustics components wich needs depth component
308  if (!isComponent(HYDRAX_COMPONENT_DEPTH))
309  {
314 
315  if (isComponent(HYDRAX_COMPONENT_SUN))
316  {
318  }
319  if (isComponent(HYDRAX_COMPONENT_FOAM))
320  {
322  }
323  if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
324  {
326  }
328  {
330  }
331 
332  if (isComponent(HYDRAX_COMPONENT_SMOOTH))
333  {
334  HydraxLOG("Smooth component needs depth component... smooth component desactivated.");
335  }
336  if (isComponent(HYDRAX_COMPONENT_CAUSTICS))
337  {
338  HydraxLOG("Caustics component needs depth component... caustics component desactivated.");
339  }
340  if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
341  {
342  HydraxLOG("God rays component needs depth component... god rays component desactivated.");
343  }
344 
345  mComponents = static_cast<HydraxComponent>(s|f|u|ur);
346  }
347  }
348 
350  {
351  // Delete underwater reflections components wich needs underwater component
352  if (!isComponent(HYDRAX_COMPONENT_UNDERWATER))
353  {
359 
360  if (isComponent(HYDRAX_COMPONENT_SUN))
361  {
363  }
364  if (isComponent(HYDRAX_COMPONENT_FOAM))
365  {
367  }
368  if (isComponent(HYDRAX_COMPONENT_DEPTH))
369  {
371  }
372  if (isComponent(HYDRAX_COMPONENT_SMOOTH))
373  {
375  }
376  if (isComponent(HYDRAX_COMPONENT_CAUSTICS))
377  {
379  }
380 
382  {
383  HydraxLOG("Underwater reflections component needs underwater component... underwater reflections component desactivated.");
384  }
385  if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
386  {
387  HydraxLOG("God rays component needs underwater component... god rays component desactivated.");
388  }
389 
390  mComponents = static_cast<HydraxComponent>(s|f|d|sm|c);
391  }
392 
393  if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS) && !isComponent(HYDRAX_COMPONENT_SUN))
394  {
395  HydraxLOG("God rays component needs sun component... god rays component desactivated.");
396 
403 
404  if (isComponent(HYDRAX_COMPONENT_FOAM))
405  {
407  }
408  if (isComponent(HYDRAX_COMPONENT_DEPTH))
409  {
411  }
412  if (isComponent(HYDRAX_COMPONENT_SMOOTH))
413  {
415  }
416  if (isComponent(HYDRAX_COMPONENT_CAUSTICS))
417  {
419  }
420  if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
421  {
423  }
425  {
427  }
428 
429  mComponents = static_cast<HydraxComponent>(f|d|sm|c|u|ur);
430  }
431  }
432 
433  int NumberOfDepthChannels = 0;
434 
435  if (isComponent(HYDRAX_COMPONENT_DEPTH))
436  {
437  NumberOfDepthChannels++;
438 
439  if (isComponent(HYDRAX_COMPONENT_CAUSTICS))
440  {
441  NumberOfDepthChannels++;
442  }
443 
444  if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
445  {
446  NumberOfDepthChannels++;
447  }
448  }
449 
450  if (NumberOfDepthChannels > 0)
451  {
452  mRttManager->setNumberOfChannels(RttManager::RTT_DEPTH, static_cast<RttManager::NumberOfChannels>(NumberOfDepthChannels));
453  }
454 
455  if (!mCreated || !mModule)
456  {
457  return;
458  }
459 
460  if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
461  {
462  mGodRaysManager->create(mComponents);
463  }
464  else
465  {
466  mGodRaysManager->remove();
467  }
468 
469  // Check for Rtt's
470  if (mCurrentFrameUnderwater && isComponent(HYDRAX_COMPONENT_UNDERWATER) && !isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS))
471  {
472  mRttManager->remove(RttManager::RTT_REFLECTION);
473  }
474  else
475  {
476  mRttManager->initialize(RttManager::RTT_REFLECTION);
477  }
478 
479  if (!isComponent(HYDRAX_COMPONENT_DEPTH))
480  {
481  mRttManager->remove(RttManager::RTT_DEPTH);
482  mRttManager->remove(RttManager::RTT_DEPTH_REFLECTION);
483  }
484  else
485  {
486  mRttManager->initialize(RttManager::RTT_DEPTH);
487 
488  if (isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS) && mCurrentFrameUnderwater)
489  {
490  mRttManager->initialize(RttManager::RTT_DEPTH_REFLECTION);
491  }
492  else
493  {
494  mRttManager->remove(RttManager::RTT_DEPTH_REFLECTION);
495  }
496  }
497  if (!isComponent(HYDRAX_COMPONENT_UNDERWATER) && mCurrentFrameUnderwater)
498  {
499  mRttManager->getTexture(RttManager::RTT_REFRACTION)->
500  getBuffer()->getRenderTarget()->getViewport(0)->
501  setSkiesEnabled(false);
502 
503  mRttManager->getTexture(RttManager::RTT_REFLECTION)->
504  getBuffer()->getRenderTarget()->getViewport(0)->
505  setSkiesEnabled(true);
506  }
507 
508  mMesh->setMaterialName("BaseWhiteNoLighting");
509  mMaterialManager->createMaterials(mComponents, MaterialManager::Options(mShaderMode, mModule->getNormalMode()));
510 
511  if (!isComponent(HYDRAX_COMPONENT_UNDERWATER))
512  {
513  mCurrentFrameUnderwater = false;
514  }
515 
516  mMesh->setMaterialName(mCurrentFrameUnderwater ?
517  mMaterialManager->getMaterial(MaterialManager::MAT_UNDERWATER)->getName() :
518  mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName());
519 
520  if (mCurrentFrameUnderwater)
521  {
522  mMaterialManager->setCompositorEnable(MaterialManager::COMP_UNDERWATER, true);
523  }
524  }
525 
526  void Hydrax::setModule(Module::Module* Module, const bool& DeleteOldModule)
527  {
528  if (mModule)
529  {
530  if (mModule->getNormalMode() != Module->getNormalMode())
531  {
532  mMaterialManager->createMaterials(mComponents, MaterialManager::Options(mShaderMode, Module->getNormalMode()));
533 
534  mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName());
535  }
536 
537  if (mModule->getNormalMode() == MaterialManager::NM_RTT && mModule->isCreated() && mModule->getNoise()->areGPUNormalMapResourcesCreated())
538  {
539  mModule->getNoise()->removeGPUNormalMapResources(mGPUNormalMapManager);
540  }
541 
542  if (DeleteOldModule)
543  {
544  delete mModule;
545  }
546  else
547  {
548  mModule->remove();
549  }
550 
551  // Due to modules can change -internally- scene nodes position,
552  // just reset them to the original position.
553  setPosition(mPosition);
554  }
555 
556  mModule = Module;
557 
558  if (mCreated)
559  {
560  if (!mModule->isCreated())
561  {
562  mModule->create();
563 
564  if (mModule->getNormalMode() == MaterialManager::NM_RTT)
565  {
566  if (!mModule->getNoise()->createGPUNormalMapResources(mGPUNormalMapManager))
567  {
568  HydraxLOG(mModule->getNoise()->getName() + " doesn't support GPU Normal map generation.");
569  }
570  }
571  }
572  else
573  {
574  if (mModule->getNormalMode() == MaterialManager::NM_RTT)
575  {
576  if (!mModule->getNoise()->areGPUNormalMapResourcesCreated())
577  {
578  if (!mModule->getNoise()->createGPUNormalMapResources(mGPUNormalMapManager))
579  {
580  HydraxLOG(mModule->getNoise()->getName() + " doesn't support GPU Normal map generation.");
581  }
582  }
583  }
584  else
585  {
586  if (mModule->getNoise()->areGPUNormalMapResourcesCreated())
587  {
588  mModule->getNoise()->removeGPUNormalMapResources(mGPUNormalMapManager);
589  }
590  }
591  }
592 
593  HydraxLOG("Updating water mesh...");
594  Ogre::String MaterialNameTmp = mMesh->getMaterialName();
595 
596  HydraxLOG("Deleting water mesh...");
597  mMesh->remove();
598  HydraxLOG("Water mesh deleted.");
599 
600  HydraxLOG("Creating water mesh...");
601  mMesh->setOptions(mModule->getMeshOptions());
602  mMesh->setMaterialName(MaterialNameTmp);
603  mMesh->create();
604  setPosition(mPosition);
605  HydraxLOG("Water mesh created.");
606 
607  HydraxLOG("Module set.");
608  }
609  }
610 
611  bool Hydrax::isComponent(const HydraxComponent &Component)
612  {
613  if (mComponents & Component)
614  {
615  return true;
616  }
617 
618  if (Component == HYDRAX_COMPONENTS_NONE && mComponents == HYDRAX_COMPONENTS_NONE)
619  {
620  return true;
621  }
622 
623  if (Component == HYDRAX_COMPONENTS_ALL && mComponents == HYDRAX_COMPONENTS_ALL)
624  {
625  return true;
626  }
627 
628  return false;
629  }
630 
631  void Hydrax::_checkUnderwater(const Ogre::Real& timeSinceLastFrame)
632  {
633  if (!isComponent(HYDRAX_COMPONENT_UNDERWATER))
634  {
635  mCurrentFrameUnderwater = false;
636 
637  return;
638  }
639 
640  // If the camera is under the current water x/z position
641  if (getHeigth(mCamera->getDerivedPosition()) > mCamera->getDerivedPosition().y-mUnderwaterCameraSwitchDelta)
642  {
643  mCurrentFrameUnderwater = true;
644 
645  if (mMesh->getMaterialName() != mMaterialManager->getMaterial(MaterialManager::MAT_UNDERWATER)->getName())
646  {
647  mRttManager->getTexture(RttManager::RTT_REFRACTION)->
648  getBuffer()->getRenderTarget()->getViewport(0)->
649  setSkiesEnabled(true);
650 
652  {
653  mRttManager->getTexture(RttManager::RTT_REFLECTION)->
654  getBuffer()->getRenderTarget()->getViewport(0)->
655  setSkiesEnabled(false);
656 
657  if (isComponent(HYDRAX_COMPONENT_DEPTH))
658  {
659  mRttManager->initialize(RttManager::RTT_DEPTH_REFLECTION);
660  }
661  }
662  else
663  {
664  mRttManager->remove(RttManager::RTT_REFLECTION);
665  }
666 
667  if (isComponent(HYDRAX_COMPONENT_DEPTH) && isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS))
668  {
669  mRttManager->initialize(RttManager::RTT_DEPTH_REFLECTION);
670  }
671 
672  mMaterialManager->reload(MaterialManager::MAT_UNDERWATER);
673 
674  mMaterialManager->setCompositorEnable(MaterialManager::COMP_UNDERWATER, true);
675 
676  mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_UNDERWATER)->getName());
677  }
678 
679  // Update god rays
680  if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
681  {
682  mGodRaysManager->update(timeSinceLastFrame);
683  }
684  }
685  else
686  {
687  mCurrentFrameUnderwater = false;
688 
689  if (mMesh->getMaterialName() != mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName())
690  {
691  // We asume that RefractionRtt/ReflectionRtt are initialized
692  mRttManager->getTexture(RttManager::RTT_REFRACTION)->
693  getBuffer()->getRenderTarget()->getViewport(0)->
694  setSkiesEnabled(false);
695 
696  if (!isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS))
697  {
698  mRttManager->initialize(RttManager::RTT_REFLECTION);
699  mMaterialManager->reload(MaterialManager::MAT_WATER);
700  }
701 
702  mRttManager->getTexture(RttManager::RTT_REFLECTION)->
703  getBuffer()->getRenderTarget()->getViewport(0)->
704  setSkiesEnabled(true);
705 
706  if (isComponent(HYDRAX_COMPONENT_DEPTH) && isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS))
707  {
708  mRttManager->remove(RttManager::RTT_DEPTH_REFLECTION);
709  }
710 
711  mMaterialManager->setCompositorEnable(MaterialManager::COMP_UNDERWATER, false);
712 
713  mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName());
714  }
715  }
716 
717  }
718 
719  void Hydrax::setPosition(const Ogre::Vector3 &Position)
720  {
721  mPosition = Position;
722 
723  if (!mCreated)
724  {
725  return;
726  }
727 
728  if (isComponent(HYDRAX_COMPONENT_DEPTH))
729  {
730  mMaterialManager->setGpuProgramParameter(
732  "uPlaneYPos", Position.y);
733  }
734 
735  mMesh->getSceneNode()->setPosition(Position.x-mMesh->getSize().Width/2, Position.y, Position.z-mMesh->getSize().Height/2);
736  mRttManager->getPlanesSceneNode()->setPosition(Position);
737 
738  // For world-space -> object-space conversion
739  setSunPosition(mSunPosition);
740  }
741 
742  void Hydrax::rotate(const Ogre::Quaternion &q)
743  {
744  if (!mCreated)
745  {
746  HydraxLOG("Hydrax::rotate(...) must be called after Hydrax::create(), skipping...");
747 
748  return;
749  }
750 
751  mMesh->getSceneNode()->rotate(q);
752  mRttManager->getPlanesSceneNode()->rotate(q);
753 
754  // For world-space -> object-space conversion
755  setSunPosition(mSunPosition);
756  }
757 
758  void Hydrax::setPlanesError(const Ogre::Real &PlanesError)
759  {
760  mPlanesError = PlanesError;
761  }
762 
763  void Hydrax::_setStrength(const Ogre::Real &Strength)
764  {
765  if (isComponent(HYDRAX_COMPONENT_FOAM))
766  {
767  mMaterialManager->setGpuProgramParameter(
769  "uFoamRange", Strength);
770 
771  if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
772  {
773  mMaterialManager->setGpuProgramParameter(
775  "uFoamRange", Strength);
776  }
777  }
778 
779  mDecalsManager->_setWaterStrength(Strength);
780  }
781 
782  void Hydrax::setFullReflectionDistance(const Ogre::Real &FullReflectionDistance)
783  {
784  mFullReflectionDistance = FullReflectionDistance;
785 
786  mMaterialManager->setGpuProgramParameter(
788  "uFullReflectionDistance", FullReflectionDistance);
789 
790  if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
791  {
792  mMaterialManager->setGpuProgramParameter(
794  "uFullReflectionDistance", FullReflectionDistance);
795  }
796  }
797 
798  void Hydrax::setGlobalTransparency(const Ogre::Real &GlobalTransparency)
799  {
800  mGlobalTransparency = GlobalTransparency;
801 
802  mMaterialManager->setGpuProgramParameter(
804  "uGlobalTransparency", GlobalTransparency);
805 
806  if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
807  {
808  mMaterialManager->setGpuProgramParameter(
810  "uGlobalTransparency", GlobalTransparency);
811  }
812  }
813 
814  void Hydrax::setWaterColor(const Ogre::Vector3 &WaterColor)
815  {
816  mWaterColor = WaterColor;
817 
818  if (!mCreated)
819  {
820  return;
821  }
822 
823  Ogre::ColourValue WC = Ogre::ColourValue(WaterColor.x, WaterColor.y, WaterColor.z);
824 
825  if (isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS) || !_isCurrentFrameUnderwater())
826  {
827  mRttManager->getTexture(RttManager::RTT_REFLECTION)->
828  getBuffer()->getRenderTarget()->getViewport(0)->
829  setBackgroundColour(WC);
830  }
831  mRttManager->getTexture(RttManager::RTT_REFRACTION)->
832  getBuffer()->getRenderTarget()->getViewport(0)->
833  setBackgroundColour(WC);
834 
835  if (!isComponent(HYDRAX_COMPONENT_DEPTH))
836  {
837  return;
838  }
839 
840  mMaterialManager->setGpuProgramParameter(
842  "uWaterColor", WaterColor);
843 
844  if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
845  {
846  mMaterialManager->setGpuProgramParameter(
848  "uWaterColor", WaterColor);
849 
850  //mMaterialManager->getCompositor(MaterialManager::COMP_UNDERWATER)->
851  // getTechnique(0)->getTargetPass(0)->getPass(0)->setClearColour(WC);
852 
853  /* Active creation/destruction
854  if (getHeigth(mCamera->getDerivedPosition()) > mCamera->getDerivedPosition().y-1.25f)
855  {
856  if (mMaterialManager->isCompositorEnable(MaterialManager::COMP_UNDERWATER))
857  {
858  mMaterialManager->setCompositorEnable(MaterialManager::COMP_UNDERWATER, false);
859  mMaterialManager->setCompositorEnable(MaterialManager::COMP_UNDERWATER, true);
860  }
861  }
862  */
863  }
864  }
865 
866 
867  void Hydrax::setNormalDistortion(const Ogre::Real &NormalDistortion)
868  {
869  mNormalDistortion = NormalDistortion;
870 
871  mMaterialManager->setGpuProgramParameter(
873  "uNormalDistortion", NormalDistortion);
874 
875  if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
876  {
877  mMaterialManager->setGpuProgramParameter(
879  "uNormalDistortion", NormalDistortion);
880  }
881  }
882 
883  void Hydrax::setSunPosition(const Ogre::Vector3 &SunPosition)
884  {
885  if (!isComponent(HYDRAX_COMPONENT_SUN))
886  {
887  return;
888  }
889 
890  mSunPosition = SunPosition;
891 
892  mMaterialManager->setGpuProgramParameter(
894  "uSunPosition", mMesh->getObjectSpacePosition(SunPosition));
895 
896  if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
897  {
898  mMaterialManager->setGpuProgramParameter(
900  "uSunPosition", mMesh->getObjectSpacePosition(SunPosition));
901  }
902  }
903 
904  void Hydrax::setSunStrength(const Ogre::Real &SunStrength)
905  {
906  if (!isComponent(HYDRAX_COMPONENT_SUN))
907  {
908  return;
909  }
910 
911  mSunStrength = SunStrength;
912 
913  mMaterialManager->setGpuProgramParameter(
915  "uSunStrength", SunStrength);
916 
917  if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
918  {
919  mMaterialManager->setGpuProgramParameter(
921  "uSunStrength", SunStrength);
922  }
923  }
924 
925  void Hydrax::setSunArea(const Ogre::Real &SunArea)
926  {
927  if (!isComponent(HYDRAX_COMPONENT_SUN))
928  {
929  return;
930  }
931 
932  mSunArea = SunArea;
933 
934  mMaterialManager->setGpuProgramParameter(
936  "uSunArea", SunArea);
937 
938  if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
939  {
940  mMaterialManager->setGpuProgramParameter(
942  "uSunArea", SunArea);
943  }
944  }
945 
946  void Hydrax::setSunColor(const Ogre::Vector3 &SunColor)
947  {
948  if (!isComponent(HYDRAX_COMPONENT_SUN))
949  {
950  return;
951  }
952 
953  mSunColor = SunColor;
954 
955  mMaterialManager->setGpuProgramParameter(
957  "uSunColor", SunColor);
958 
959  if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
960  {
961  mMaterialManager->setGpuProgramParameter(
963  "uSunColor", SunColor);
964  }
965  }
966 
967  void Hydrax::setFoamMaxDistance(const Ogre::Real &FoamMaxDistance)
968  {
969  if (!isComponent(HYDRAX_COMPONENT_FOAM))
970  {
971  return;
972  }
973 
974  mFoamMaxDistance = FoamMaxDistance;
975 
976  mMaterialManager->setGpuProgramParameter(
978  "uFoamMaxDistance", FoamMaxDistance);
979 
980  if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
981  {
982  mMaterialManager->setGpuProgramParameter(
984  "uFoamMaxDistance", FoamMaxDistance);
985  }
986  }
987 
988  void Hydrax::setFoamScale(const Ogre::Real &FoamScale)
989  {
990  if (!isComponent(HYDRAX_COMPONENT_FOAM))
991  {
992  return;
993  }
994 
995  mFoamScale = FoamScale;
996 
997  mMaterialManager->setGpuProgramParameter(
999  "uFoamScale", FoamScale);
1000 
1001  if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
1002  {
1003  mMaterialManager->setGpuProgramParameter(
1005  "uFoamScale", FoamScale);
1006  }
1007  }
1008 
1009  void Hydrax::setFoamStart(const Ogre::Real &FoamStart)
1010  {
1011  if (!isComponent(HYDRAX_COMPONENT_FOAM))
1012  {
1013  return;
1014  }
1015 
1016  mFoamStart = FoamStart;
1017 
1018  mMaterialManager->setGpuProgramParameter(
1020  "uFoamStart", FoamStart);
1021 
1022  if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
1023  {
1024  mMaterialManager->setGpuProgramParameter(
1026  "uFoamStart", FoamStart);
1027  }
1028  }
1029 
1030  void Hydrax::setFoamTransparency(const Ogre::Real &FoamTransparency)
1031  {
1032  if (!isComponent(HYDRAX_COMPONENT_FOAM))
1033  {
1034  return;
1035  }
1036 
1037  mFoamTransparency = FoamTransparency;
1038 
1039  mMaterialManager->setGpuProgramParameter(
1041  "uFoamTransparency", FoamTransparency);
1042 
1043  if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
1044  {
1045  mMaterialManager->setGpuProgramParameter(
1047  "uFoamTransparency", FoamTransparency);
1048  }
1049  }
1050 
1051  void Hydrax::setDepthLimit(const Ogre::Real &DepthLimit)
1052  {
1053  if (!isComponent(HYDRAX_COMPONENT_DEPTH))
1054  {
1055  return;
1056  }
1057 
1058  mDepthLimit = DepthLimit;
1059 
1060  if (mDepthLimit <= 0)
1061  {
1062  mDepthLimit = 1;
1063  }
1064 
1065  mMaterialManager->setGpuProgramParameter(
1067  "uDepthLimit", 1/mDepthLimit);
1068  }
1069 
1070  void Hydrax::setDistLimit(const Ogre::Real &DistLimit)
1071  {
1072  if (!isComponent(HYDRAX_COMPONENT_DEPTH))
1073  {
1074  return;
1075  }
1076 
1077  mDistLimit = DistLimit;
1078 
1079  if (mDistLimit <= 0)
1080  {
1081  mDistLimit = 1;
1082  }
1083 
1084  mMaterialManager->setGpuProgramParameter(
1086  "uDistLimit", 1/mDistLimit);
1087  }
1088 
1089  void Hydrax::setSmoothPower(const Ogre::Real &SmoothPower)
1090  {
1091  if (!isComponent(HYDRAX_COMPONENT_SMOOTH))
1092  {
1093  return;
1094  }
1095 
1096  mSmoothPower = SmoothPower;
1097 
1098  mMaterialManager->setGpuProgramParameter(
1100  "uSmoothPower", SmoothPower);
1101  }
1102 
1103  void Hydrax::setCausticsScale(const Ogre::Real &CausticsScale)
1104  {
1105  if (!isComponent(HYDRAX_COMPONENT_CAUSTICS))
1106  {
1107  return;
1108  }
1109 
1110  mCausticsScale = CausticsScale;
1111 
1112  mMaterialManager->setGpuProgramParameter(
1114  "uCausticsScale", CausticsScale);
1115  }
1116 
1117  void Hydrax::setCausticsPower(const Ogre::Real &CausticsPower)
1118  {
1119  if (!isComponent(HYDRAX_COMPONENT_CAUSTICS))
1120  {
1121  return;
1122  }
1123 
1124  mCausticsPower = CausticsPower;
1125 
1126  mMaterialManager->setGpuProgramParameter(
1128  "uCausticsPower", CausticsPower);
1129 
1130  if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
1131  {
1132  if (isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS))
1133  {
1134  mMaterialManager->setGpuProgramParameter(
1136  "uCausticsPower", CausticsPower);
1137  }
1138 
1139  mMaterialManager->setGpuProgramParameter(
1141  "uCausticsPower", CausticsPower);
1142  }
1143  }
1144 
1145  void Hydrax::setCausticsEnd(const Ogre::Real &CausticsEnd)
1146  {
1147  if (!isComponent(HYDRAX_COMPONENT_CAUSTICS))
1148  {
1149  return;
1150  }
1151 
1152  mCausticsEnd = CausticsEnd;
1153 
1154  mMaterialManager->setGpuProgramParameter(
1156  "uCausticsEnd", CausticsEnd);
1157  }
1158 }
Hydrax::MaterialManager::MAT_UNDERWATER
@ MAT_UNDERWATER
Definition: MaterialManager.h:57
Hydrax::HYDRAX_COMPONENT_FOAM
@ HYDRAX_COMPONENT_FOAM
Definition: Enums.h:60
Hydrax::HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS
@ HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS
Underwater reflections and god rays need underwater component.
Definition: Enums.h:67
Hydrax::HYDRAX_COMPONENTS_ALL
@ HYDRAX_COMPONENTS_ALL
Definition: Enums.h:71
Hydrax::TextureManager
Class for manager Normal maps.
Definition: TextureManager.h:45
Hydrax
Definition: CfgFileManager.cpp:28
Hydrax::HYDRAX_COMPONENT_SUN
@ HYDRAX_COMPONENT_SUN
Definition: Enums.h:59
Hydrax::DecalsManager
Decals manager class.
Definition: DecalsManager.h:202
Hydrax::RttManager::NumberOfChannels
NumberOfChannels
Number of channels.
Definition: RttManager.h:71
Hydrax.h
Hydrax::RttManager::RTT_REFLECTION
@ RTT_REFLECTION
Definition: RttManager.h:52
Hydrax::MaterialManager
Material/Shader manager class.
Definition: MaterialManager.h:44
Hydrax::MaterialManager::MAT_DEPTH
@ MAT_DEPTH
Definition: MaterialManager.h:55
Hydrax::MaterialManager::COMP_UNDERWATER
@ COMP_UNDERWATER
Definition: MaterialManager.h:72
Hydrax::Hydrax::DeviceListener::eventOccurred
void eventOccurred(const Ogre::String &eventName, const Ogre::NameValuePairList *parameters)
Event occurred.
Definition: Hydrax.cpp:251
Hydrax::MaterialManager::Options
Material options.
Definition: MaterialManager.h:112
Hydrax::GPUNormalMapManager
Class to manager GPU normal maps.
Definition: GPUNormalMapManager.h:45
Hydrax::Module::Module::create
virtual void create()
Create.
Definition: Module.cpp:46
Hydrax::HYDRAX_COMPONENT_DEPTH
@ HYDRAX_COMPONENT_DEPTH
Definition: Enums.h:61
Hydrax::RttManager::RTT_DEPTH
@ RTT_DEPTH
Definition: RttManager.h:54
HydraxLOG
#define HydraxLOG(msg)
Definition: Application.h:59
Hydrax::MaterialManager::GPUP_FRAGMENT
@ GPUP_FRAGMENT
Definition: MaterialManager.h:83
Hydrax::Module::Module
Base module class, Override it for create different ways of create water noise.
Definition: Module.h:46
Hydrax::Mesh
Class wich contains all funtions/variables related to Hydrax water mesh.
Definition: Mesh.h:46
Hydrax::RttManager
Rtt's manager class.
Definition: RttManager.h:45
Hydrax::Hydrax
Main Hydrax class.
Definition: Hydrax.h:56
Hydrax::GodRaysManager
Underwater god rays manager class God rays.
Definition: GodRaysManager.h:46
Hydrax::MaterialManager::NM_RTT
@ NM_RTT
Definition: MaterialManager.h:107
Hydrax::RttManager::RTT_DEPTH_REFLECTION
@ RTT_DEPTH_REFLECTION
Definition: RttManager.h:55
Hydrax::CfgFileManager
Class to load/save all Hydrax options from/to a config file.
Definition: CfgFileManager.h:44
Hydrax::HYDRAX_COMPONENT_SMOOTH
@ HYDRAX_COMPONENT_SMOOTH
Smooth transitions and caustics components need depth component.
Definition: Enums.h:63
Hydrax::MaterialManager::MAT_WATER
@ MAT_WATER
Definition: MaterialManager.h:53
Hydrax::HydraxComponent
HydraxComponent
Hydrax flags to select components wich we want to use.
Definition: Enums.h:57
Hydrax::HYDRAX_COMPONENTS_NONE
@ HYDRAX_COMPONENTS_NONE
Definition: Enums.h:70
Hydrax::HYDRAX_COMPONENT_UNDERWATER
@ HYDRAX_COMPONENT_UNDERWATER
Definition: Enums.h:65
Hydrax::HYDRAX_COMPONENT_CAUSTICS
@ HYDRAX_COMPONENT_CAUSTICS
Definition: Enums.h:64
Hydrax::Module::Module::getNormalMode
const MaterialManager::NormalMode & getNormalMode() const
Get the normal generation mode.
Definition: Module.h:125
Ogre
Definition: ExtinguishableFireAffector.cpp:35
Hydrax::HYDRAX_COMPONENT_UNDERWATER_GODRAYS
@ HYDRAX_COMPONENT_UNDERWATER_GODRAYS
Definition: Enums.h:68
Hydrax::MaterialManager::MAT_UNDERWATER_COMPOSITOR
@ MAT_UNDERWATER_COMPOSITOR
Definition: MaterialManager.h:59
Hydrax::RttManager::RTT_REFRACTION
@ RTT_REFRACTION
Definition: RttManager.h:53
Hydrax::MaterialManager::ShaderMode
ShaderMode
Shader mode.
Definition: MaterialManager.h:88
Hydrax::MaterialManager::GPUP_VERTEX
@ GPUP_VERTEX
Definition: MaterialManager.h:81