Problems with RenderTexture

Hi,

I’m trying to create a water effect, I render the scene in a render texture, and then I draw the fluid nodes in the top of the texture applying a simple refraction shader to this texture.

In the first attempt, I added the fluid node to the render texture (well, it was added in a child of the RTT). It worked nice in the PC and mac, but when I tested the effect in a mobile device, I saw that the texture was corrupt. I suppose that in mobile devices I can’t use the content of a texture as a input of another shader before end to render on it.

You can see the effect in a mac an in an iPad in these screenshots;


An the code in this:

Texture2D *bkgTex = GraphicsManager::getInstance()->getMainTexture(); //the texture of the rtf in where I render the scene

m_node = FluidNode::create((Fluid *)fluid, bkgTex);

Node *parent = GraphicsManager::getInstance()->getTilesNode(); //tilesNode is a child of the mainTexture

parent->addChild(m_node, 2);

Then I tried to detach the fluid node from the main texture and draw it later, but I had to position properly the fluid node as if it was a tiles node child, so I used this approach:

Texture2D *bkgTex = GraphicsManager::getInstance()->getMainTexture();

m_node = FluidNode::create((Fluid *)fluid, bkgTex);

Node *parent = GraphicsManager::getInstance()->getMainLayer(); // the main layer of the scene

parent->addChild(m_node, 7);

but since the tiles node position change with the scroll, I changed the draw method of the fluid node in order to use the model view matrix of the tiles node:

Mat4 tilesTtransform = GraphicsManager::getInstance()->getTilesNode()->getNodeToWorldTransform();

m_customCommand.init(_globalZOrder);
m_customCommand.func = CC_CALLBACK_0(FluidNode::onDraw, this, tilesTtransform, flags);
Director::getInstance()->getRenderer()->addCommand(&m_customCommand);

but I can see that the fluid node is renderer with a wrong offset:

I don’t know how to resolve this issue. how I should get the correct transform of the node? Is the draw code OK? please, any help would be appreciated.

Thanks in advance.