1
\$\begingroup\$

I'm doing lighting in world space (not in eye space), so I set the normal matrix as follows:

modelProgram->setUniform( "NormalMatrix", inverse(transpose(mat3(modelMatrix))) );

Now I noticed that all the tutorials set the normal matrix as the inverse transpose of the ModelView matrix. This also means they do lighting in eye space, right?

Do I have to do lighting in eye space when using the normal matrix? I actually do normal mapping too if it matters.

\$\endgroup\$
4
\$\begingroup\$

It's common for people to compute lighting in eye space because of how the specular component of lighting in the Phong model is calculated. Doing the calculation in view space, allows you to avoid a vector subtraction in the vertex shader, a basically negligible optimization.

If you were instead to do the calculations in world space, which you absolutely can, you would just additionally need to pass to your shader the eye's direction (or compute it from the view matrix within your shader).

It is certainly possible to do lighting in world space, and if you find that more intuitive you should go that route.

\$\endgroup\$
  • \$\begingroup\$ Then it is okay to set the normal matrix as the inverse transpose of the ModelMatrix as well? \$\endgroup\$ – Pilpel Jan 16 '16 at 4:32
  • \$\begingroup\$ Yes as long as you're aware throughout the rest of your shader that the normals are in world space. \$\endgroup\$ – Alex Sherman Jan 16 '16 at 4:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.