Skip to main content
gamedev.net
🔒 Locked 🎯 Unreal

reflection (use GLSL)solved

Started by bybw 1 reply 600+ views
Original Post
bybw
bybw
hello, i've got the my reflection work in fixed pipeline, but i met some trouble when using shader. the reflection texture is already stored in ref_tex and set to texture0.

[Vertex]
void main(void)
{
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_Vertex;
}

[Fragment]
uniform sampler2D tex;
void main (void)
{
gl_FragColor= texture2DProj(tex, gl_TexCoord[0]);
}






glMatrixMode(GL_TEXTURE);
glLoadMatrixf(Mr);
glMultMatrixf(projection);
glMultMatrixf(modelview);

// here i got the texture matrix i've setup, right?

shader.begin();
// get location and set uniform
shader.setUniform1i("tex", 0);

glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, ref_tex);
glEnable(GL_TEXTURE_2D);

// draw water plane
glBegin(GL_QUADS);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0);
glVertex3f(-size, 0, -size);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0);
glVertex3f(-size, 0, size);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1);
glVertex3f( size, 0, size);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1);
glVertex3f( size, 0, -size);
glEnd();

shader.end();







fixed pipeline(use automatically generated texcoord, the reflected image is right): use shader(the image was distorted): i dunno how this could happen. any help would be appreciated. [Edited by - bybw on December 31, 2004 9:13:34 AM]
bybw
bybw
i render the reflection scene with pbuffer, then copy the image to the texutre.
the RTT pass is right, cos i can get the correct result in fixed function pipeline. And the shader is ok, then there must be somethin' wrong in the second pass..

anyone found out some mistakes?
bybw
bybw
ok, solved the problem :)
just made a mistake when calculating the texcoord in vs.
the projtexcoord should be Mprojtex * inPos as Yann described in his article.

[Edited by - bybw on January 1, 2005 6:02:33 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.