Glyph
Glyph

Reputation: 31860

Given the model/view/projection transformation matrix, how do I compute the normal matrix without using deprecated features in GLSL 1.2?

I know that the normal transformation matrix is the inverse of the transpose of the model/view/projection matrix, but it looks like "inverse" was only added in GLSL 1.4 and I can't find a "transpose". Do I have to just copy and paste a bunch of math into my GLSL? (If so, is there a nice authoritative open-source place I can copy from?)

To be clear, what I'm asking is "How do I calculate gl_NormalMatrix without using deprecated APIs"?

Upvotes: 1

Views: 1391

Answers (2)

fatto
fatto

Reputation: 1

just to clarify there's also transpose and if you don't do any scale the normal matrix is the 3x3 submatrix, in glsl you can do

normal = mat3(model_matrix) * v_normal;

Upvotes: 0

Nicol Bolas
Nicol Bolas

Reputation: 473407

This is normally handled by computing the transpose of the inverse of the modelview matrix

N = (M^-1)^T

on the CPU, then uploading the matrix just like uploading any other matrix.

Upvotes: 3

Related Questions