Rigs of Rods 2023.09
Soft-body Physics Simulation
Loading...
Searching...
No Matches
Hydrax.cpp
Go to the documentation of this file.
1/*
2--------------------------------------------------------------------------------
3This source file is part of Hydrax.
4Visit ---
5
6Copyright (C) 2008 Xavier Verguín González <xavierverguin@hotmail.com>
7 <xavyiy@gmail.com>
8
9This program is free software; you can redistribute it and/or modify it under
10the terms of the GNU Lesser General Public License as published by the Free Software
11Foundation; either version 2 of the License, or (at your option) any later
12version.
13
14This program is distributed in the hope that it will be useful, but WITHOUT
15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17
18You should have received a copy of the GNU Lesser General Public License along with
19this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21http://www.gnu.org/copyleft/lesser.txt.
22--------------------------------------------------------------------------------
23
24--------------------------------------------------------------------------------
25Contributors:
26 Jose Luis Cercós Pita <jlcercos@alumnos.upm.es>
27--------------------------------------------------------------------------------
28*/
29
30#pragma warning(disable:4355)
31
32#include <Hydrax.h>
33
34namespace 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
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
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
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
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
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
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 mMaterialManager->updateAnimatedTextures(timeSinceLastFrame);
296 mModule->update(timeSinceLastFrame);
297 mDecalsManager->update();
298 _checkUnderwater(timeSinceLastFrame);
299 }
300 }
301
303 {
304 mComponents = Components;
305
306 if (isComponent(HYDRAX_COMPONENT_SMOOTH) || isComponent(HYDRAX_COMPONENT_CAUSTICS) || isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
307 {
308 // Delete smooth and/or caustics components wich needs depth component
309 if (!isComponent(HYDRAX_COMPONENT_DEPTH))
310 {
315
316 if (isComponent(HYDRAX_COMPONENT_SUN))
317 {
319 }
320 if (isComponent(HYDRAX_COMPONENT_FOAM))
321 {
323 }
324 if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
325 {
327 }
329 {
331 }
332
333 if (isComponent(HYDRAX_COMPONENT_SMOOTH))
334 {
335 HydraxLOG("Smooth component needs depth component... smooth component desactivated.");
336 }
337 if (isComponent(HYDRAX_COMPONENT_CAUSTICS))
338 {
339 HydraxLOG("Caustics component needs depth component... caustics component desactivated.");
340 }
342 {
343 HydraxLOG("God rays component needs depth component... god rays component desactivated.");
344 }
345
346 mComponents = static_cast<HydraxComponent>(s|f|u|ur);
347 }
348 }
349
351 {
352 // Delete underwater reflections components wich needs underwater component
353 if (!isComponent(HYDRAX_COMPONENT_UNDERWATER))
354 {
360
361 if (isComponent(HYDRAX_COMPONENT_SUN))
362 {
364 }
365 if (isComponent(HYDRAX_COMPONENT_FOAM))
366 {
368 }
369 if (isComponent(HYDRAX_COMPONENT_DEPTH))
370 {
372 }
373 if (isComponent(HYDRAX_COMPONENT_SMOOTH))
374 {
376 }
377 if (isComponent(HYDRAX_COMPONENT_CAUSTICS))
378 {
380 }
381
383 {
384 HydraxLOG("Underwater reflections component needs underwater component... underwater reflections component desactivated.");
385 }
387 {
388 HydraxLOG("God rays component needs underwater component... god rays component desactivated.");
389 }
390
391 mComponents = static_cast<HydraxComponent>(s|f|d|sm|c);
392 }
393
394 if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS) && !isComponent(HYDRAX_COMPONENT_SUN))
395 {
396 HydraxLOG("God rays component needs sun component... god rays component desactivated.");
397
404
405 if (isComponent(HYDRAX_COMPONENT_FOAM))
406 {
408 }
409 if (isComponent(HYDRAX_COMPONENT_DEPTH))
410 {
412 }
413 if (isComponent(HYDRAX_COMPONENT_SMOOTH))
414 {
416 }
417 if (isComponent(HYDRAX_COMPONENT_CAUSTICS))
418 {
420 }
421 if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
422 {
424 }
426 {
428 }
429
430 mComponents = static_cast<HydraxComponent>(f|d|sm|c|u|ur);
431 }
432 }
433
434 int NumberOfDepthChannels = 0;
435
436 if (isComponent(HYDRAX_COMPONENT_DEPTH))
437 {
438 NumberOfDepthChannels++;
439
440 if (isComponent(HYDRAX_COMPONENT_CAUSTICS))
441 {
442 NumberOfDepthChannels++;
443 }
444
446 {
447 NumberOfDepthChannels++;
448 }
449 }
450
451 if (NumberOfDepthChannels > 0)
452 {
453 mRttManager->setNumberOfChannels(RttManager::RTT_DEPTH, static_cast<RttManager::NumberOfChannels>(NumberOfDepthChannels));
454 }
455
456 if (!mCreated || !mModule)
457 {
458 return;
459 }
460
462 {
463 mGodRaysManager->create(mComponents);
464 }
465 else
466 {
467 mGodRaysManager->remove();
468 }
469
470 // Check for Rtt's
471 if (mCurrentFrameUnderwater && isComponent(HYDRAX_COMPONENT_UNDERWATER) && !isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS))
472 {
473 mRttManager->remove(RttManager::RTT_REFLECTION);
474 }
475 else
476 {
477 mRttManager->initialize(RttManager::RTT_REFLECTION);
478 }
479
480 if (!isComponent(HYDRAX_COMPONENT_DEPTH))
481 {
482 mRttManager->remove(RttManager::RTT_DEPTH);
483 mRttManager->remove(RttManager::RTT_DEPTH_REFLECTION);
484 }
485 else
486 {
487 mRttManager->initialize(RttManager::RTT_DEPTH);
488
489 if (isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS) && mCurrentFrameUnderwater)
490 {
491 mRttManager->initialize(RttManager::RTT_DEPTH_REFLECTION);
492 }
493 else
494 {
495 mRttManager->remove(RttManager::RTT_DEPTH_REFLECTION);
496 }
497 }
498 if (!isComponent(HYDRAX_COMPONENT_UNDERWATER) && mCurrentFrameUnderwater)
499 {
500 mRttManager->getTexture(RttManager::RTT_REFRACTION)->
501 getBuffer()->getRenderTarget()->getViewport(0)->
502 setSkiesEnabled(false);
503
504 mRttManager->getTexture(RttManager::RTT_REFLECTION)->
505 getBuffer()->getRenderTarget()->getViewport(0)->
506 setSkiesEnabled(true);
507 }
508
509 mMesh->setMaterialName("BaseWhiteNoLighting");
510 mMaterialManager->createMaterials(mComponents, MaterialManager::Options(mShaderMode, mModule->getNormalMode()));
511
512 if (!isComponent(HYDRAX_COMPONENT_UNDERWATER))
513 {
514 mCurrentFrameUnderwater = false;
515 }
516
517 mMesh->setMaterialName(mCurrentFrameUnderwater ?
518 mMaterialManager->getMaterial(MaterialManager::MAT_UNDERWATER)->getName() :
519 mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName());
520
521 if (mCurrentFrameUnderwater)
522 {
523 mMaterialManager->setCompositorEnable(MaterialManager::COMP_UNDERWATER, true);
524 }
525 }
526
527 void Hydrax::setModule(Module::Module* Module, const bool& DeleteOldModule)
528 {
529 if (mModule)
530 {
531 if (mModule->getNormalMode() != Module->getNormalMode())
532 {
533 mMaterialManager->createMaterials(mComponents, MaterialManager::Options(mShaderMode, Module->getNormalMode()));
534
535 mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName());
536 }
537
538 if (mModule->getNormalMode() == MaterialManager::NM_RTT && mModule->isCreated() && mModule->getNoise()->areGPUNormalMapResourcesCreated())
539 {
540 mModule->getNoise()->removeGPUNormalMapResources(mGPUNormalMapManager);
541 }
542
543 if (DeleteOldModule)
544 {
545 delete mModule;
546 }
547 else
548 {
549 mModule->remove();
550 }
551
552 // Due to modules can change -internally- scene nodes position,
553 // just reset them to the original position.
554 setPosition(mPosition);
555 }
556
557 mModule = Module;
558
559 if (mCreated)
560 {
561 if (!mModule->isCreated())
562 {
563 mModule->create();
564
565 if (mModule->getNormalMode() == MaterialManager::NM_RTT)
566 {
567 if (!mModule->getNoise()->createGPUNormalMapResources(mGPUNormalMapManager))
568 {
569 HydraxLOG(mModule->getNoise()->getName() + " doesn't support GPU Normal map generation.");
570 }
571 }
572 }
573 else
574 {
575 if (mModule->getNormalMode() == MaterialManager::NM_RTT)
576 {
577 if (!mModule->getNoise()->areGPUNormalMapResourcesCreated())
578 {
579 if (!mModule->getNoise()->createGPUNormalMapResources(mGPUNormalMapManager))
580 {
581 HydraxLOG(mModule->getNoise()->getName() + " doesn't support GPU Normal map generation.");
582 }
583 }
584 }
585 else
586 {
587 if (mModule->getNoise()->areGPUNormalMapResourcesCreated())
588 {
589 mModule->getNoise()->removeGPUNormalMapResources(mGPUNormalMapManager);
590 }
591 }
592 }
593
594 HydraxLOG("Updating water mesh...");
595 Ogre::String MaterialNameTmp = mMesh->getMaterialName();
596
597 HydraxLOG("Deleting water mesh...");
598 mMesh->remove();
599 HydraxLOG("Water mesh deleted.");
600
601 HydraxLOG("Creating water mesh...");
602 mMesh->setOptions(mModule->getMeshOptions());
603 mMesh->setMaterialName(MaterialNameTmp);
604 mMesh->create();
605 setPosition(mPosition);
606 HydraxLOG("Water mesh created.");
607
608 HydraxLOG("Module set.");
609 }
610 }
611
613 {
614 if (mComponents & Component)
615 {
616 return true;
617 }
618
619 if (Component == HYDRAX_COMPONENTS_NONE && mComponents == HYDRAX_COMPONENTS_NONE)
620 {
621 return true;
622 }
623
624 if (Component == HYDRAX_COMPONENTS_ALL && mComponents == HYDRAX_COMPONENTS_ALL)
625 {
626 return true;
627 }
628
629 return false;
630 }
631
632 void Hydrax::_checkUnderwater(const Ogre::Real& timeSinceLastFrame)
633 {
634 if (!isComponent(HYDRAX_COMPONENT_UNDERWATER))
635 {
636 mCurrentFrameUnderwater = false;
637
638 return;
639 }
640
641 // If the camera is under the current water x/z position
642 if (getHeigth(mCamera->getDerivedPosition()) > mCamera->getDerivedPosition().y-mUnderwaterCameraSwitchDelta)
643 {
644 mCurrentFrameUnderwater = true;
645
646 if (mMesh->getMaterialName() != mMaterialManager->getMaterial(MaterialManager::MAT_UNDERWATER)->getName())
647 {
648 mRttManager->getTexture(RttManager::RTT_REFRACTION)->
649 getBuffer()->getRenderTarget()->getViewport(0)->
650 setSkiesEnabled(true);
651
653 {
654 mRttManager->getTexture(RttManager::RTT_REFLECTION)->
655 getBuffer()->getRenderTarget()->getViewport(0)->
656 setSkiesEnabled(false);
657
658 if (isComponent(HYDRAX_COMPONENT_DEPTH))
659 {
660 mRttManager->initialize(RttManager::RTT_DEPTH_REFLECTION);
661 }
662 }
663 else
664 {
665 mRttManager->remove(RttManager::RTT_REFLECTION);
666 }
667
669 {
670 mRttManager->initialize(RttManager::RTT_DEPTH_REFLECTION);
671 }
672
673 mMaterialManager->reload(MaterialManager::MAT_UNDERWATER);
674
675 mMaterialManager->setCompositorEnable(MaterialManager::COMP_UNDERWATER, true);
676
677 mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_UNDERWATER)->getName());
678 }
679
680 // Update god rays
682 {
683 mGodRaysManager->update(timeSinceLastFrame);
684 }
685 }
686 else
687 {
688 mCurrentFrameUnderwater = false;
689
690 if (mMesh->getMaterialName() != mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName())
691 {
692 // We asume that RefractionRtt/ReflectionRtt are initialized
693 mRttManager->getTexture(RttManager::RTT_REFRACTION)->
694 getBuffer()->getRenderTarget()->getViewport(0)->
695 setSkiesEnabled(false);
696
698 {
699 mRttManager->initialize(RttManager::RTT_REFLECTION);
700 mMaterialManager->reload(MaterialManager::MAT_WATER);
701 }
702
703 mRttManager->getTexture(RttManager::RTT_REFLECTION)->
704 getBuffer()->getRenderTarget()->getViewport(0)->
705 setSkiesEnabled(true);
706
708 {
709 mRttManager->remove(RttManager::RTT_DEPTH_REFLECTION);
710 }
711
712 mMaterialManager->setCompositorEnable(MaterialManager::COMP_UNDERWATER, false);
713
714 mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName());
715 }
716 }
717
718 }
719
720 void Hydrax::setPosition(const Ogre::Vector3 &Position)
721 {
722 mPosition = Position;
723
724 if (!mCreated)
725 {
726 return;
727 }
728
729 if (isComponent(HYDRAX_COMPONENT_DEPTH))
730 {
731 mMaterialManager->setGpuProgramParameter(
733 "uPlaneYPos", Position.y);
734 }
735
736 mMesh->getSceneNode()->setPosition(Position.x-mMesh->getSize().Width/2, Position.y, Position.z-mMesh->getSize().Height/2);
737 mRttManager->getPlanesSceneNode()->setPosition(Position);
738
739 // For world-space -> object-space conversion
740 setSunPosition(mSunPosition);
741 }
742
743 void Hydrax::rotate(const Ogre::Quaternion &q)
744 {
745 if (!mCreated)
746 {
747 HydraxLOG("Hydrax::rotate(...) must be called after Hydrax::create(), skipping...");
748
749 return;
750 }
751
752 mMesh->getSceneNode()->rotate(q);
753 mRttManager->getPlanesSceneNode()->rotate(q);
754
755 // For world-space -> object-space conversion
756 setSunPosition(mSunPosition);
757 }
758
759 void Hydrax::setPlanesError(const Ogre::Real &PlanesError)
760 {
761 mPlanesError = PlanesError;
762 }
763
764 void Hydrax::_setStrength(const Ogre::Real &Strength)
765 {
766 if (isComponent(HYDRAX_COMPONENT_FOAM))
767 {
768 mMaterialManager->setGpuProgramParameter(
770 "uFoamRange", Strength);
771
772 if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
773 {
774 mMaterialManager->setGpuProgramParameter(
776 "uFoamRange", Strength);
777 }
778 }
779
780 mDecalsManager->_setWaterStrength(Strength);
781 }
782
783 void Hydrax::setFullReflectionDistance(const Ogre::Real &FullReflectionDistance)
784 {
785 mFullReflectionDistance = FullReflectionDistance;
786
787 mMaterialManager->setGpuProgramParameter(
789 "uFullReflectionDistance", FullReflectionDistance);
790
791 if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
792 {
793 mMaterialManager->setGpuProgramParameter(
795 "uFullReflectionDistance", FullReflectionDistance);
796 }
797 }
798
799 void Hydrax::setGlobalTransparency(const Ogre::Real &GlobalTransparency)
800 {
801 mGlobalTransparency = GlobalTransparency;
802
803 mMaterialManager->setGpuProgramParameter(
805 "uGlobalTransparency", GlobalTransparency);
806
807 if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
808 {
809 mMaterialManager->setGpuProgramParameter(
811 "uGlobalTransparency", GlobalTransparency);
812 }
813 }
814
815 void Hydrax::setWaterColor(const Ogre::Vector3 &WaterColor)
816 {
817 mWaterColor = WaterColor;
818
819 if (!mCreated)
820 {
821 return;
822 }
823
824 Ogre::ColourValue WC = Ogre::ColourValue(WaterColor.x, WaterColor.y, WaterColor.z);
825
826 if (isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS) || !_isCurrentFrameUnderwater())
827 {
828 mRttManager->getTexture(RttManager::RTT_REFLECTION)->
829 getBuffer()->getRenderTarget()->getViewport(0)->
830 setBackgroundColour(WC);
831 }
832 mRttManager->getTexture(RttManager::RTT_REFRACTION)->
833 getBuffer()->getRenderTarget()->getViewport(0)->
834 setBackgroundColour(WC);
835
836 if (!isComponent(HYDRAX_COMPONENT_DEPTH))
837 {
838 return;
839 }
840
841 mMaterialManager->setGpuProgramParameter(
843 "uWaterColor", WaterColor);
844
845 if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
846 {
847 mMaterialManager->setGpuProgramParameter(
849 "uWaterColor", WaterColor);
850
851 //mMaterialManager->getCompositor(MaterialManager::COMP_UNDERWATER)->
852 // getTechnique(0)->getTargetPass(0)->getPass(0)->setClearColour(WC);
853
854 /* Active creation/destruction
855 if (getHeigth(mCamera->getDerivedPosition()) > mCamera->getDerivedPosition().y-1.25f)
856 {
857 if (mMaterialManager->isCompositorEnable(MaterialManager::COMP_UNDERWATER))
858 {
859 mMaterialManager->setCompositorEnable(MaterialManager::COMP_UNDERWATER, false);
860 mMaterialManager->setCompositorEnable(MaterialManager::COMP_UNDERWATER, true);
861 }
862 }
863 */
864 }
865 }
866
867
868 void Hydrax::setNormalDistortion(const Ogre::Real &NormalDistortion)
869 {
870 mNormalDistortion = NormalDistortion;
871
872 mMaterialManager->setGpuProgramParameter(
874 "uNormalDistortion", NormalDistortion);
875
876 if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
877 {
878 mMaterialManager->setGpuProgramParameter(
880 "uNormalDistortion", NormalDistortion);
881 }
882 }
883
884 void Hydrax::setSunPosition(const Ogre::Vector3 &SunPosition)
885 {
886 if (!isComponent(HYDRAX_COMPONENT_SUN))
887 {
888 return;
889 }
890
891 mSunPosition = SunPosition;
892
893 mMaterialManager->setGpuProgramParameter(
895 "uSunPosition", mMesh->getObjectSpacePosition(SunPosition));
896
897 if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
898 {
899 mMaterialManager->setGpuProgramParameter(
901 "uSunPosition", mMesh->getObjectSpacePosition(SunPosition));
902 }
903 }
904
905 void Hydrax::setSunStrength(const Ogre::Real &SunStrength)
906 {
907 if (!isComponent(HYDRAX_COMPONENT_SUN))
908 {
909 return;
910 }
911
912 mSunStrength = SunStrength;
913
914 mMaterialManager->setGpuProgramParameter(
916 "uSunStrength", SunStrength);
917
918 if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
919 {
920 mMaterialManager->setGpuProgramParameter(
922 "uSunStrength", SunStrength);
923 }
924 }
925
926 void Hydrax::setSunArea(const Ogre::Real &SunArea)
927 {
928 if (!isComponent(HYDRAX_COMPONENT_SUN))
929 {
930 return;
931 }
932
933 mSunArea = SunArea;
934
935 mMaterialManager->setGpuProgramParameter(
937 "uSunArea", SunArea);
938
939 if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
940 {
941 mMaterialManager->setGpuProgramParameter(
943 "uSunArea", SunArea);
944 }
945 }
946
947 void Hydrax::setSunColor(const Ogre::Vector3 &SunColor)
948 {
949 if (!isComponent(HYDRAX_COMPONENT_SUN))
950 {
951 return;
952 }
953
954 mSunColor = SunColor;
955
956 mMaterialManager->setGpuProgramParameter(
958 "uSunColor", SunColor);
959
960 if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
961 {
962 mMaterialManager->setGpuProgramParameter(
964 "uSunColor", SunColor);
965 }
966 }
967
968 void Hydrax::setFoamMaxDistance(const Ogre::Real &FoamMaxDistance)
969 {
970 if (!isComponent(HYDRAX_COMPONENT_FOAM))
971 {
972 return;
973 }
974
975 mFoamMaxDistance = FoamMaxDistance;
976
977 mMaterialManager->setGpuProgramParameter(
979 "uFoamMaxDistance", FoamMaxDistance);
980
981 if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
982 {
983 mMaterialManager->setGpuProgramParameter(
985 "uFoamMaxDistance", FoamMaxDistance);
986 }
987 }
988
989 void Hydrax::setFoamScale(const Ogre::Real &FoamScale)
990 {
991 if (!isComponent(HYDRAX_COMPONENT_FOAM))
992 {
993 return;
994 }
995
996 mFoamScale = FoamScale;
997
998 mMaterialManager->setGpuProgramParameter(
1000 "uFoamScale", FoamScale);
1001
1002 if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
1003 {
1004 mMaterialManager->setGpuProgramParameter(
1006 "uFoamScale", FoamScale);
1007 }
1008 }
1009
1010 void Hydrax::setFoamStart(const Ogre::Real &FoamStart)
1011 {
1012 if (!isComponent(HYDRAX_COMPONENT_FOAM))
1013 {
1014 return;
1015 }
1016
1017 mFoamStart = FoamStart;
1018
1019 mMaterialManager->setGpuProgramParameter(
1021 "uFoamStart", FoamStart);
1022
1023 if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
1024 {
1025 mMaterialManager->setGpuProgramParameter(
1027 "uFoamStart", FoamStart);
1028 }
1029 }
1030
1031 void Hydrax::setFoamTransparency(const Ogre::Real &FoamTransparency)
1032 {
1033 if (!isComponent(HYDRAX_COMPONENT_FOAM))
1034 {
1035 return;
1036 }
1037
1038 mFoamTransparency = FoamTransparency;
1039
1040 mMaterialManager->setGpuProgramParameter(
1042 "uFoamTransparency", FoamTransparency);
1043
1044 if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
1045 {
1046 mMaterialManager->setGpuProgramParameter(
1048 "uFoamTransparency", FoamTransparency);
1049 }
1050 }
1051
1052 void Hydrax::setDepthLimit(const Ogre::Real &DepthLimit)
1053 {
1054 if (!isComponent(HYDRAX_COMPONENT_DEPTH))
1055 {
1056 return;
1057 }
1058
1059 mDepthLimit = DepthLimit;
1060
1061 if (mDepthLimit <= 0)
1062 {
1063 mDepthLimit = 1;
1064 }
1065
1066 mMaterialManager->setGpuProgramParameter(
1068 "uDepthLimit", 1/mDepthLimit);
1069 }
1070
1071 void Hydrax::setDistLimit(const Ogre::Real &DistLimit)
1072 {
1073 if (!isComponent(HYDRAX_COMPONENT_DEPTH))
1074 {
1075 return;
1076 }
1077
1078 mDistLimit = DistLimit;
1079
1080 if (mDistLimit <= 0)
1081 {
1082 mDistLimit = 1;
1083 }
1084
1085 mMaterialManager->setGpuProgramParameter(
1087 "uDistLimit", 1/mDistLimit);
1088 }
1089
1090 void Hydrax::setSmoothPower(const Ogre::Real &SmoothPower)
1091 {
1092 if (!isComponent(HYDRAX_COMPONENT_SMOOTH))
1093 {
1094 return;
1095 }
1096
1097 mSmoothPower = SmoothPower;
1098
1099 mMaterialManager->setGpuProgramParameter(
1101 "uSmoothPower", SmoothPower);
1102 }
1103
1104 void Hydrax::setCausticsScale(const Ogre::Real &CausticsScale)
1105 {
1106 if (!isComponent(HYDRAX_COMPONENT_CAUSTICS))
1107 {
1108 return;
1109 }
1110
1111 mCausticsScale = CausticsScale;
1112
1113 mMaterialManager->setGpuProgramParameter(
1115 "uCausticsScale", CausticsScale);
1116 }
1117
1118 void Hydrax::setCausticsPower(const Ogre::Real &CausticsPower)
1119 {
1120 if (!isComponent(HYDRAX_COMPONENT_CAUSTICS))
1121 {
1122 return;
1123 }
1124
1125 mCausticsPower = CausticsPower;
1126
1127 mMaterialManager->setGpuProgramParameter(
1129 "uCausticsPower", CausticsPower);
1130
1131 if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
1132 {
1134 {
1135 mMaterialManager->setGpuProgramParameter(
1137 "uCausticsPower", CausticsPower);
1138 }
1139
1140 mMaterialManager->setGpuProgramParameter(
1142 "uCausticsPower", CausticsPower);
1143 }
1144 }
1145
1146 void Hydrax::setCausticsEnd(const Ogre::Real &CausticsEnd)
1147 {
1148 if (!isComponent(HYDRAX_COMPONENT_CAUSTICS))
1149 {
1150 return;
1151 }
1152
1153 mCausticsEnd = CausticsEnd;
1154
1155 mMaterialManager->setGpuProgramParameter(
1157 "uCausticsEnd", CausticsEnd);
1158 }
1159}
#define HydraxLOG(msg)
Definition Application.h:60
Class to load/save all Hydrax options from/to a config file.
Decals manager class.
Class to manager GPU normal maps.
Underwater god rays manager class God rays.
void eventOccurred(const Ogre::String &eventName, const Ogre::NameValuePairList *parameters)
Event occurred.
Definition Hydrax.cpp:251
Main Hydrax class.
Definition Hydrax.h:57
void remove()
Remove hydrax, you can call this method to remove Hydrax from the scene or release (secondary) Hydrax...
Definition Hydrax.cpp:177
void setFoamTransparency(const Ogre::Real &FoamTransparency)
Set foam transparency.
Definition Hydrax.cpp:1031
void setShaderMode(const MaterialManager::ShaderMode &ShaderMode)
Set shader mode.
Definition Hydrax.cpp:279
void setGlobalTransparency(const Ogre::Real &GlobalTransparencyDistance)
Definition Hydrax.cpp:799
void setDistLimit(const Ogre::Real &DistLimit)
Set distance limit underwater (occlusion)
Definition Hydrax.cpp:1071
void setPosition(const Ogre::Vector3 &Position)
Set water position.
Definition Hydrax.cpp:720
void setSunArea(const Ogre::Real &SunArea)
Set sun area.
Definition Hydrax.cpp:926
void setVisible(const bool &Visible)
Show/Hide hydrax water.
Definition Hydrax.cpp:197
void setPlanesError(const Ogre::Real &PlanesError)
Set clip planes error.
Definition Hydrax.cpp:759
void rotate(const Ogre::Quaternion &q)
Rotate water and planes.
Definition Hydrax.cpp:743
void setModule(Module::Module *Module, const bool &DeleteOldModule=true)
Set Hydrax module.
Definition Hydrax.cpp:527
void _checkUnderwater(const Ogre::Real &timeSinceLastFrame)
Check for underwater effects.
Definition Hydrax.cpp:632
void setFoamStart(const Ogre::Real &FoamStart)
Set foam start.
Definition Hydrax.cpp:1010
bool isComponent(const HydraxComponent &Component)
Returns if the especified component is active.
Definition Hydrax.cpp:612
void setComponents(const HydraxComponent &Components)
Set Hydrax components.
Definition Hydrax.cpp:302
void setCausticsPower(const Ogre::Real &CausticsPower)
Set caustics power.
Definition Hydrax.cpp:1118
void setFoamMaxDistance(const Ogre::Real &FoamMaxDistance)
Set foam max distance.
Definition Hydrax.cpp:968
void setDepthLimit(const Ogre::Real &DepthLimit)
Set depth limit.
Definition Hydrax.cpp:1052
void _checkVisible()
setVisible() helper funtion
Definition Hydrax.cpp:204
void setSunPosition(const Ogre::Vector3 &SunPosition)
Set sun position.
Definition Hydrax.cpp:884
void setPolygonMode(const Ogre::PolygonMode &PM)
Set polygon mode (Solid, Wireframe, Points)
Definition Hydrax.cpp:262
void setFoamScale(const Ogre::Real &FoamScale)
Set foam scale.
Definition Hydrax.cpp:989
void setCausticsScale(const Ogre::Real &CausticsScale)
Set caustics scale.
Definition Hydrax.cpp:1104
void _setStrength(const Ogre::Real &Strength)
Set water strength GPU param.
Definition Hydrax.cpp:764
void setSmoothPower(const Ogre::Real &SmoothPower)
Set smooth power.
Definition Hydrax.cpp:1090
void setSunStrength(const Ogre::Real &SunStrength)
Set sun strength.
Definition Hydrax.cpp:905
void create()
Create all resources according with current Hydrax components and add Hydrax to the scene.
Definition Hydrax.cpp:103
~Hydrax()
Destructor.
Definition Hydrax.cpp:82
void setNormalDistortion(const Ogre::Real &NormalDistortion)
Set normal distortion.
Definition Hydrax.cpp:868
void update(const Ogre::Real &timeSinceLastFrame)
Call every frame.
Definition Hydrax.cpp:291
void setSunColor(const Ogre::Vector3 &SunColor)
Set sun color.
Definition Hydrax.cpp:947
void setFullReflectionDistance(const Ogre::Real &FullReflectionDistance)
Set full reflection distance.
Definition Hydrax.cpp:783
void setWaterColor(const Ogre::Vector3 &WaterColor)
Definition Hydrax.cpp:815
void setCausticsEnd(const Ogre::Real &CausticsEnd)
Set caustics end.
Definition Hydrax.cpp:1146
Material/Shader manager class.
Class wich contains all funtions/variables related to Hydrax water mesh.
Definition Mesh.h:47
Base module class, Override it for create different ways of create water noise.
Definition Module.h:47
virtual void create()
Create.
Definition Module.cpp:46
const MaterialManager::NormalMode & getNormalMode() const
Get the normal generation mode.
Definition Module.h:125
Rtt's manager class.
Definition RttManager.h:46
NumberOfChannels
Number of channels.
Definition RttManager.h:72
Class for manager Normal maps.
HydraxComponent
Hydrax flags to select components wich we want to use.
Definition Enums.h:58
@ HYDRAX_COMPONENTS_NONE
Definition Enums.h:70
@ HYDRAX_COMPONENTS_ALL
Definition Enums.h:71
@ HYDRAX_COMPONENT_DEPTH
Definition Enums.h:61
@ HYDRAX_COMPONENT_SMOOTH
Smooth transitions and caustics components need depth component.
Definition Enums.h:63
@ HYDRAX_COMPONENT_UNDERWATER
Definition Enums.h:65
@ HYDRAX_COMPONENT_SUN
Definition Enums.h:59
@ HYDRAX_COMPONENT_UNDERWATER_GODRAYS
Definition Enums.h:68
@ HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS
Underwater reflections and god rays need underwater component.
Definition Enums.h:67
@ HYDRAX_COMPONENT_FOAM
Definition Enums.h:60
@ HYDRAX_COMPONENT_CAUSTICS
Definition Enums.h:64