Title: GLSL vertex interpolation question/problem Post by: cKleinhuis on April 13, 2013, 09:18:20 PM hi there, some of you seem to be perfect for helping me out with my current problem:
i want to do a vertex interpolation in the vertex shader i am using a fixed pipeline attribute for giving the shader a secondary coordinate -> gl_Normal i am somehow encountering a very strange problem, which i thought has to do with the "w" component, but this does not seem to be the issue, what is the problem ? the problem is that when i put the same coordinate in GL.vertex3f(mycoordinate) GL.normal(mycoordinate) they are NOT THE SAME ... ??? i am blending linearly between them: vec3 vertex=mix(gl_Vertex.xyz,gl_Normal.xyz,interpolationvalue); and after the interpolation i calculate the final position with: gl_Position = gl_ModelViewProjectionMatrix * vec4(vertex,1); and, i thought the position should not change the slightest, but it is somehow strange, because the points actually move ... :( any ideas !? Title: Re: GLSL vertex interpolation question/problem Post by: Syntopia on April 13, 2013, 10:50:00 PM the problem is that when i put the same coordinate in GL.vertex3f(mycoordinate) GL.normal(mycoordinate) You are setting normal3f before calling vertex3f, right? Title: Re: GLSL vertex interpolation question/problem Post by: hobold on April 13, 2013, 11:34:24 PM Not sure if this is relevant here, but there is a mathematical difference between transforming
- a location in space - a normal vector both seem to be the same kind of 3-component vector, but they have different meanings. The former simply moves as the transformation says. But the latter is really the orientation of a tangent plane, and so the normal vector cannot simply be transformed by the same matrix as a location in space. It must remain perpendicular to the surface. Therefore another matrix is derived from the original transformation (the transpose of the adjoint? I am not sure offhand), and normal vectors are instead transformed by that derived matrix. In other words, the mismatch might come from the fact that two identical input vectors are multiplied with different transformation matrices. Title: Re: GLSL vertex interpolation question/problem Post by: Syntopia on April 14, 2013, 09:41:50 AM In other words, the mismatch might come from the fact that two identical input vectors are multiplied with different transformation matrices. OpenGL should not apply any transformations to the input vectors before the vertex shader. Typically, you apply these yourself in the vertex shader, e.g.: Code: gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; Btw, the gl_NormalMatrix is supplied by OpenGL, so you do not have to compute it yourself. It is the transposed inverse of the upper 3x3 part of the ModelViewProjectionMatrix matrix. Also, for typical projection matrices (uniform scaling + rotation), you don't need to take the transposed inverse, since these matrices are orthogonal. But you need to strip the fourth component translation away. Title: Re: GLSL vertex interpolation question/problem Post by: cKleinhuis on April 14, 2013, 04:00:23 PM You are setting normal3f before calling vertex3f, right? arhh, lol this was the error, thank you for pointing!!! |