Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualifthen

Posted 10 November 2012 - 03:49 AM

I think that it is okay, the lightMatrix looks like the only pitfall. It should be the same as the modelview matrix.

Look at it this way: the fragment shader needs to know only three things for calculating lightning (for point light) – the position of the fragment (variable), the normal of the fragment (variable) and the position of the light (uniform). All of them must be in the same coordinate space.

(The normals use another matrix because of scaling. If you call glScalef(1,1,0.5), the normals must be scaled by the opposite because of stuff. The normal matrix preserves the rotation, doesn't have translation (the normals are true vectors, not positions) and corrects the scaling. Take note, however, that object space normal multiplied by the normal matrix is in eye space.)

(That also means you don't have to compute lightning in eye space, it can be done in object space too; that would mean that you can have a static light source, not one moving with the camera, without performing additional matrix calculations on the CPU. But you would have to you wanted a light static to camera. It really depends what to use on whether the light is carried by the cameraman (e.g. flashlight) or not (e.g. a chandelier).)

Other than that, it looks good to me.

#1ifthen

Posted 10 November 2012 - 03:44 AM

I think that it is okay, the lightMatrix looks like the only pitfall. It should be the same as the modelview matrix.

Look at it this way: the fragment shader needs to know only three things for calculating lightning (for point light) – the position of the fragment (variable), the normal of the fragment (variable) and the position of the light (uniform). All of them must be in the same coordinate space.

(The normals use another matrix because of scaling. If you call glScalef(1,1,0.5), the normals must be scaled by the opposite because of stuff. The normal matrix preserves the rotation, doesn't have translation (the normals are true vectors, not positions) and corrects the scaling. Take note, however, that object space normal multiplied by the normal matrix is in eye space.)

(That also means you don't have to compute lightning in eye space, it can be done in object space too; that would mean that you would have a static light source, not one moving with the camera, without performing additional matrix calculations on the CPU. I personally like it more.)

Other than that, it looks good to me.

PARTNERS