Skip to main content
GameDev.net gamedev.net
🔒 Locked

reflection using projective texturing [solved]

Started by rotalever Sep 12, 2006 at 12:53 PM 6 replies 900+ views
Original Post
rotalever
rotalever
Hi, I'm trying to implement a water system. For the reflection I render the whole (clipped) Scene into a Texture. In the second rendering step I use this texture and project it onto a plane to get the reflections. It does actually work good, but with some errors you see in the screenshot. Both screenshots show the same scene from different viewpoints and camera angles. You see that the reflections looks good in the center (green arrow) but left and right of it bad (red arrow). http://img236.imageshack.us/my.php?image=screenpos1he8.png http://img236.imageshack.us/my.php?image=screenpos2sq8.png Here is the relevant Code (which draws the texture into the scene), I dont know what went wrong.. glMatrixMode(GL_TEXTURE); glLoadIdentity(); glTranslatef(0.5f, 0.5f, 0.0f); glScalef(0.5f, 0.5f, 1.0f); glMultMatrixd( projmatrix ); glMultMatrixd( mvmatrix ); glMatrixMode(GL_MODELVIEW); glBindTexture(GL_TEXTURE_2D, mirrorTex); glBegin(GL_TRIANGLE_STRIP); glTexCoord3f(-300.0f,20.0f,-300.0f); glVertex3f(-300.0f,20.0f,-300.0f); glTexCoord3f(-300.0f,20.0f,300.0f); glVertex3f(-300.0f,20.0f,300.0f); glTexCoord3f(300.0f,20.0f,-300.0f); glVertex3f(300.0f,20.0f,-300.0f); glTexCoord3f(300.0f,20.0f,300.0f); glVertex3f(300.0f,20.0f,300.0f); glEnd(); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); edit: In my opinion the texture is not scaled correctly!? But why? [Edited by - rotalever on September 13, 2006 1:09:30 PM]
jfdegbo
jfdegbo
Hello,

i don't know where your problem come from, but i ask myself why the hell you would like to do such texture projection ... keep your reflected scene (first pass) in frame buffer and render then the upper scene without drawing the water plane (or rendering it with any blending enabled)

Really don't understand why you make things so complicated... or I am totally missing something here ?

JFD
_____My little engine : I.E.
rotalever
rotalever
Quote:
Original post by jfdegbo
i don't know where your problem come from, but i ask myself why the hell you would like to do such texture projection ... keep your reflected scene (first pass) in frame buffer and render then the upper scene without drawing the water plane (or rendering it with any blending enabled)

If you only want a simple reflection (mirror) this would be the best way. But in the end, I would like to have a water surface. And as you know water is not completely flat. Therefore I render the mirrored scene onto a texture and display that texture by using a plane. Later I will create waves on the plane. This waves will deform the reflection ( the projected texture ) as well. With rendering the mirrored scene directly to the framebuffer I cannot get a wave effect.

rotalever
Falhar
Falhar
i think you need to set Ortho projection and draw the texture .. as it is seen normaly when renderet directly.
rotalever
rotalever
Just using glOrtho like this?
glMatrixMode(GL_TEXTURE);glLoadIdentity();glTranslatef(0.5f, 0.5f, 0.5f);glScalef(0.5f, 0.5f, 0.5f);glMultMatrixd( projmatrix );glMultMatrixd( mvmatrix );glMatrixMode(GL_PROJECTION);glPushMatrix();    glLoadIdentity();    glOrtho (-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);    glMatrixMode(GL_MODELVIEW);        ... /*Doing some translations*/    glBindTexture(GL_TEXTURE_2D, mirrorTex);    glBegin(GL_TRIANGLE_STRIP);        glTexCoord3f(-300.0f,20.0f,-300.0f); glVertex3f(-300.0f,20.0f,-300.0f);        glTexCoord3f(-300.0f,20.0f,300.0f); glVertex3f(-300.0f,20.0f,300.0f);        glTexCoord3f(300.0f,20.0f,-300.0f); glVertex3f(300.0f,20.0f,-300.0f);        glTexCoord3f(300.0f,20.0f,300.0f); glVertex3f(300.0f,20.0f,300.0f);    glEnd();glPopMatrix();glMatrixMode(GL_TEXTURE);glLoadIdentity();glMatrixMode(GL_MODELVIEW);

This does not work: More precisely: I do not see the water plane.
rotalever
rotalever
I found the bug! When I rendered the texture, I set the viewport to 512x512 (window is 1024x768). Now I thought I had to set gluPerspective(angle, 512/512, 1.0f, 1000.0f); with "512/512" = 1 when rendering the texture. This was the error. Even with a 1:1 texture I have to use the same relation (4:3) as with my window...

rotalever

Topic Locked

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

Sign in to reply to this topic.