View Full Version : Render to texture projection onto plane

06-23-2004, 11:58 AM
I'm trying to render my scene to a texture then project it onto a water plane, and so far it works except for one little problem. When i'm looking at the water plane, on both sides of the viewing volume, the texture has been cut off. Here's what i'm talking about.

problem (http://cs.selu.edu/~soconnell/reflection3.jpg)

Here's the code i'm using.

code (http://cs.selu.edu/~soconnell/code.txt)

Does anybody know what is wrong?

06-23-2004, 02:41 PM
It looks like the view you rendered to texture doesn't include everything the normal view does.

What do you get if you render to the screen the view you are rendering to the texture?

06-23-2004, 02:55 PM
If I render to the screen what I render to the texture, its just a square block on the screen and has exactly what is suppose to be rendered.

But I tried changing the aspect ratio in the projection from 1, to the same aspect when rendering normally, since 256/256 = 1.

Anyway, that got rid of the side cutoffs, but now if I zoom way out or zoom way in, the reflection becomes distorted or moves away from the actualy geometry it is underneath.

Here's two screenshots of it actually working
working (http://cs.selu.edu/~soconnell/reflection4.jpg)
working (http://cs.selu.edu/~soconnell/reflection5.jpg)

But if I zoom way out and move from side to side, then the reflection of the mountains in the water moves away from the actualy terrain.

And if I zoom in, it becomes distorted like in these screenshots
working (http://cs.selu.edu/~soconnell/reflection6.jpg)
working (http://cs.selu.edu/~soconnell/reflection7.jpg)

06-23-2004, 03:11 PM
Isn't it supposed to look like that? (distorted?)

I dunno, I thought that's what real-life reflections such as those in your pics do :confused:

06-23-2004, 03:57 PM
Well maybe the flattening of the hills is normal, but what about that cuttoff problem? The only thing I can figure is that somehow the viewport isn't being stretched right or projected correctly.

Here's an example

wierd (http://cs.selu.edu/~soconnell/reflection8.jpg)

06-23-2004, 04:06 PM
More distortion and stretching towards the camera and more ripples in water? like these?
water_1 (http://www.acclaimimages.com/_gallery/_SM/0020-0405-1916-5516_SM.jpg)

water_2 (http://www.codemasters.com/dragonempires/imagelibrary/JanWebSiteGWE2.jpg)

06-23-2004, 05:02 PM
Here are some more screenshots of what I'm talking about.

I show what's being rendered to texture as well as the actual scene in these 2 images so you can see how it must be something wrong with the projection. Or at least I think.

image 1 (http://cs.selu.edu/~soconnell/reflection9.jpg)
image 2 (http://cs.selu.edu/~soconnell/reflection10.jpg)

I would really appreciate it if someone could tell me whats wrong with my code. PLEASE !!!!!!!

06-23-2004, 05:18 PM
Well, when you 'squash' the reflected landscape, you're doing so by tilting the quad onwhich the reflection is rendered. Normally that will expose skewed edges that are a bit too small.

I wouldn't know how to fix this, other than stretching your quad along with its texture coordinates, based on the amount of 'tilt'.

06-23-2004, 06:27 PM
Well there is no quad that is being rendered to. Its simply the screen itself. If you look at the small window I've created, you see exactly what is being rendered to the texture. My problem is that the water plane does not 'stretch' the texture correctly when i zoom in too close, that's the problem. Something is wrong with the projection.

Tom Nuydens
06-23-2004, 11:17 PM
Shouldn't you be using object linear texgen instead of eye linear?

-- Tom

06-24-2004, 02:11 AM
Oh, I actually got it to work correctly.

All I did was simply change the aspect ratio in RenderGLSceneToTexture and in loadProjectionMatrix to 4.0 / 3.0, and now it works fine. Go figure....

06-24-2004, 10:35 AM
Well now that I figured out what I was doing wrong, does anybody have any suggestions or links to sites that show how to do water distortion? Preferably a vertex shader technique or just plain old math on the cpu.