Google

HOW TO: Integrate Hydrax v0.4 with Caelum

easy-use library in order to render pretty water scenes.

Moderators: OGRE Team, Hydrax Moderator Group

HOW TO: Integrate Hydrax v0.4 with Caelum

Postby Netskate » Thu Oct 23, 2008 12:31 pm

When you go to integrate these two libraries you can encounter a series of problems.

This little how to should help you to solve these problems in the right way and should give you some "tricks" to avoid them.

This thread will deal only about the ProjectedGrid module (also if some problems are related to both hydrax module).

First of all you had to disable Caelum fog and be sure that setfarclipdistance of your camera is something like 9999*6 (if this setting is 0 you can't see the water).

You had to be sure that hydrax is updated AFTER any camera movement, else the projectedgrid infinite plane stay always a frame back from the camera and it

can't follow the camera correctly.

After you are sure you haven't problem with this you can go forward.

One of the most common problem is a black row in the horizon where hydrax infinite plane meet caelum, something like this:

ImageImage

You have two choice:
1. Waiting for the new hydrax v0.5 version that must have a method like: Hydrax::RttManager::addDisabledClipRenderQueue(...);

2. For now, edit hydrax source. The problem is that Caelum objects are rendered in different rendere queues, as you can see in the

CaelumPrerequisites.h:

Code: Select all
    // Render group for caelum stuff
    // It's best to have them all together
    enum CaelumRenderQueueGroupId
    {
        CAELUM_RENDER_QUEUE_STARFIELD       = Ogre::RENDER_QUEUE_SKIES_EARLY + 0,
      CAELUM_RENDER_QUEUE_MOON_BACKGROUND = Ogre::RENDER_QUEUE_SKIES_EARLY + 1,
        CAELUM_RENDER_QUEUE_SKYDOME         = Ogre::RENDER_QUEUE_SKIES_EARLY + 2,
      CAELUM_RENDER_QUEUE_MOON            = Ogre::RENDER_QUEUE_SKIES_EARLY + 3,
        CAELUM_RENDER_QUEUE_SUN             = Ogre::RENDER_QUEUE_SKIES_EARLY + 4,
        CAELUM_RENDER_QUEUE_CLOUDS          = Ogre::RENDER_QUEUE_SKIES_EARLY + 5,
        CAELUM_RENDER_QUEUE_GROUND_FOG      = Ogre::RENDER_QUEUE_SKIES_EARLY + 6,
    };


This mean that Caelum objects avoid the disableCustomNearClipPlane that Hydrax disable in order to prevent these kind of artefacts.

So, you need to edit hydrax source to add the Caelum render queues which must be disabled.

Go to this file RttManager.cpp (row 497):

and substitute this:

Code: Select all
void RttManager::CReflectionListener::CReflectionQueueListener::renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool

&skipThisInvocation)
   {
      if ((queueGroupId == Ogre::RENDER_QUEUE_SKIES_EARLY || queueGroupId == Ogre::RENDER_QUEUE_SKIES_LATE)
         && mActive)
      {
         mRttManager->mHydrax->getCamera()->disableCustomNearClipPlane();
         Ogre::Root::getSingleton().getRenderSystem()->_setProjectionMatrix(mRttManager->mHydrax->getCamera()->getProjectionMatrixRS());
      }
   }

   void RttManager::CReflectionListener::CReflectionQueueListener::renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool

&skipThisInvocation)
   {
      if ((queueGroupId == Ogre::RENDER_QUEUE_SKIES_EARLY || queueGroupId == Ogre::RENDER_QUEUE_SKIES_LATE)
         && mActive)
      {
         mRttManager->mHydrax->getCamera()->enableCustomNearClipPlane(mRttManager->mPlanes[RTT_REFLECTION]);
         Ogre::Root::getSingleton().getRenderSystem()->_setProjectionMatrix(mRttManager->mHydrax->getCamera()->getProjectionMatrixRS());
      }
   }

with this:
Code: Select all
void RttManager::CReflectionListener::CReflectionQueueListener::renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool

&skipThisInvocation)
   {
      if ((queueGroupId == Ogre::RENDER_QUEUE_SKIES_EARLY || queueGroupId == Ogre::RENDER_QUEUE_SKIES_LATE || queueGroupId ==

(Ogre::RENDER_QUEUE_SKIES_EARLY + 2))
         && mActive)
      {
         mRttManager->mHydrax->getCamera()->disableCustomNearClipPlane();
         Ogre::Root::getSingleton().getRenderSystem()->_setProjectionMatrix(mRttManager->mHydrax->getCamera()->getProjectionMatrixRS());
      }
   }

   void RttManager::CReflectionListener::CReflectionQueueListener::renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool

&skipThisInvocation)
   {
      if ((queueGroupId == Ogre::RENDER_QUEUE_SKIES_EARLY || queueGroupId == Ogre::RENDER_QUEUE_SKIES_LATE || queueGroupId ==

(Ogre::RENDER_QUEUE_SKIES_EARLY + 2))
         && mActive)
      {
         mRttManager->mHydrax->getCamera()->enableCustomNearClipPlane(mRttManager->mPlanes[RTT_REFLECTION]);
         Ogre::Root::getSingleton().getRenderSystem()->_setProjectionMatrix(mRttManager->mHydrax->getCamera()->getProjectionMatrixRS());
      }
   }


now the black row in the horizon should be disappear :)

Another problem you can encounter is that sun, moon and/or other Caelum objects cause artifacts when fall into water. So, because they aren't ogre entities

to avoid this you need to add a specified hydrax depth technique to ALL caelum material objects.

This is the problem:
ImageImage

Add this HydraxDepthTechnique to ALL caelum objects materials, to avoid it:
Code: Select all
technique HydraxDepth
    {
        scheme HydraxDepth
        pass
        {
   lighting off
   texture_unit
         {
            colour_op_ex modulate src_manual src_current 0 0 0
    }
        }
    }


Overcome this annoying problems, you can go forward to tweak hydrax sun's reflects with caelum sun's position, colour, etc.

What we want to do?
We want making sun's reflects move over hydrax water plane, and change its colour in base of the current time (day, night etc). We also want change water

colour to make it more dark when night fall.

To do this, the first thing we need is the sun position. There are two way to calculate it.

1. use this function directly from nature demo (you can find it in the showcase forum):
Code: Select all
Ogre::Vector3 sunPosition = camera->getDerivedPosition();
   sunPosition -= mCaelumSystem->getSun()->getLightDirection() * 80000;

However, in my opinion, this function is not very accurate.

2. it's what I suggest, edit Caelum source adding a getter method for the abstract class BaseSkyLight scene node. In this way you can know the exact

position of every object that extend the BaseSkyLight class, as Sun and Moon :), it's very simple.

In SkyLight.h (around row 103) add this prototype:
Code: Select all
/// get current scene node
Ogre::SceneNode *getSceneNode() const;


in SkyLight.cpp (around row 97) add this method definition:
Code: Select all
Ogre::SceneNode* BaseSkyLight::getSceneNode() const{
   return mNode;
}


Recompile Caelum library, exchanging the old dll in your project with the newest and rebuild your project.

Now all you had to do to get sun or moon position is write a simple function like this:
Code: Select all
Ogre::Vector3 getSunPosition(){
   return caelumManager->getSun()->getSceneNode()->getPosition();
}


More clearly and more accurated, in my opinion.

So now that we can know tha sun position we need to set some hydrax parameters every frame (before calling Hydrax::update();).

They are:
Code: Select all
Hydrax::setSunArea();
Hydrax::setWaterColor();
Hydrax::setSunPosition();
Hydrax::setSunColor();


setSunPosition:
Use one the method descibed above.

setSunArea:
This is a value you can edit or not, I prefer to edit it making the sun area more big when getSunPosition().y is around 0.0
and more small when getSunPosition().y is around his max value (midday), to do this I use a simple linear interpolation.
Note: more small is the value of the sunArea and more big will be it.

setSunColor:
I set this value with "caelumManager->getSun()->getBodyColour()" value.

setWaterColor:
To set this value refer to this thread: http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=8420

in the end, this are the result I have achieved:

http://www.youtube.com/watch?v=TzPpZ1HK-FY

I hope you can do the same, or better and sharing your result with us.

ps: sorry for my bad english, any correction is appreciated.
ps2: thanks to xavyiy for his patience and the help he gave me.

---- EDIT -----
I implement another tweak to avoid that sun reflects is shown on water when sky is cloudy.

There are many solution to do this, but this is the fastest and easiest
solution I have found.

The easiest way was to decrement the alpha value of sun colour in base of the increment of the cloud, this would have made sun reflects fading to trasparent/opaque.
But how xavy told, all the colour in hydrax are contained into a Vector3 instead of a ColourValue to optimize shader calculation (float3 is more fast than float4).

So here my method:
First of all you had to calculate you water "darkest" colour (the colour you would use at sun 0.0 heigth). Call it sunTransparentColour.

After you have done this, when sky is cloudy (choices a value of cloud cover to define it cloudy, for example cloudCover=0.5) instead of set sun colour position as described before, you can set the sun colour in this way:

Code: Select all
mHydrax->setSunColor(getColourLinearInterpolation(0.0,hmHydrax->getSunColor(), 1.0, sunTransparentColour, mCaelum->getCloudCover()));


0.0 and 1.0 are the range of possible cloud cover (as defined in caelum).
getsuncolour is the actual sun color on the water.
suntrasparent colour is the colour calculated before.
getcloudcover is the current cloud cover of caelum.

here the code of the getColourLinearInterpolation:
Code: Select all
   Ogre::Vector3 GameSupport::getColourLinearInterpolation(Ogre::Real Xa,Ogre::Vector3 Ya,Ogre::Real Xb,Ogre::Vector3 Yb,Ogre::Real X){
      const Ogre::Real k = Xa - Xb;
      Ogre::Vector3 temp;

      temp.x = ((((X-Xb)/k)*Ya.x)-(((X-Xa)/k)*Yb.x));
      temp.y = ((((X-Xb)/k)*Ya.y)-(((X-Xa)/k)*Yb.y));
      temp.z = ((((X-Xb)/k)*Ya.z)-(((X-Xa)/k)*Yb.z));
      
      return temp;
   }
Last edited by Netskate on Sat Dec 06, 2008 3:21 pm, edited 3 times in total.
-- N3tsk4t3 --
User avatar
Netskate
 
Posts: 105
Joined: Fri Sep 12, 2008 1:27 am
Location: Messina, Italy

Postby Xavyiy » Thu Oct 23, 2008 5:40 pm

Excelent explanation, and awesome the final Hydrax/Caelum integration video.

Xavi
Xavier Verguí­n González
-------------------------------------------
Hydrax! Ogre3d Water plugin
SkyX! Ogre3d Sky & Clouds plugin
Hydrax-SkyX demo 1.0!
Xavyiy
 
Posts: 264
Joined: Mon Aug 13, 2007 3:52 am

Postby Netskate » Thu Oct 23, 2008 6:52 pm

wouldn't have been possible without you.

thanks
-- N3tsk4t3 --
User avatar
Netskate
 
Posts: 105
Joined: Fri Sep 12, 2008 1:27 am
Location: Messina, Italy

Postby Caphalor » Thu Oct 23, 2008 8:39 pm

Really great work! I had the same problems and they are solved now. :)
But I also have another problem with Hydrax/Caelum concerning underwater rendering.
Image
In addition to the artifacts, the movement of the water and caustic is really strange and all in all not smooth. The problem only appears underwater when using Caelum (it works with a static skybox).
User avatar
Caphalor
 
Posts: 118
Joined: Tue Feb 06, 2007 8:56 pm
Location: Berlin, Germany

Postby Xavyiy » Fri Oct 24, 2008 8:33 am

Add the HydraxDepth techinque to all Caelum materials ;)
Xavier Verguí­n González
-------------------------------------------
Hydrax! Ogre3d Water plugin
SkyX! Ogre3d Sky & Clouds plugin
Hydrax-SkyX demo 1.0!
Xavyiy
 
Posts: 264
Joined: Mon Aug 13, 2007 3:52 am

Postby Caphalor » Fri Oct 24, 2008 10:44 am

Thanks for the answer, but I did that already and it didn't solve the issue. :(

Netskate, does it work for you? You don't show underwater rendering your video...
Last edited by Caphalor on Fri Oct 24, 2008 11:30 am, edited 1 time in total.
User avatar
Caphalor
 
Posts: 118
Joined: Tue Feb 06, 2007 8:56 pm
Location: Berlin, Germany

Postby Netskate » Fri Oct 24, 2008 11:26 am

I don't use underwater effects into my game.

After have seen your problem I tried to add them, and here how they looks:

Image Image

seems to be another strange problem in the horizon with a blank line, and sun doesn't look as should be.

But I haven't set hydrax to disable customfarclipplane for all caelum render queues, can you try this?

ps: the water movement seems to be fine for me in my demo.
-- N3tsk4t3 --
User avatar
Netskate
 
Posts: 105
Joined: Fri Sep 12, 2008 1:27 am
Location: Messina, Italy

Postby Caphalor » Fri Oct 24, 2008 11:57 am

But I haven't set hydrax to disable customfarclipplane for all caelum render queues, can you try this?

That doesn't help. :(
User avatar
Caphalor
 
Posts: 118
Joined: Tue Feb 06, 2007 8:56 pm
Location: Berlin, Germany

Postby Xavyiy » Fri Oct 24, 2008 11:59 am

@Netskate
Post some debug screenshots of hydrax depth map underwater.

Custom near clip plane isn't involved in this problem(It's only for reflections). The fact is that caelum components seems not to be cliped by the near custom clip plane, so I think the problem is related with Caelum more than with Hydrax, I'll look into it as soon as I finish the new Radial grid module.

Xavi
Xavier Verguí­n González
-------------------------------------------
Hydrax! Ogre3d Water plugin
SkyX! Ogre3d Sky & Clouds plugin
Hydrax-SkyX demo 1.0!
Xavyiy
 
Posts: 264
Joined: Mon Aug 13, 2007 3:52 am

Postby Netskate » Fri Oct 24, 2008 12:33 pm

here:

ImageImage ImageImage
-- N3tsk4t3 --
User avatar
Netskate
 
Posts: 105
Joined: Fri Sep 12, 2008 1:27 am
Location: Messina, Italy

Postby Xavyiy » Fri Oct 24, 2008 1:07 pm

Okey, I know what's happening.
The fact is that Caelums components aren't clipped by the custom near clip plane(Only when camera reflection isn't actived, so... it must be an Ogre bug.., I will post it in Developer ogre forum tonight.), but Ogre should be care of this.. so Or it's an Ogre's bug, or Caelum components have some option for not be clippling.
Can you post a post explaining the problem in Caelum's thread?

Xavi
Xavier Verguí­n González
-------------------------------------------
Hydrax! Ogre3d Water plugin
SkyX! Ogre3d Sky & Clouds plugin
Hydrax-SkyX demo 1.0!
Xavyiy
 
Posts: 264
Joined: Mon Aug 13, 2007 3:52 am

Postby bharling » Thu Oct 30, 2008 11:18 am

Fantastic video, any chance of a demo?
JTS System
bharling
 
Posts: 436
Joined: Fri Jun 30, 2006 1:06 pm
Location: UK

Postby Netskate » Thu Oct 30, 2008 2:08 pm

you can download the demo at this url:

http://www.netskate.site90.net/download ... Hydrax.rar
-- N3tsk4t3 --
User avatar
Netskate
 
Posts: 105
Joined: Fri Sep 12, 2008 1:27 am
Location: Messina, Italy

Postby Caphalor » Thu Oct 30, 2008 2:39 pm

Any progress concerning the caelum underwater problem? *bump*
User avatar
Caphalor
 
Posts: 118
Joined: Tue Feb 06, 2007 8:56 pm
Location: Berlin, Germany

Postby Netskate » Thu Oct 30, 2008 3:05 pm

Xavyiy wrote:Okey, I know what's happening.
The fact is that Caelums components aren't clipped by the custom near clip plane(Only when camera reflection isn't actived, so... it must be an Ogre bug.., I will post it in Developer ogre forum tonight.), but Ogre should be care of this.. so Or it's an Ogre's bug, or Caelum components have some option for not be clippling.
Can you post a post explaining the problem in Caelum's thread?

Xavi


I suggest you to post in the Caelum forum and explain your problem.
-- N3tsk4t3 --
User avatar
Netskate
 
Posts: 105
Joined: Fri Sep 12, 2008 1:27 am
Location: Messina, Italy

Next

Return to Hydrax

Who is online

Users browsing this forum: No registered users and 1 guest