ok, this is slowly driving me crazy and I've reached the point where i've spent far too long trying to work out the problem, i'm starting to go blind due to lack of sleep and frustation is bring on a headache, mostly coz I have this horrible feeling its going to be a simple answer to my question [crying]
Ok, having read the thread
here about Water reflections between Yann and Mephs I thought i'd have a go at producing a reflection on a plane using a projected texture myself.
So I went about modifiying a test app i've got and butchered some GLSL shadow mapping code to do the projective bit, cross referenced with the thread above, a book and google.
First problem to hint, for some reason my RTT wasnt Rendering, but I thought i'll forgo that problem for now, instead deciding to concetrate on the issue of making sure my projectivive texture coordinates where in the right range, so at least i knew that bit was right, the outcome was
this (the image is textured onto a quad which extends -5,-5 => 5,5 on the XZ plane where Y=0 to try to make my life easier).
Now, unless i'm going crazy, if my texture matrix and GLSL programs were right, there should only be one ghost on the quad and it shouldnt be sheared like that.
The image in question is a 128*128*32 texture, which is fine and perfectly alined on other objects which are normaly in scene.
the texture is setup thusly
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D,GL_GENERATE_MIPMAP,GL_TRUE);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,psimage->getWidth(),psimage->getHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,(unsigned char *)psimage->getPixels());
I'm using the following code to setup the texture matrix to perform the projection
SetCamera(); // sets camera up so its 4 units up, 14 back and rotated 45 degrees downwards on the X axis
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
// bind reflection texture to unit zero
ReflectionProg->useIt();
ReflectionProg->sendUniform("reflectTex", 0); // tell the programs where to find the texture
glMatrixMode(GL_TEXTURE);
{
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
ReflectScene();
glGetFloatv(GL_MODELVIEW_MATRIX,viewMatrix);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glGetFloatv(GL_PROJECTION_MATRIX,ProjMatrix);
glMatrixMode(GL_TEXTURE);
glLoadMatrixf(viewMatrix);
glMultMatrixf(ProjMatrix);
glMultMatrixf(remapMatrix);
}
glMatrixMode(GL_MODELVIEW);
glBindTexture(GL_TEXTURE_2D, texture[1]);
DrawReflectionSurface();
ReflectionProg->disableIt();
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
ReflectionProg is an object which holds the vertex and fragment programs (GLSL)
the various matrices are all glfloat var[16].
remapMatrix is defined thus:
GLfloat remapMatrix[] = {0.5,0.0,0.0,0.5,
0.0,0.5,0.0,0.5,
0.0,0.0,0.5,0.5,
0.0,0.0,0.0,1};
and the GLSL progs are as follows:
// Vertex
varying vec4 projCoord;
void main()
{
projCoord = gl_TextureMatrix[0] * gl_Vertex;
gl_FrontColor = vec4(1.0,1.0,1.0,1.0);
gl_Position = ftransform();
}
// Fragment
uniform sampler2D reflectTex;
varying vec4 projCoord;
const vec4 ambient = vec4(0.13), boost = vec4(1.06);
void main()
{
vec4 reflectionValue = texture2D(reflectTex, projCoord.xy);
gl_FragColor = boost * gl_Color * reflectionValue + ambient;
}
All of which compile fine.
As I said, i'm probably missing something simple but i'll be damned if I can see where and lack of code for showing how to construct this matrix isnt helpping (Nvidia have a paper which says the texmatrix = remap*proj*view*model, which is what i thought i was doing... [crying])
I'm going to get some sleep now, any help would be appricated [smile]
[help]