Render to texture water reflection
Render to texture water reflection
I am trying to make my own water scene node. I have a big plane, and i flip the screen upside down and render that to the texture for the reflection. But the problem is it doesn't line up on my plane to where it is suppose to.
How on earth am i ment to line up the RTT'ed texture so that it looks like its in the correct place?
Has somebody perhaps got an example of this already? I have seen shader ones which didn't look right, and i have tried a mirror scene node i found in the code snippets but it did not have the desired effect.
thanks for your help,
esaptonor
How on earth am i ment to line up the RTT'ed texture so that it looks like its in the correct place?
Has somebody perhaps got an example of this already? I have seen shader ones which didn't look right, and i have tried a mirror scene node i found in the code snippets but it did not have the desired effect.
thanks for your help,
esaptonor
-
hey_i_am_real
- Posts: 44
- Joined: Thu Sep 28, 2006 2:27 pm
- Location: Europe
If you mean like your water shader, i tried to avoid that as it doesn't work very well when the water is large.
I am trying to replicate what was done here: http://www.gametutorials.com/gtstore/pc ... part6.aspx
doesn't seem like you can download that anymore, ill post some code. Its all in opengl.
this is just a snippet from where they get the reflection. I don't know opengl, but to me it seems as though all they are doing is rendering to a texture like i am trying to do...but their one works!
somehow their reflection lines up perfectly...
I am trying to replicate what was done here: http://www.gametutorials.com/gtstore/pc ... part6.aspx
doesn't seem like you can download that anymore, ill post some code. Its all in opengl.
this is just a snippet from where they get the reflection. I don't know opengl, but to me it seems as though all they are doing is rendering to a texture like i am trying to do...but their one works!
Code: Select all
// Change the view port to be the size of the texture we will render to
glViewport(0,0, textureSize, textureSize);
// Clear the color and depth bits, reset the matrix and position our camera.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
g_Camera.Look();
// So we don't affect any other objects in the world we push on a new matrix
glPushMatrix();
// If our camera is above the water we will render the scene flipped upside down.
// In order to line up the reflection nicely with the world we have to translate
// the world to the position of our reflected surface, multiplied by two.
if(g_Camera.Position().y > waterHeight)
{
// Translate the world, then flip it upside down
glTranslatef(0.0f, waterHeight*2.0f, 0.0f);
glScalef(1.0, -1.0, 1.0);
// Since the world is updside down we need to change the culling to FRONT
glCullFace(GL_FRONT);
// Set our plane equation and turn clipping on
double plane[4] = {0.0, 1.0, 0.0, -waterHeight};
glEnable(GL_CLIP_PLANE0);
glClipPlane(GL_CLIP_PLANE0, plane);
// Render the world upside down and clipped (only render the top flipped).
// If we don't turn OFF caustics for the reflection texture we get horrible
// artifacts in the water. That is why we set bRenderCaustics to FALSE.
RenderWorld(false);
// Turn clipping off
glDisable(GL_CLIP_PLANE0);
// Restore back-face culling
glCullFace(GL_BACK);
}
else
{
// If the camera is below the water we don't want to flip the world,
// but just render it clipped so only the top is drawn.
double plane[4] = {0.0, 1.0, 0.0, waterHeight};
glEnable(GL_CLIP_PLANE0);
glClipPlane(GL_CLIP_PLANE0, plane);
RenderWorld(true);
glDisable(GL_CLIP_PLANE0);
}
// Restore the previous matrix
glPopMatrix();
// Bind the current scene to our reflection texture
glBindTexture(GL_TEXTURE_2D, g_Texture[REFLECTION_ID]);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
