When I want to get the normalmatrix, I prepare a normalmatrix variable as Matrix4 and substitute "Inverse of modelview matrix" for it by using Matrix4.Invert .
Next, use GL.UniformMatrix4 for loading the variables into shaders .
Then, in a shader using normalmatrix(type is mat4), write "mat3(normalmatrix)" . It means taking upper-left 3x3 of the normalmatrix .
You can get the inversion matrix by using inverse(mat 4) as well.
Posted Monday, 20 September, 2010 - 13:10 by Shocker
Sorry . I have forgotten to write about transposing matrix .
You can transpose a matrix by specifying an argument in UniformMatrix4 or writing "transpose(mat 4)" .
Comments
Re: Getting normal matrix from modelview matrix
gl_NormalMatrix in your vertex shader ;)
Re: Getting normal matrix from modelview matrix
no more in OpenGL > 3.x...
Re: Getting normal matrix from modelview matrix
http://www.lighthouse3d.com/opengl/glsl/index.php?normalmatrix
When I want to get the normalmatrix, I prepare a normalmatrix variable as Matrix4 and substitute "Inverse of modelview matrix" for it by using Matrix4.Invert .
Next, use GL.UniformMatrix4 for loading the variables into shaders .
Then, in a shader using normalmatrix(type is mat4), write "mat3(normalmatrix)" . It means taking upper-left 3x3 of the normalmatrix .
You can get the inversion matrix by using inverse(mat 4) as well.
Re: Getting normal matrix from modelview matrix
Ok, thank you !
Re: Getting normal matrix from modelview matrix
Sorry . I have forgotten to write about transposing matrix .
You can transpose a matrix by specifying an argument in UniformMatrix4 or writing "transpose(mat 4)" .
Re: Getting normal matrix from modelview matrix
I'm not sure I follow... Do you have a code sample you could post?