Tuesday, April 14, 2009

Hydrax + Caelum

I have integrated the Hydrax 0.5 and Caelum 0.4 in my project.  Thanks for Xavyiy and Cdleonard's great work. And the topic HOW TO: Integrate Hydrax V0.4 with Caemum in Ogre forum also give me a great favor.
First some screen shot of my recenly work. All of them are rendered by OpenGL and CG. Some detail information can be found in my previous post.

Except for the problems metioned in forum topic, I also solved some new problems
1. I found PointStarFiled can not reflect on ocean surface. This problem can be solved by changing material StarPoint's atrribute cull_hardwar as none.

material Caelum/StarPoint
{
...........................

            // Works with default culling:
            cull_hardware clockwise
            
...........................
}

2. I'm very pleased with the visual effect of Hydrax. However, using Hydrax has been a very large perfomance hit for us.  I test the project grid with perlin noise. I found noise calculation is the bottleneck of the CPU. So I excute void Perlin::_calculeNoise() in another thread. The modification is very small, only take care about memory protection is enough.

3. The water doesn't follow the camera expecially when rotate the camera horizontally, see the screeshot as example. 

The project grid's lagging can be solved by streching the projected water area. The project area is determinde by four conner point, so the code is changed as red color shows:
bool ProjectedGrid::_renderGeometry(const Ogre::Matrix4& m,const Ogre::Matrix4& _viewMat, const Ogre::Vector3& WorldPos)
{
t_corners0 = _calculeWorldPosition(Ogre::Vector2( 0.0f, 0.0f),m,_viewMat);
t_corners1 = _calculeWorldPosition(Ogre::Vector2(+1.0f, 0.0f),m,_viewMat);
t_corners2 = _calculeWorldPosition(Ogre::Vector2(-0.2f,+1.0f),m,_viewMat);
t_corners3 = _calculeWorldPosition(Ogre::Vector2(+1.2f,+1.0f),m,_viewMat);
                ........................
       }

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.