GLSL reflection. Camera position problem
Hi,
I am making reflection/refraction on my water surface using cube mapping. I need to compute incident vector from my eye position and vertex position. I have a problem with position of my camera. I use glLookAt to set camera. In nVidia SDK I found "dispersion" tutorial and there is camera position multiplayed by ViewInverse matrix (in vertex shader) to get position in eye space. I don't know how to obtain this matrix after using glLookAt. I know that DirectX actually have this matrix. But I wan't to know how to do it in OpenGL. I know how to compute inverse matrix, so only I need to know how to get this matrix. Can you help? Thanx a lot! :-)
A/ if youre using glsl u can obtain that in the vertex shader gl_MVInverse (or someit)
B/ all u need is a matrix44 inverse function (majority of math libs have this)
u can get the mv matrix44 by using glGetFloatv( GL_MODELVIEW_MATRIX, mv );
B/ all u need is a matrix44 inverse function (majority of math libs have this)
u can get the mv matrix44 by using glGetFloatv( GL_MODELVIEW_MATRIX, mv );
No, this is not what I am asking. I don't need ModelViewMatrix, just ViewMatrix. This is from NVIDIA SKD dispersion demo. I need to know how to get that viewInverse matrix and it's not ModelView. Vertex shader will look something like this.
// outputsvarying vec3 normal;varying vec3 incident;// uniform inputsuniform vec4 eyePos;uniform vec4 displace;uniform mat4 viewInverse;void main(){ // deformation float deformation = sin(gl_Vertex.y * displace.x + displace.y) * displace.z; vec4 position = (gl_Vertex + vec4(gl_Normal, 1.0) * deformation); // transform normal to world space normal = gl_NormalMatrix * gl_Normal; // mul by modelIT // transform position to world space vec4 worldPos = gl_ModelViewMatrix * position; // mul by model // transform eye position to world space vec4 worldEyePos = viewInverse * eyePos; // calculate incident vector incident = worldPos.xyz - worldEyePos.xyz; // output position gl_Position = gl_ModelViewProjectionMatrix * position;}[\source]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement