   Water uv distortion issue
  I'm trying to implement uv distortion for my water shader but i'm doing something wrong. Here's the image with the shader applied:Now notice that the reflection is a bit off. When not including this line in the shader:projCoord.xy += N.xy*0.05f;   Everything lines up perfectly but of course, there's no distortion going on. What follows is the full fragment shader.uniform sampler2D tex,norm;varying vec2 texCoord0;varying vec4 viewCoords;varying vec4 pos;void main(){   vec3 N = texture2D(norm, texCoord0*8);   vec4 projCoord = viewCoords / viewCoords.q;   projCoord = (projCoord + 1.0) * 0.5;   projCoord.xy += N.xy*0.05f; projCoord = clamp(projCoord, 0.001, 0.999);   gl_FragColor = texture2D(tex, projCoord.xy);}What i do is render the clipped upside down world in a texture using the current camera and the project the texture onto the water plane.So what options do i have to correct the issue?   
  I think converting rgb to xyz is this:projCoord = (projCoord * 2.0) - 1.0;   ;Quote:Original post by GumgoI think converting rgb to xyz is this:projCoord = (projCoord * 2.0) - 1.0;God, i'm so dumb! Well, sorry for that, you were right![Edited by - Deliverance on May 17, 2010 8:59:20 AM];  Bump.. If i need to provide further details please ask an i'll gladly mention them.   ;  I think that you forgot to "uncompress" N from [0..1] to [-1..0..1]. Try out:uniform sampler2D tex,norm;varying vec2 texCoord0;varying vec4 viewCoords;varying vec4 pos;void main(){   vec3 N = texture2D(norm, texCoord0*8);   // map from [0..1] to [-1..0..1]   N = N * 2.0 - 1.0;   vec4 projCoord = viewCoords / viewCoords.q;   projCoord = (projCoord + 1.0) * 0.5;   projCoord.xy += N.xy*0.05f; projCoord = clamp(projCoord, 0.001, 0.999);   gl_FragColor = texture2D(tex, projCoord.xy);};  print out what values N.xy contains, find out their ranges.. do they contain negative values or not, etc?it looks like a quite big shift, so it might be that you think their values are from -1 to 1, but they are from 0 to 1, and thus quite off..so how about (N.xy * 2 - 1) * 0.05?if that doesn't work, just find out the values of the numbers (by mapping them to different guessed ranges, and looking at the colour output on screen)   ;Quote:Original post by davepermenprint out what values N.xy contains, find out their ranges.. do they contain negative values or not, etc?it looks like a quite big shift, so it might be that you think their values are from -1 to 1, but they are from 0 to 1, and thus quite off..so how about (N.xy * 2 - 1) * 0.05?if that doesn't work, just find out the values of the numbers (by mapping them to different guessed ranges, and looking at the colour output on screen)Thanks, i was misconverting from rgb[0..1] to xyz[-1..1].   