HydraX : Strange bugs when rendering scene to a texture

azerty45

08-08-2013 17:00:23

Hello everyone,

I have a strange problem when trying to render a HydraX scene to a texture.

My app renders the scene into :
- A RenderWindow
- A RenderTexture (Grayscale with PF_L8)

Without HydraX, the RenderTexture renders the whole scene correctly (exactly similar to the render window in grayscale)

However, when I use HydraX, the water is not correctly rendered only in the Render Texture (everything is OK in the window) :
- When I pitch the camera so that the horizon is in the lower part of the screen, the water is very dark in the render texture.
- When the horizon is in the upper portion of the screen, some strange reflections like a folding of another part of the scene appear in the Hydrax water, only in the Render Texture.

Pictures below illustrate the problem :
[attachment=1]HydraXRTT.jpg[/attachment]
[attachment=0]HydraXRTT2.jpg[/attachment]



Here is the relevant parts of my code :

- Window/RTT initialization and updating

void OgreSystem::Configure()
{
m_pFrameBuffer = new unsigned char[resX * resY * Ogre::PixelUtil::getNumElemBytes(Ogre::PF_L8)];
m_PixelBox = Ogre::PixelBox(resX, resY, 1, Ogre::PF_L8, m_pFrameBuffer);

m_pWindow = m_pRoot->initialise(true, "Generateur Video");

m_pCamera = m_pSceneMgr->createCamera("Cam");

m_pCamera->setPosition(Ogre::Vector3(0,0,0));
m_pCamera->setNearClipDistance(0.2);
m_pCamera->setFarClipDistance(99999);

Ogre::TexturePtr rtt_texture = Ogre::TextureManager::getSingleton().createManual("RttTex",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_2D, m_resolution_X, m_resolution_Y, 0,
Ogre::PF_L8,
Ogre::TU_RENDERTARGET);

m_pTex = rtt_texture->getBuffer()->getRenderTarget();

m_pTex->setAutoUpdated(false);
m_pTex->addListener(this);

Ogre::Viewport* vp_tex = m_pTex->addViewport(m_pCamera);
vp_tex->setClearEveryFrame(true);
vp_tex->setBackgroundColour(Ogre::ColourValue::Black);
vp_tex->setOverlaysEnabled(false);

m_pCamera->setAspectRatio(Ogre::Real(vp_tex->getActualWidth()) / Ogre::Real(vp_tex->getActualHeight()));

Ogre::Viewport* vp = m_pWindow->addViewport(m_pCamera); // Attache la camera a la vue
vp->setBackgroundColour(Ogre::ColourValue::Black);
m_pCamera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));

}


bool OgreSystem::RenderFrame()
{
m_pRoot->renderOneFrame();

Ogre::WindowEventUtilities::messagePump();

time.reset();
m_pTex->update(true);

// To send texture data over the network
m_pTex->copyContentsToMemory(m_PixelBox, Ogre::RenderTarget::FB_AUTO);

return true;

}


- HydraX config and updating
Draw()
{
// Same problem selecting RTT or Window viewport
//m_pHydrax = new Hydrax::Hydrax(m_pSceneMgr, m_pCamera, m_pWindow->getViewport(0));
m_pHydrax = new Hydrax::Hydrax(m_pSceneMgr, m_pCamera, m_pTex->getViewport(0));


// Create our projected grid module
Hydrax::Module::ProjectedGrid *mModule
= new Hydrax::Module::ProjectedGrid(// Hydrax parent pointer
m_pHydrax,
// Noise module
new Hydrax::Noise::Perlin(/*Generic one*/),
// Base plane
Ogre::Plane(Ogre::Vector3(0,1,0), Ogre::Vector3(0,0,0)),
//Ogre::Plane(Ogre::Vector3::UNIT_Y, Ogre::Real(0.0f)),
// Normal mode
Hydrax::MaterialManager::NM_VERTEX,
// Projected grid options
Hydrax::Module::ProjectedGrid::Options(/*Generic one*/));

// Set our module
m_pHydrax->setModule(static_cast<Hydrax::Module::Module*>(mModule));

m_pHydrax->loadCfg("HydraxTest3.hdx");

m_pHydrax->setShaderMode(Hydrax::MaterialManager::SM_CG);
// Create water
m_pHydrax->create();

if (m_pTerrain != 0)
{
if (m_pTerrain->GetTerrain() != NULL)
{
Ogre::MaterialPtr ptr = m_pTerrain->GetTerrain()->getMaterial();
m_pHydrax->getMaterialManager()->addDepthTechnique(ptr->createTechnique());

m_pHydrax->setPosition(Ogre::Vector3(0.0, -m_pTerrain->GetHauteurOffset() + 5, 0.0));
}
}
}


bool Eau::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
if (m_pHydrax != 0)
{
m_pHydrax->update(evt.timeSinceLastFrame);
}

return true;
}



Why the render texture image is not identical to the renderWindow image in grayscale ? Is there confusions between my RTT and HydraX reflection RTT ?

Without going into details, the rendering into the grayscale texture is important because I send the pixel data in real time over the network to another device which performs specific processing on the pictures.

Any elucidation of this problem would be greatly appreciated !

Thank you in advance