View Full Version : problem with full screen projective texture

05-02-2010, 07:19 PM
I try to do refraction effect on water surface using full screen projective texture

by transform vertex position to post w space and then move it from -1,1 to 0,1 then interpolate it using key word "noperspective"

this give correct result for the most part except when viewing from very low altitude (at the same level with projected surface) there will be some garbage pixel.

The code (GLSL 1.5) below is how I calculate my fullscreen projective texture coordinate

uniform mat4 cameraMatrix;
uniform mat4 modelMatrix;
uniform mat4 projectionMatrix;

noperspective out vec2 intProjTexCoord;

void main()

mat4 modelviewMatrix = cameraMatrix*modelMatrix;

gl_Position = projectionMatrix*modelviewMatrix*vec4(vertex.xyz,1 .0);

//calculate full screen projective texture coordinate here
intProjTexCoord = ((gl_Position.xy/gl_Position.w)+1.0)*0.5;


this image show the error when viewing at low altitude.
The red part is where texture projected on planar mesh.

http://www.freeimagehosting.net/uploads/th.50f1ffdf70.jpg (http://www.freeimagehosting.net/image.php?50f1ffdf70.jpg)

and this is when view at higher altitude (no error)

http://www.freeimagehosting.net/uploads/th.c06b99317f.jpg (http://www.freeimagehosting.net/image.php?c06b99317f.jpg)

If the method I use is not the best method can someone suggest me how to correctly do this ?