From: Diederick C. Niehorster <dcnieho@gm...>  20120609 09:29:24

Hi, On Sat, Jun 9, 2012 at 4:27 PM, Diederick C. Niehorster <dcnieho@...> wrote: > > I have both a world space and a view space shader here. I'll be > needing an inverse in either case tho, as both require a normal > matrix, which is: > "normal matrix" N = transpose(inverse(M)), where M is the modelview matrix. Sorry, that should be the transposed inverse of the upper left 3x3 of the modelview matrix. Here's some code that should do inverse and transpose at once: float determinant = +A(0,0)*(A(1,1)*A(2,2)A(2,1)*A(1,2)) A(0,1)*(A(1,0)*A(2,2)A(1,2)*A(2,0)) +A(0,2)*(A(1,0)*A(2,1)A(1,1)*A(2,0)); float invdet = 1/determinant; result(0,0) = (A(1,1)*A(2,2)A(2,1)*A(1,2))*invdet; result(1,0) = (A(0,1)*A(2,2)A(0,2)*A(2,1))*invdet; result(2,0) = (A(0,1)*A(1,2)A(0,2)*A(1,1))*invdet; result(0,1) = (A(1,0)*A(2,2)A(1,2)*A(2,0))*invdet; result(1,1) = (A(0,0)*A(2,2)A(0,2)*A(2,0))*invdet; result(2,1) = (A(0,0)*A(1,2)A(1,0)*A(0,2))*invdet; result(0,2) = (A(1,0)*A(2,1)A(2,0)*A(1,1))*invdet; result(1,2) = (A(0,0)*A(2,1)A(2,0)*A(0,1))*invdet; result(2,2) = (A(0,0)*A(1,1)A(1,0)*A(0,1))*invdet; Best, Dee 