Planar reflection help


#1

Hi!

I have a water shader where I’ve added a cloudy texture to simulate reflections.
It works well as it follows the camera, but when I turn the camera the texture follows the rotation.
How can I stop the rotation?

[video=youtube_share;qOB7f5olcFs]https://youtu.be/qOB7f5olcFs[/video]

From vertex shader:

vec3 vEyeNormal = gl_NormalMatrix * gl_Normal;

vec4 vVert4 = gl_ModelViewMatrix * gl_Vertex;
vec3 vEyeVertex = normalize(vVert4.xyz / vVert4.w);
vec4 vCoords = vec4(reflect(vEyeVertex, vEyeNormal), 0.0);
RefTexcoord.xyz =normalize(vCoords.xyz);

From frag shader:

vec4 refImage = texture2D(refMap, vec2(RefTexcoord.x, RefTexcoord.y));

Cheers!


#2

By reflecting a world-space vector rather than an eye-space vector.

E.g.


vec3 eye_w = gl_ModelViewMatrixInverse[3].xyz;
vec3 incident = gl_Vertex.xyz - eye_w;
vec3 reflected = reflect(incident, gl_Normal);
vec3 RefTexcoord =normalize(reflected);
...


#3

That did the trick!
Thank you!!