PDA

View Full Version : Mirrors and render to texture



JC Miaou
10-21-2002, 04:13 AM
Hi everybody,

I need some help about planar reflection.
I want to use the "render to texture" way because it is then easy to apply effects on resulting texture (like waves for example).

Here is what I do :

1) Render the scene from the "mirror point of view" (that is from the mirrored eye position)
2) copy the frame buffer to texture with glCopyTexSubImage2D
3) compute X,Y window coordinates of the mirror vertices with gluProject
4) glScissor with the resulting 2D bounding frame
3) compute U,V texture coordinates of the mirror vertices using viewport definition
4) Render the scene from the eye point of view

The issues are :
1) when I draw the mirror, the texture seems to be deformed. Have to set a special texture matrix ? Is it due to perspective correction when the texture is applied ?
2) when the mirror is partially out of window when rendering from the mirrored point of view, the resulting texture coordinates (computed from gluProject and viewport) are out of bounds [0,1] : out-of-memory texture part is displayed on the mirror !

thanks.

Madoc
10-22-2002, 02:50 AM
I suppose the distortion you see is indeed something to do with how the texture is interpolated. I see the same distorion in my render to texture reflections if the polygons are large on screen. I'm not sure why there is so much distortion nor would I know how to correct it.
The seams you see at the edges of the screen are a result of the same problem. This you can correct by increasing the field of view when rendering to texture so as to give the texture some margin to work with, also useful when you begin applying perturbations.

JC Miaou
10-22-2002, 10:53 PM
Thanks a lot Madoc. I am happy to see I am not the only one with this kind of problem. I have been searching with google and in OpenGL forums for a long and nobody was talking about this issue !


Originally posted by Madoc:
I see the same distorion in my render to texture reflections if the polygons are large on screen. I'm not sure why there is so much distortion nor would I know how to correct it.

Maybe I could try to refine my mirror mesh (which is a simple quad) in order to reduce the distortion introducing more vertex for the texture interpolation.


Originally posted by Madoc:
... you can correct by increasing the field of view when rendering to texture so as to give the texture some margin to work with.

I think it is a good idea but I will not have a real mirror anymore.