RigsofRods
Soft-body Physics Simulation
RttManager.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 #pragma warning(disable:4267)
26 
27 #include "RttManager.h"
28 
29 #include "Hydrax.h"
30 
31 #define _def_Hydrax_Reflection_Rtt_Name "HydraxReflectionMap"
32 #define _def_Hydrax_Refraction_Rtt_Name "HydraxRefractionMap"
33 #define _def_Hydrax_Depth_Rtt_Name "HydraxDepthMap"
34 #define _def_Hydrax_Depth_Reflection_Rtt_Name "HydraxDepthReflectionMap"
35 #define _def_Hydrax_API_Rtt_Name "HydraxAPIMap"
36 #define _def_Hydrax_GPU_Normal_Map_Rtt_Name "HydraxNormalMap"
37 
38 namespace Hydrax
39 {
41  : mHydrax(h)
42  , mPlanesSceneNode(0)
43  , mReflectionDisplacementError(0.5f)
44  {
45  Ogre::String RttNames[6] =
52 
53  for (int k = 0; k < 6; k++)
54  {
55  mPlanes[k] = static_cast<Ogre::MovablePlane*>(NULL);
56  mTextures[k].setNull();
57  mRttOptions[k].Name = RttNames[k];
58  mRttOptions[k].Size_ = Size(0);
61  }
62 
71  }
72 
74  {
75  removeAll();
76  }
77 
79  {
80  if (!mPlanesSceneNode)
81  {
82  mPlanesSceneNode = mHydrax->getSceneManager()->getRootSceneNode()->createChildSceneNode();
84  }
85 
86  switch(Rtt)
87  {
88  case RTT_REFLECTION:
89  {
90  const Ogre::Vector3& WC = mHydrax->getWaterColor();
91 
92  bool RenderSkyBox = !mHydrax->_isCurrentFrameUnderwater();
93 
94  _initializeRtt(Rtt, Ogre::Vector3::UNIT_Y, Ogre::ColourValue(WC.x, WC.y, WC.z), RenderSkyBox, &mReflectionListener);
95  }
96  break;
97 
98  case RTT_REFRACTION:
99  {
100  const Ogre::Vector3& WC = mHydrax->getWaterColor();
101 
102  bool RenderSkyBox = mHydrax->_isCurrentFrameUnderwater();
103 
104  _initializeRtt(Rtt, Ogre::Vector3::NEGATIVE_UNIT_Y, Ogre::ColourValue(WC.x, WC.y, WC.z), RenderSkyBox, &mRefractionListener);
105  }
106  break;
107 
108  case RTT_DEPTH:
109  {
110  _initializeRtt(Rtt, Ogre::Vector3::NEGATIVE_UNIT_Y, Ogre::ColourValue::Black, false, &mDepthListener, "HydraxDepth", false);
111  }
112  break;
113 
115  {
116  _initializeRtt(Rtt, Ogre::Vector3::NEGATIVE_UNIT_Y, Ogre::ColourValue::Black, false, &mDepthReflectionListener, "HydraxDepth", false);
117  }
118  break;
119 
120  case RTT_GPU_NORMAL_MAP:
121  {
122  _initializeRtt(Rtt, Ogre::Vector3::NEGATIVE_UNIT_Y, Ogre::ColourValue(0.5,1,0.5), false, &mGPUNormalMapListener, "", false);
123  }
124  break;
125  }
126  }
127 
128  void RttManager::remove(const RttType& Rtt)
129  {
130  Ogre::TexturePtr &Tex = mTextures[Rtt];
131 
132  if (!Tex.isNull())
133  {
134  Ogre::RenderTarget* RT = Tex->getBuffer()->getRenderTarget();
135  RT->removeAllListeners();
136  RT->removeAllViewports();
137 
138  Ogre::TextureManager::getSingleton().remove(mRttOptions[Rtt].Name);
139  Ogre::MeshManager::getSingleton().remove(mRttOptions[Rtt].Name + "ClipPlane");
140 
141  Tex.setNull();
142  delete mPlanes[Rtt];
143  mPlanes[Rtt] = static_cast<Ogre::MovablePlane*>(NULL);
144  }
145 
146  // Check it to avoid any possible problem(texture initializated by createTextureUnit(Name..))
147  if (Ogre::TextureManager::getSingleton().resourceExists(mRttOptions[Rtt].Name))
148  {
149  Ogre::TextureManager::getSingleton().remove(mRttOptions[Rtt].Name);
150  }
151  }
152 
154  {
155  for (int k = 0; k < 6; k++)
156  {
157  remove(static_cast<RttType>(k));
158  }
159 
160  if (mPlanesSceneNode)
161  {
162  mPlanesSceneNode->detachAllObjects();
163  mPlanesSceneNode->getParentSceneNode()->removeAndDestroyChild(mPlanesSceneNode);
164  mPlanesSceneNode = 0;
165  }
166  }
167 
168  void RttManager::_initializeRtt(const RttType& Rtt, const Ogre::Vector3& PlaneNormal,
169  const Ogre::ColourValue& BackgroundColour, const bool& RenderSky,
170  Ogre::RenderTargetListener* RTListener, const Ogre::String& MaterialScheme,
171  const bool& ShadowsEnabled)
172  {
173  remove(Rtt);
174 
175  mPlanes[Rtt] = new Ogre::MovablePlane(mRttOptions[Rtt].Name + "Plane");
176 
177  mPlanes[Rtt]->d = 0;
178  mPlanes[Rtt]->normal = PlaneNormal;
179 
180  Ogre::MeshManager::getSingleton().
181  createPlane(mRttOptions[Rtt].Name + "ClipPlane", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
182  *mPlanes[Rtt],
183  mHydrax->getMesh()->getSize().Width,mHydrax->getMesh()->getSize().Height, // PG grid.. <-- look into
184  10,10, true, 1,5,5, Ogre::Vector3::UNIT_Z);
185 
186  mPlanes[Rtt]->setCastShadows(false);
187  mPlanesSceneNode->attachObject(mPlanes[Rtt]);
188 
189  Size TSize = mRttOptions[Rtt].Size_;
190 
191  if (TSize.Width == 0 || TSize.Height == 0)
192  {
193  TSize.Width = mHydrax->getViewport()->getActualWidth();
194  TSize.Height = mHydrax->getViewport()->getActualHeight();
195  }
196 
197  mTextures[Rtt] = Ogre::TextureManager::getSingleton()
198  .createManual(mRttOptions[Rtt].Name,
199  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
200  Ogre::TEX_TYPE_2D,
201  TSize.Width,
202  TSize.Height,
203  0,
204  getPixelFormat(Rtt),
205  Ogre::TU_RENDERTARGET);
206 
207  Ogre::RenderTarget* RT_Texture = mTextures[Rtt]->getBuffer()->getRenderTarget();
208 
209  Ogre::Viewport *RT_Texture_Viewport = RT_Texture->addViewport(mHydrax->getCamera());
210  RT_Texture_Viewport->setClearEveryFrame(true);
211  RT_Texture_Viewport->setBackgroundColour(BackgroundColour);
212  RT_Texture_Viewport->setOverlaysEnabled(false);
213  RT_Texture_Viewport->setShadowsEnabled(ShadowsEnabled);
214  if (MaterialScheme != "")
215  {
216  RT_Texture_Viewport->setMaterialScheme(MaterialScheme);
217  }
218  RT_Texture_Viewport->setSkiesEnabled(RenderSky);
219 
220  RT_Texture->addListener(RTListener);
221  }
222 
223  void RttManager::setTextureSize(const RttType& Rtt, const Size& S)
224  {
225  mRttOptions[static_cast<int>(Rtt)].Size_ = S;
226 
227  if (!getTexture(Rtt).isNull())
228  {
229  initialize(Rtt);
230 
232 
234  {
236 
238  {
240  }
241  }
242  }
243  }
244 
246  {
247  bool ReloadMaterialsNeeded = false;
248 
249  for(int k = 0; k < 5; k++)
250  {
251  mRttOptions[static_cast<RttType>(k)].Size_ = S;
252 
253  if (!getTexture(static_cast<RttType>(k)).isNull())
254  {
255  initialize(static_cast<RttType>(k));
256 
257  ReloadMaterialsNeeded = true;
258  }
259  }
260 
261  if (ReloadMaterialsNeeded)
262  {
264 
266  {
268 
270  {
272  }
273  }
274  }
275  }
276 
277  const Ogre::PixelFormat RttManager::getPixelFormat(const RttType& Rtt) const
278  {
279  switch (mRttOptions[Rtt].NumberOfChannels_)
280  {
281  // One channel (R)
282  case NOC_1 :
283  {
284  switch (mRttOptions[Rtt].BitsPerChannel_)
285  {
286  // 8 bits
287  case BPC_8 :
288  {
289  return Ogre::PF_L8;
290  }
291  break;
292 
293  // 16 bits
294  case BPC_16 :
295  {
296  return Ogre::PF_FLOAT16_R;
297  }
298  break;
299 
300  // 32 bits
301  case BPC_32 :
302  {
303  return Ogre::PF_FLOAT32_R;
304  }
305  break;
306  }
307  }
308  break;
309 
310  // Two channels (RG)
311  case NOC_2 :
312  {
313  switch (mRttOptions[Rtt].BitsPerChannel_)
314  {
315  // 8 bits
316  case BPC_8 :
317  {
318  //...
319  }
320  break;
321 
322  // 16 bits
323  case BPC_16 :
324  {
325  return Ogre::PF_FLOAT16_GR;
326  }
327  break;
328 
329  // 32 bits
330  case BPC_32 :
331  {
332  return Ogre::PF_FLOAT32_GR;
333  }
334  break;
335  }
336  }
337  break;
338 
339  // Three channels (RGB)
340  case NOC_3 :
341  {
342  switch (mRttOptions[Rtt].BitsPerChannel_)
343  {
344  // 8 bits
345  case BPC_8 :
346  {
347  return Ogre::PF_B8G8R8;
348  }
349  break;
350 
351  // 16 bits
352  case BPC_16 :
353  {
354  return Ogre::PF_FLOAT16_RGB;
355  }
356  break;
357 
358  // 32 bits
359  case BPC_32 :
360  {
361  return Ogre::PF_FLOAT32_RGB;
362  }
363  break;
364  }
365  }
366  break;
367 
368  // Four channels (RGBA)
369  case NOC_4 :
370  {
371  switch (mRttOptions[Rtt].BitsPerChannel_)
372  {
373  // 8 bits
374  case BPC_8 :
375  {
376  return Ogre::PF_B8G8R8A8;
377  }
378  break;
379 
380  // 16 bits
381  case BPC_16 :
382  {
383  return Ogre::PF_FLOAT16_RGBA;
384  }
385  break;
386 
387  // 32 bits
388  case BPC_32 :
389  {
390  return Ogre::PF_FLOAT32_RGBA;
391  }
392  break;
393  }
394  }
395  break;
396 
397  }
398 
399  // >= than needed
400  return Ogre::PF_FLOAT32_RGBA;
401  }
402 
404 
405  void RttManager::CReflectionListener::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
406  {
408 
410 
411  mHydrax->getMesh()->getEntity()->setVisible(false);
412 
414  {
415  mRttManager->mPlanes[RTT_REFLECTION]->getParentNode()->translate(0,-mHydrax->getPlanesError(),0);
416  }
417  else
418  {
419  mRttManager->mPlanes[RTT_REFLECTION]->getParentNode()->translate(0,+mHydrax->getPlanesError(),0);
420  }
421 
422  bool IsInUnderwaterError = false;
423 
424  // Underwater
426  (mHydrax->getCamera()->getDerivedPosition().y > mRttManager->mPlanes[RTT_REFLECTION]->getParentNode()->getPosition().y))
427  {
428  mCameraPlaneDiff = 0;
429  IsInUnderwaterError = true;
430  }
431  // Overwater
432  else if ((!mHydrax->_isCurrentFrameUnderwater()) &&
433  (mHydrax->getCamera()->getDerivedPosition().y < mRttManager->mPlanes[RTT_REFLECTION]->getParentNode()->getPosition().y))
434  {
435  mCameraPlaneDiff = mRttManager->mPlanes[RTT_REFLECTION]->getParentNode()->getPosition().y-mHydrax->getCamera()->getDerivedPosition().y+mRttManager->mReflectionDisplacementError;
436  mRttManager->mPlanes[RTT_REFLECTION]->getParentNode()->translate(0,-mCameraPlaneDiff,0);
437  }
438  else
439  {
440  mCameraPlaneDiff = 0;
441  }
442 
444  {
446  {
448  }
449  }
450 
451  mHydrax->getCamera()->enableReflection(mRttManager->mPlanes[RTT_REFLECTION]);
452 
453  if (IsInUnderwaterError)
454  {
456  }
457  else
458  {
459  mHydrax->getCamera()->enableCustomNearClipPlane(mRttManager->mPlanes[RTT_REFLECTION]);
460  }
461  }
462 
463  void RttManager::CReflectionListener::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
464  {
465  Hydrax *mHydrax = mRttManager->mHydrax;
466 
467  mHydrax->getMesh()->getEntity()->setVisible(true);
468 
469  if (mCameraPlaneDiff != 0)
470  {
471  mRttManager->mPlanes[RTT_REFLECTION]->getParentNode()->translate(0,mCameraPlaneDiff,0);
472  }
473 
475  {
476  mRttManager->mPlanes[RTT_REFLECTION]->getParentNode()->translate(0,mHydrax->getPlanesError(),0);
477  }
478  else
479  {
480  mRttManager->mPlanes[RTT_REFLECTION]->getParentNode()->translate(0,-mHydrax->getPlanesError(),0);
481  }
482 
483  mHydrax->getCamera()->disableReflection();
484  mHydrax->getCamera()->disableCustomNearClipPlane();
485 
487  {
489  {
490  mRttManager->mPlanes[RTT_REFLECTION]->normal = -mRttManager->mPlanes[RTT_REFLECTION]->normal;
491  }
492  }
493 
494  mCReflectionQueueListener.mActive = false;
495  }
496 
497  void RttManager::CReflectionListener::CReflectionQueueListener::renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool
498 
499  &skipThisInvocation)
500  {
501  if ((queueGroupId == Ogre::RENDER_QUEUE_SKIES_EARLY || queueGroupId == Ogre::RENDER_QUEUE_SKIES_LATE || queueGroupId ==
502 
503  (Ogre::RENDER_QUEUE_SKIES_EARLY + 2))
504  && mActive)
505  {
506  mRttManager->mHydrax->getCamera()->disableCustomNearClipPlane();
507  Ogre::Root::getSingleton().getRenderSystem()->_setProjectionMatrix(mRttManager->mHydrax->getCamera()->getProjectionMatrixRS());
508  }
509  }
510 
511  void RttManager::CReflectionListener::CReflectionQueueListener::renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool
512 
513  &skipThisInvocation)
514  {
515  if ((queueGroupId == Ogre::RENDER_QUEUE_SKIES_EARLY || queueGroupId == Ogre::RENDER_QUEUE_SKIES_LATE || queueGroupId ==
516 
517  (Ogre::RENDER_QUEUE_SKIES_EARLY + 2))
518  && mActive)
519  {
520  mRttManager->mHydrax->getCamera()->enableCustomNearClipPlane(mRttManager->mPlanes[RTT_REFLECTION]);
521  Ogre::Root::getSingleton().getRenderSystem()->_setProjectionMatrix(mRttManager->mHydrax->getCamera()->getProjectionMatrixRS());
522  }
523  }
524 
525  void RttManager::CRefractionListener::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
526  {
527  Hydrax *mHydrax = mRttManager->mHydrax;
528 
529  mHydrax->getMesh()->getEntity()->setVisible(false);
530 
531  if (Ogre::Math::Abs(mHydrax->getPosition().y - mHydrax->getCamera()->getDerivedPosition().y) > mHydrax->getPlanesError())
532  {
534  {
535  mRttManager->mPlanes[RTT_REFRACTION]->normal = -mRttManager->mPlanes[RTT_REFRACTION]->normal;
536  mRttManager->mPlanes[RTT_REFRACTION]->getParentNode()->translate(0,-mHydrax->getPlanesError(),0);
537  }
538  else
539  {
540  mRttManager->mPlanes[RTT_REFRACTION]->getParentNode()->translate(0,mHydrax->getPlanesError(),0);
541  }
542 
543  mHydrax->getCamera()->enableCustomNearClipPlane(mRttManager->mPlanes[RTT_REFRACTION]);
544  }
545  }
546 
547  void RttManager::CRefractionListener::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
548  {
549  Hydrax *mHydrax = mRttManager->mHydrax;
550 
551  mHydrax->getMesh()->getEntity()->setVisible(true);
552 
553  if (Ogre::Math::Abs(mHydrax->getPosition().y - mHydrax->getCamera()->getDerivedPosition().y) > mHydrax->getPlanesError())
554  {
556  {
557  mRttManager->mPlanes[RTT_REFRACTION]->normal = -mRttManager->mPlanes[RTT_REFRACTION]->normal;
558  mRttManager->mPlanes[RTT_REFRACTION]->getParentNode()->translate(0,+mHydrax->getPlanesError(),0);
559  }
560  else
561  {
562  mRttManager->mPlanes[RTT_REFRACTION]->getParentNode()->translate(0,-mHydrax->getPlanesError(),0);
563  }
564 
565  mHydrax->getCamera()->disableCustomNearClipPlane();
566  }
567  }
568 
569  void RttManager::CDepthListener::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
570  {
571  Hydrax *mHydrax = mRttManager->mHydrax;
572 
573  Ogre::SceneManager::MovableObjectIterator EntityIterator =
574  mHydrax->getSceneManager()->getMovableObjectIterator("Entity");
575  Ogre::Entity* CurrentEntity;
576  unsigned int k;
577 
578  mMaterials.empty();
579 
580  while (EntityIterator.hasMoreElements())
581  {
582  CurrentEntity = static_cast<Ogre::Entity*>(EntityIterator.peekNextValue());
583 
584  for(k = 0; k < CurrentEntity->getNumSubEntities(); k++)
585  {
586  mMaterials.push(CurrentEntity->getSubEntity(k)->getMaterialName());
587 
588  CurrentEntity->getSubEntity(k)->setMaterialName(mHydrax->getMaterialManager()->getMaterial(MaterialManager::MAT_DEPTH)->getName());
589  }
590 
591  EntityIterator.moveNext();
592  }
593 
594  if (Ogre::Math::Abs(mHydrax->getPosition().y - mHydrax->getCamera()->getDerivedPosition().y) > mHydrax->getPlanesError())
595  {
597  {
598  mRttManager->mPlanes[RTT_DEPTH]->normal = -mRttManager->mPlanes[RTT_DEPTH]->normal;
599  mRttManager->mPlanes[RTT_DEPTH]->getParentNode()->translate(0,-mHydrax->getPlanesError(),0);
600  }
601  else
602  {
603  mRttManager->mPlanes[RTT_DEPTH]->getParentNode()->translate(0,mHydrax->getPlanesError(),0);
604  mHydrax->getCamera()->enableCustomNearClipPlane(mRttManager->mPlanes[RTT_DEPTH]);
605  }
606  }
607 
609  {
610  mHydrax->getMesh()->getEntity()->setVisible(true);
611  mHydrax->getMesh()->getEntity()->setMaterialName(
613  getName());
614  mHydrax->getMesh()->getEntity()->setRenderQueueGroup(Ogre::RENDER_QUEUE_SKIES_EARLY);
616  }
617  else
618  {
619  mHydrax->getMesh()->getEntity()->setVisible(false);
620  }
621  }
622 
623  void RttManager::CDepthListener::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
624  {
625  Hydrax *mHydrax = mRttManager->mHydrax;
626 
627  Ogre::SceneManager::MovableObjectIterator EntityIterator =
628  mHydrax->getSceneManager()->getMovableObjectIterator("Entity");
629  Ogre::Entity* CurrentEntity;
630  unsigned int k;
631 
632  while (EntityIterator.hasMoreElements())
633  {
634  CurrentEntity = static_cast<Ogre::Entity*>(EntityIterator.peekNextValue());
635 
636  for(k = 0; k < CurrentEntity->getNumSubEntities(); k++)
637  {
638  CurrentEntity->getSubEntity(k)->setMaterialName(mMaterials.front());
639 
640  mMaterials.pop();
641  }
642 
643  EntityIterator.moveNext();
644  }
645 
646  mHydrax->getMesh()->getEntity()->setVisible(true);
648  mHydrax->getMesh()->getEntity()->setRenderQueueGroup(Ogre::RENDER_QUEUE_1);
649 
650  if (Ogre::Math::Abs(mHydrax->getPosition().y - mHydrax->getCamera()->getDerivedPosition().y) > mHydrax->getPlanesError())
651  {
653  {
654  mRttManager->mPlanes[RTT_DEPTH]->normal = -mRttManager->mPlanes[RTT_DEPTH]->normal;
655  mRttManager->mPlanes[RTT_DEPTH]->getParentNode()->translate(0,+mHydrax->getPlanesError(),0);
656  }
657  else
658  {
659  mRttManager->mPlanes[RTT_DEPTH]->getParentNode()->translate(0,-mHydrax->getPlanesError(),0);
660  }
661 
662  mHydrax->getCamera()->disableCustomNearClipPlane();
663  }
664  }
665 
666  void RttManager::CDepthReflectionListener::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
667  {
668  Hydrax *mHydrax = mRttManager->mHydrax;
669 
670  mHydrax->getMesh()->getEntity()->setVisible(false);
671 
672  Ogre::SceneManager::MovableObjectIterator EntityIterator =
673  mHydrax->getSceneManager()->getMovableObjectIterator("Entity");
674  Ogre::Entity* CurrentEntity;
675  unsigned int k;
676 
677  mMaterials.empty();
678 
679  while (EntityIterator.hasMoreElements())
680  {
681  CurrentEntity = static_cast<Ogre::Entity*>(EntityIterator.peekNextValue());
682 
683  for(k = 0; k < CurrentEntity->getNumSubEntities(); k++)
684  {
685  mMaterials.push(CurrentEntity->getSubEntity(k)->getMaterialName());
686 
687  CurrentEntity->getSubEntity(k)->setMaterialName(mHydrax->getMaterialManager()->getMaterial(MaterialManager::MAT_DEPTH)->getName());
688  }
689 
690  EntityIterator.moveNext();
691  }
692 
693  mRttManager->mPlanes[RTT_DEPTH_REFLECTION]->getParentNode()->translate(0,-mHydrax->getPlanesError(),0);
694 
695  bool IsInUnderwaterError = false;
696 
697  if (mHydrax->getCamera()->getDerivedPosition().y > mRttManager->mPlanes[RTT_DEPTH_REFLECTION]->getParentNode()->getPosition().y)
698  {
699  mCameraPlaneDiff = 0;
700  IsInUnderwaterError = true;
701  }
702  else
703  {
704  mCameraPlaneDiff = 0;
705  }
706 
707  mHydrax->getCamera()->enableReflection(mRttManager->mPlanes[RTT_DEPTH_REFLECTION]);
708 
709  if (!IsInUnderwaterError)
710  {
711  mHydrax->getCamera()->enableCustomNearClipPlane(mRttManager->mPlanes[RTT_DEPTH_REFLECTION]);
712  }
713  }
714 
715  void RttManager::CDepthReflectionListener::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
716  {
717  Hydrax *mHydrax = mRttManager->mHydrax;
718 
719  Ogre::SceneManager::MovableObjectIterator EntityIterator =
720  mHydrax->getSceneManager()->getMovableObjectIterator("Entity");
721  Ogre::Entity* CurrentEntity;
722  unsigned int k;
723 
724  while (EntityIterator.hasMoreElements())
725  {
726  CurrentEntity = static_cast<Ogre::Entity*>(EntityIterator.peekNextValue());
727 
728  for(k = 0; k < CurrentEntity->getNumSubEntities(); k++)
729  {
730  CurrentEntity->getSubEntity(k)->setMaterialName(mMaterials.front());
731 
732  mMaterials.pop();
733  }
734 
735  EntityIterator.moveNext();
736  }
737 
738  mHydrax->getMesh()->getEntity()->setVisible(true);
739 
740  if (mCameraPlaneDiff != 0)
741  {
742  mRttManager->mPlanes[RTT_DEPTH_REFLECTION]->getParentNode()->translate(0,mCameraPlaneDiff,0);
743  }
744 
745  mRttManager->mPlanes[RTT_DEPTH_REFLECTION]->getParentNode()->translate(0,mHydrax->getPlanesError(),0);
746 
747  mHydrax->getCamera()->disableReflection();
748  mHydrax->getCamera()->disableCustomNearClipPlane();
749  }
750 
751  void RttManager::CGPUNormalMapListener::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
752  {
753  mOldMaterialName = mRttManager->mHydrax->getMesh()->getMaterialName();
754  mRttManager->mHydrax->getMesh()->setMaterialName(mRttManager->mHydrax->getGPUNormalMapManager()->getNormalMapMaterial()->getName());
755 
756  Ogre::SceneManager *mSceneMgr = mRttManager->mHydrax->getSceneManager();
757 
758  // Render only the Hydrax mesh(Ogre::RENDER_QUEUE_1)
759  mSceneMgr->clearSpecialCaseRenderQueues();
760  mSceneMgr->addSpecialCaseRenderQueue(Ogre::RENDER_QUEUE_1);
761  mSceneMgr->setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_INCLUDE);
762  }
763 
764  void RttManager::CGPUNormalMapListener::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
765  {
766  mRttManager->mHydrax->getMesh()->setMaterialName(mOldMaterialName);
767 
768  Ogre::SceneManager *mSceneMgr = mRttManager->mHydrax->getSceneManager();
769 
770  // Render all
771  mSceneMgr->clearSpecialCaseRenderQueues();
772  mSceneMgr->setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_EXCLUDE);
773  }
774 }
Hydrax::MaterialManager::MAT_UNDERWATER
@ MAT_UNDERWATER
Definition: MaterialManager.h:57
Hydrax::RttManager::CDepthListener::postRenderTargetUpdate
void postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:623
Hydrax::Hydrax::getGodRaysManager
GodRaysManager * getGodRaysManager()
Get Hydrax::GodRaysManager.
Definition: Hydrax.h:349
Hydrax::RttManager::CReflectionListener::CReflectionQueueListener::mActive
bool mActive
Is the reflection Rtt active?
Definition: RttManager.h:276
Hydrax::Hydrax::getWaterColor
const Ogre::Vector3 & getWaterColor() const
Get water color.
Definition: Hydrax.h:476
Hydrax::RttManager::NOC_1
@ NOC_1
Definition: RttManager.h:73
Hydrax::RttManager::~RttManager
~RttManager()
Destructor.
Definition: RttManager.cpp:73
Hydrax::RttManager::NOC_3
@ NOC_3
Definition: RttManager.h:75
Hydrax::Hydrax::getPosition
const Ogre::Vector3 & getPosition() const
Get water position.
Definition: Hydrax.h:413
Hydrax::MaterialManager::getMaterial
Ogre::MaterialPtr & getMaterial(const MaterialType &Material)
Get material.
Definition: MaterialManager.h:221
Hydrax::RttManager::RttOptions::BitsPerChannel_
BitsPerChannel BitsPerChannel_
Bits per channel.
Definition: RttManager.h:90
Hydrax::Hydrax::getPlanesError
const Ogre::Real & getPlanesError() const
Get current clip planes error.
Definition: Hydrax.h:421
Hydrax::Hydrax::getMesh
Mesh * getMesh()
Get Hydrax::Mesh.
Definition: Hydrax.h:317
Hydrax
Definition: CfgFileManager.cpp:28
Hydrax::RttManager::RttType
RttType
Rtt enumeration.
Definition: RttManager.h:50
Hydrax::RttManager::mRefractionListener
CRefractionListener mRefractionListener
Definition: RttManager.h:377
Hydrax::RttManager::CRefractionListener::preRenderTargetUpdate
void preRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:525
_def_Hydrax_Depth_Rtt_Name
#define _def_Hydrax_Depth_Rtt_Name
Definition: RttManager.cpp:33
Hydrax::Hydrax::getMaterialManager
MaterialManager * getMaterialManager()
Get Hydrax::MaterialManager.
Definition: Hydrax.h:325
Hydrax::Size
Struct wich contains an especific width and height value.
Definition: Help.h:40
Hydrax::RttManager::RttOptions::Name
Ogre::String Name
Texture names.
Definition: RttManager.h:84
Hydrax::RttManager::RTT_GPU_NORMAL_MAP
@ RTT_GPU_NORMAL_MAP
Definition: RttManager.h:57
Hydrax.h
Hydrax::RttManager::mHydrax
Hydrax * mHydrax
Hydrax parent pointer.
Definition: RttManager.h:363
Hydrax::RttManager::RTT_REFLECTION
@ RTT_REFLECTION
Definition: RttManager.h:52
Hydrax::RttManager::removeAll
void removeAll()
Remove all RttManager resources.
Definition: RttManager.cpp:153
Hydrax::MaterialManager::MAT_DEPTH
@ MAT_DEPTH
Definition: MaterialManager.h:55
_def_Hydrax_API_Rtt_Name
#define _def_Hydrax_API_Rtt_Name
Definition: RttManager.cpp:35
Hydrax::RttManager::CGPUNormalMapListener::postRenderTargetUpdate
void postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:764
Hydrax::RttManager::RttManager
RttManager(Hydrax *h)
Constructor.
Definition: RttManager.cpp:40
Hydrax::RttManager::CReflectionListener::mRttManager
RttManager * mRttManager
Rtt manager pointer.
Definition: RttManager.h:283
Hydrax::RttManager::setTexturesSize
void setTexturesSize(const Size &S)
Set Rtt textures size.
Definition: RttManager.cpp:245
Hydrax::RttManager::BPC_32
@ BPC_32
Definition: RttManager.h:66
Hydrax::RttManager::mTextures
Ogre::TexturePtr mTextures[6]
Rtt textures vector.
Definition: RttManager.h:371
Hydrax::RttManager::_initializeRtt
void _initializeRtt(const RttType &Rtt, const Ogre::Vector3 &RttPlaneNormal, const Ogre::ColourValue &BackgroundColour, const bool &RenderSky, Ogre::RenderTargetListener *RTListener, const Ogre::String &MaterialScheme="", const bool &ShadowsEnabled=true)
Definition: RttManager.cpp:168
Hydrax::RttManager::CGPUNormalMapListener::preRenderTargetUpdate
void preRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:751
Hydrax::Hydrax::isComponent
bool isComponent(const HydraxComponent &Component)
Returns if the especified component is active.
Definition: Hydrax.cpp:611
Hydrax::RttManager::RTT_DEPTH
@ RTT_DEPTH
Definition: RttManager.h:54
Hydrax::Hydrax::getSceneManager
Ogre::SceneManager * getSceneManager()
Get scene manager.
Definition: Hydrax.h:309
Hydrax::Hydrax::getCamera
Ogre::Camera * getCamera()
Get rendering camera.
Definition: Hydrax.h:293
Hydrax::RttManager::mReflectionListener
CReflectionListener mReflectionListener
Rtt listener objects.
Definition: RttManager.h:376
Hydrax::RttManager::mPlanes
Ogre::MovablePlane * mPlanes[6]
Rtt planes vector.
Definition: RttManager.h:368
RttManager.h
Hydrax::RttManager::mReflectionDisplacementError
Ogre::Real mReflectionDisplacementError
Reflection displacement error, range [0.01, ~2].
Definition: RttManager.h:388
Hydrax::RttManager::mRttOptions
RttOptions mRttOptions[6]
Rtt options.
Definition: RttManager.h:373
_def_Hydrax_Refraction_Rtt_Name
#define _def_Hydrax_Refraction_Rtt_Name
Definition: RttManager.cpp:32
Hydrax::RttManager::RttOptions::Size_
Size Size_
Size; Size(0,0) to get main viewport size.
Definition: RttManager.h:86
Hydrax::RttManager::BPC_8
@ BPC_8
Definition: RttManager.h:64
Hydrax::Hydrax::getViewport
Ogre::Viewport * getViewport()
Get main window viewport.
Definition: Hydrax.h:301
_def_Hydrax_Depth_Reflection_Rtt_Name
#define _def_Hydrax_Depth_Reflection_Rtt_Name
Definition: RttManager.cpp:34
Hydrax::MaterialManager::MAT_SIMPLE_RED
@ MAT_SIMPLE_RED
Definition: MaterialManager.h:61
Hydrax::MaterialManager::reload
void reload(const MaterialType &Material)
Reload material.
Definition: MaterialManager.cpp:3143
Hydrax::RttManager::CReflectionListener::postRenderTargetUpdate
void postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:463
Hydrax::RttManager::RTT_DEPTH_REFLECTION
@ RTT_DEPTH_REFLECTION
Definition: RttManager.h:55
Hydrax::RttManager::CDepthListener::preRenderTargetUpdate
void preRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:569
Hydrax::RttManager::NOC_4
@ NOC_4
Definition: RttManager.h:76
Hydrax::RttManager::CReflectionListener::CReflectionQueueListener::mRttManager
RttManager * mRttManager
Definition: RttManager.h:274
Hydrax::RttManager::getPixelFormat
const Ogre::PixelFormat getPixelFormat(const RttType &Rtt) const
Definition: RttManager.cpp:277
Hydrax::RttManager::CGPUNormalMapListener::mRttManager
RttManager * mRttManager
Rtt manager pointer.
Definition: RttManager.h:328
Hydrax::RttManager::mGPUNormalMapListener
CGPUNormalMapListener mGPUNormalMapListener
Definition: RttManager.h:380
Hydrax::RttManager::CReflectionListener::mCameraPlaneDiff
Ogre::Real mCameraPlaneDiff
Camera.y - Plane.y difference.
Definition: RttManager.h:286
Hydrax::RttManager::CDepthListener::mRttManager
RttManager * mRttManager
Rtt manager pointer.
Definition: RttManager.h:296
_def_Hydrax_GPU_Normal_Map_Rtt_Name
#define _def_Hydrax_GPU_Normal_Map_Rtt_Name
Definition: RttManager.cpp:36
Hydrax::RttManager::NOC_2
@ NOC_2
Definition: RttManager.h:74
Hydrax::Size::Width
int Width
Width value.
Definition: Help.h:43
Hydrax::MaterialManager::MAT_WATER
@ MAT_WATER
Definition: MaterialManager.h:53
Hydrax::RttManager::mDepthReflectionListener
CDepthReflectionListener mDepthReflectionListener
Definition: RttManager.h:379
Hydrax::RttManager::BPC_16
@ BPC_16
Definition: RttManager.h:65
Hydrax::RttManager::initialize
void initialize(const RttType &Rtt)
Initialize a RTT.
Definition: RttManager.cpp:78
Hydrax::HYDRAX_COMPONENT_UNDERWATER
@ HYDRAX_COMPONENT_UNDERWATER
Definition: Enums.h:65
Hydrax::RttManager::setTextureSize
void setTextureSize(const RttType &Rtt, const Size &S)
Set Rtt texture size.
Definition: RttManager.cpp:223
_def_Hydrax_Reflection_Rtt_Name
#define _def_Hydrax_Reflection_Rtt_Name
Definition: RttManager.cpp:31
Hydrax::RttManager::CReflectionListener::mCReflectionQueueListener
CReflectionQueueListener mCReflectionQueueListener
CReflectionQueueListener.
Definition: RttManager.h:280
Hydrax::RttManager::RttOptions::NumberOfChannels_
NumberOfChannels NumberOfChannels_
Number of channels.
Definition: RttManager.h:88
Hydrax::MaterialManager::MAT_UNDERWATER_COMPOSITOR
@ MAT_UNDERWATER_COMPOSITOR
Definition: MaterialManager.h:59
Hydrax::RttManager::CDepthReflectionListener::postRenderTargetUpdate
void postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:715
Hydrax::RttManager::remove
void remove(const RttType &Rtt)
Removes a RTT.
Definition: RttManager.cpp:128
Hydrax::RttManager::CDepthReflectionListener::preRenderTargetUpdate
void preRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:666
Hydrax::RttManager::CRefractionListener::postRenderTargetUpdate
void postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:547
Hydrax::RttManager::RTT_REFRACTION
@ RTT_REFRACTION
Definition: RttManager.h:53
Hydrax::RttManager::CRefractionListener::mRttManager
RttManager * mRttManager
Rtt manager pointer.
Definition: RttManager.h:252
Hydrax::RttManager::mPlanesSceneNode
Ogre::SceneNode * mPlanesSceneNode
SceneNode to attach our planes.
Definition: RttManager.h:366
Hydrax::Hydrax::_isCurrentFrameUnderwater
const bool & _isCurrentFrameUnderwater() const
Is current frame underwater?
Definition: Hydrax.h:621
Hydrax::RttManager::CReflectionListener::CReflectionQueueListener::renderQueueEnded
void renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &skipThisInvocation) override
Definition: RttManager.cpp:511
Hydrax::RttManager::getTexture
Ogre::TexturePtr getTexture(RttType Rtt)
Get Rtt texture.
Definition: RttManager.h:145
Hydrax::Size::Height
int Height
Height value.
Definition: Help.h:45
Hydrax::RttManager::CReflectionListener::CReflectionQueueListener::renderQueueStarted
void renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &skipThisInvocation) override
Definition: RttManager.cpp:497
Hydrax::Mesh::getEntity
Ogre::Entity * getEntity()
Get entity.
Definition: Mesh.h:221
Hydrax::GodRaysManager::setVisible
void setVisible(const bool &Visible)
Set visible.
Definition: GodRaysManager.h:165
Hydrax::RttManager::mDepthListener
CDepthListener mDepthListener
Definition: RttManager.h:378
Hydrax::RttManager::CDepthReflectionListener::mRttManager
RttManager * mRttManager
Rtt manager pointer.
Definition: RttManager.h:312
Hydrax::RttManager::CReflectionListener::preRenderTargetUpdate
void preRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:405
Hydrax::Mesh::getSize
const Size & getSize() const
Get mesh size.
Definition: Mesh.h:237