   Light position in shader
  Hey guys. I have a big problem that I can't figure out. I've been trying this for some weeks now.So first I have a vector3 that has the light position in worldspace. ( used the test values 64,64,64).Now using a deferred shader I have my modelview_matrix and my projection_matrix in the shader. I used glUniformMatrix4fv(var,1,false,v); to set a matrix uniform. (I'm not sure wether to use false or true since I get them with glGetFloatv passing GL_MODELVIEW_MATRIX and GL_PROJECTION_MATRIX). Now in my vert I have the lightPos vec3. I try to get the viewLight by multiplying mod_mat(modelview matrix) by lightPos. So that should stay fixed. However if I rotate my camera or move it the light also moves.Could anyone help me here?   
  I always use FALSE in glUniformMatrix4fv so that it won't transpose my matrix. I really don't understand why they added that parameter in the first place.What I do is that on the CPU, I have my lights in world space. I move them to eye space with CameraMatrix * light_pos and I upload to my shader."So that should stay fixed. However if I rotate my camera or move it the light also moves."It depends on what you matrix is in GL_MODELVIEW_MATRIX.   ;  I don't know how to multiply a camera matrix with the pight position on the CPU. On gpu I con just write mod_mat*lightPos.I get the modelviewmatrix right after I set up my camera. And anyway I use push and pop every time I draw something so it doesn't matter where I get the modelviewmatrix as long as it's not in a draw routine.   ;  Something like thisresult4D=matrix[<span class="cpp-number">0</span>]*vector4D<span style="font-weight:bold;">+<br>matrix[<span class="cpp-number">4</span>]*vector4D[i+<span class="cpp-number">1</span>]+<br>matrix[<span class="cpp-number">8</span>]*vector4D[i+<span class="cpp-number">2</span>]+<br>matrix[<span class="cpp-number">12</span>]*vector4D[i+<span class="cpp-number">3</span>];<span class="cpp-comment">//w is 1</span><br><br>result4D[i+<span class="cpp-number">1</span>]=matrix[<span class="cpp-number">1</span>]*vector4D<span style="font-weight:bold;">+<br>matrix[<span class="cpp-number">5</span>]*vector4D[i+<span class="cpp-number">1</span>]+<br>matrix[<span class="cpp-number">9</span>]*vector4D[i+<span class="cpp-number">2</span>]+<br>matrix[<span class="cpp-number">13</span>]*vector4D[i+<span class="cpp-number">3</span>];<br><br>result4D[i+<span class="cpp-number">2</span>]=matrix[<span class="cpp-number">2</span>]*vector4D<span style="font-weight:bold;">+<br>matrix[<span class="cpp-number">6</span>]*vector4D[i+<span class="cpp-number">1</span>]+<br>matrix[<span class="cpp-number">10</span>]*vector4D[i+<span class="cpp-number">2</span>]+<br>matrix[<span class="cpp-number">14</span>]*vector4D[i+<span class="cpp-number">3</span>];<br><br>result4D[i+<span class="cpp-number">3</span>]=matrix[<span class="cpp-number">3</span>]*vector4D<span style="font-weight:bold;">+<br>matrix[<span class="cpp-number">7</span>]*vector4D[i+<span class="cpp-number">1</span>]+<br>matrix[<span class="cpp-number">11</span>]*vector4D[i+<span class="cpp-number">2</span>]+<br>matrix[<span class="cpp-number">15</span>]*vector4D[i+<span class="cpp-number">3</span>];<br><br></pre></div><!–ENDSCRIPT–> ;  Hm... I've tryed this over and over and it still acts weird.Can't figure it out and it drive's me nuts   ;  For correct lighting you have to understand the different spaces and the transformations between them.Lets sayOS = object spaceWS = world spaceCS = camera spaceYour model data(vertices) are in object space, what you see on the screen is a projection of the camera space, so you need three matrices to convert your model from object space to the screenOS ==M=> WS ==V=> CS ==P=> Screenwith M=MODEL, V=VIEW and P=PROJECTION.Your GL_MODELVIEW_MATRIX is already the concatinated M and V matrix, MV called and here is your problem. For correct lighting you have to work in the same space. When you take your light position in WS you need either to transform your vertices to WS too or you have to transform your light position into CS. Transform your vertices to WS is complicated, because you got the MV but not the M matrix. Best to get your lights to CS. Well, if you have your lights already in WS you just need to transform them to CS by the V matrix.Take a look at the following pseudo code of a typical render cycle in opengl:// move cameraglRotate(..)glTranslate(..)..X..for each mesh do glPush(...) glRotate(...) glTranslat(..) ... render mesh glPop(..)endAt the position marked as X you have done your camera movement just before starting to render your meshes. At this time your MV matrix is the same as your V matrix and you can extract the V matrix by using glGetFloatv/GL_MODELVIEW_MATRIX. Then you have to transform your light position by V before uploading them.--Ashaman   