Render to texture projection onto plane

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.


Here’s the code i’m using.


Does anybody know what is wrong?

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?

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

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

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:

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


More distortion and stretching towards the camera and more ripples in water? like these?


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
image 2

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

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’.

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.

Shouldn’t you be using object linear texgen instead of eye linear?

– Tom

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…

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.