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.

Thursday, October 16, 2008

My First International Conference--ICSC'2008

Congratulations to RickChang and myself!!! Last Sat., we have the fistr experience for attending International Conference, haha!!

The conference was originally hold in Sichuan Province. Because of the big earth quake in May, the venue was changed to Fragrant Hill Hotel, Beijing. What what what a pity, my side-trip to JiuZhai is gone. Anyway, it's still exciting, some pictures for memory.

IMG.1 Doing my presentation, ~~nervous

IMG.2 Doing my presentation

IMG.3 Waiting for lunch, so relax^_^

IMG.4 Smile & Sunshine

Wednesday, October 15, 2008

Shadow for Ogre

Additive shadow in Ogre can generate more realistic effect than other shadow technic. When I adopt it in my project, there're so many problem. Now, i've got rid of them^_^, just share the experience with whoever being in trouble with the same problem.

The scene is composed of a runtime generated terrain, and a lander. I want the lander can cast shadow on terrain. The lander and terrain are rendered by custom CG shader. The main light of the scene is a directional light, and on the top of lander, there're two small indicator light, which are simulated by two directional light. You can see from the followed graphic

At first, after setting the standard parameter for additive shadow, i can not generate any shadow on terrain.
Laterly, although there are shadow on the terrain, but when the lander move to the terrain, a white plane will flicker on the terrain. My Gosh!!!

For the first problem, if the object is rendered with custom shader, some changes for the object's material must be involved:
If the cast shadow object using hardware skinned technich, you must define the vertex program for rendering the shdow texture. Otherwise, Ogre will return to use fixed function, and any change of vertext will be eliminated. But if the custom shader do not change the vertex data, just for lighting effect, there's no need to define "shadow_caster_vertex_program_ref".
shadow_caster_vertex_program_ref myShadowCasterVertexProgram
param_indexed_auto 0 worldviewproj_matrix
param_indexed_auto 4 ambient_light_colour

If the receive shadow object using custom shader, while you need to define both the vertex and fragment shader. Please remember you should do it under any situation. The previous one is generate the texcoord for shadow texture, and the later one is sample the shadow texture to modulate the lighting effect of the object.
shadow_receiver_vertex_program_ref myShadowReceiverVertexProgram
param_indexed_auto 0 worldviewproj_matrix
param_indexed_auto 4 texture_viewproj_matrix
shadow_receiver_fragment_program_ref myShadowReceiverFragmentProgram
param_named_auto lightDiffuse light_diffuse_colour 0

The second problem is very boring. I spend three days to solved it. I just want the direction main light can generate shadwo, so I turn on the setCastsShadows character of this light, and turn off the correspondence character of the other two spot light. But in actually when excute the diffuse pass rendering, all the light was iterated, so the material is change to "iteration once_per_light directional". "directional" means only the directional light will be iterated.

Well, some pictures of final effect, haha

Sunday, January 13, 2008

Lunar Surface Rendering with Ogre3D(1)

It's my great honor to annouce that, Miss Mandy WANG, has her first blog published ^_^!!!

First, post some picture for my recent work-----Lunar Surface Rendering.

Big big thanks to ZhongHua Song, the images and data you provided is a great help for the project, really excellent work!!!