Sign in to follow this  

reflection (use GLSL)solved

This topic is 4730 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

This topic is 4730 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this