Wednesday, April 8, 2009

Hydrax ---- OpenGL Version

       Hydrax is an excellent Ocean Addons for Ogre. Now, I want to make use of it in my project. Thanks for Xavyiy's great work. Download link at: http://www.ogre3d.org/wiki/index.php/Hydrax

        Although, Xavyiy has written all shaders for HLSL and CG, there're still some artifacts, when run the executable file directly in OpenGL Mode. These days, I made some modification to run Hydrax in OpenGL properly. The modification can be summarized as follow:

1.  Fresnel Texture
        When run in OpenGL mode, there're some mistake for CG reading 1d texture"Fresnel.bmp" for WaterMaterial and UnderWaterMaterial. The ocean surface looks like with no correct normals as Fig.1. This problem can be fixed by hardly change the "Fresnel.bmp" as a 2d texture, with size of 256x1. Result can be see in Fig.2.
















Fig1. Ocean Surface with wrong normal vectors.               
















Fig2. Ocean Surface with correct normal vectors.

2.  UnderWaterMaterial's ScaleMat
        When  the viewpoint stays under water, the underwarter reflect shows wrong reflect direction, as Fig.3. I changed the ScaleMat in UnderWaterMaterial as :
ScaleMat = float4x4( 0.5, 0, 0, 0.5,
       0, 0.5, 0, 0.5,
       0, 0, 0.5, 0.5,
       0, 0, 0, 1);




    











Fig3. Wrong reflection direction under water.                            
















Fig4. Correct reflection direction under water.

3.  RTT Error for DepthCompositor
      I found when the viewpoint moves under the horizon, there're many RTT textures were created and destroyed every frame. The FPS droped heavely. Just comment the following code in Hydrax::setWaterColor(const Ogre::Vector3 &WaterColor) can solve the problem. The RTT texture will only create once when move under horizon.
if (getHeigth(mCamera->getDerivedPosition()) > mCamera->getDerivedPosition().y-1.25f)
{
if (mMaterialManager->isCompositorEnable(MaterialManager::COMP_UNDERWATER))
{
mMaterialManager->setCompositorEnable(MaterialManager::COMP_UNDERWATER, false);
mMaterialManager->setCompositorEnable(MaterialManager::COMP_UNDERWATER, true);
}
}

        Finally, give some screen shot for my OpenGL version Hydrax effect. Next few days, I'll combin Hydrax with Caelum together.

   Fig5. Ocean surface effect for OpenGL version Hydrax.


  Fig6. Under water effect for OpenGL version Hydrax.


Fig7. Under water GodRay effect for OpenGL version Hydrax.




3 comments:

  1. Could you post this with demo on Hydrax forums please?

    I need this

    ReplyDelete
  2. i have the same problems on my mac.
    could you please elaborate more on where to make this changes? AFAIK there are not much shader files but most of them get assembled at runtime, depending on the configuration. and i am a bit overwhelmed with the whole Hydrax sourcecode ...
    thanks in advance!

    ReplyDelete
  3. What did you mean by "hardly change the "Fresnel.bmp" as a 2d texture, with size of 256x1" ?

    ReplyDelete