# My lighting is way off

Show 40 post(s) from this thread on one page
Page 2 of 2 First 12
• 07-26-2013, 05:59 PM
hlewin
LightRelPos = LightAbsolutePos - ObjectAbsolutePos
LightPosInObjectSpace = ObjectRotation * LightRelPos

dot(LightPosInObjectSpace, normal)
• 07-26-2013, 07:25 PM
Rakehell
Quote:

Originally Posted by hlewin
LightRelPos = LightAbsolutePos - ObjectAbsolutePos
LightPosInObjectSpace = ObjectRotation * LightRelPos

dot(LightPosInObjectSpace, normal)

They're spheres. Can they really be rotated?
• 07-26-2013, 10:17 PM
Nowhere-01
there's GLM library for vector\matrix math, that has syntax based GLSL: http://glm.g-truc.net/

generating viewMatrix in GLM can be done with glm::LookAt function, or using a set of manual transformations:

Code :

```glm::mat4 viewMatrix = glm::rotate(glm::mat4(1.0), -cameraRotation.x, glm::vec3(1, 0, 0)); viewMatrix = glm::rotate(viewMatrix, -cameraRotation.y, glm::vec3(0, 1, 0)); viewMatrix = glm::rotate(viewMatrix, -cameraRotation.z, glm::vec3(0, 0, 1));   viewMatrix = glm::translate(viewMatrix, -cameraPosition);```

note, that rotation in this case goes before translation.

but you better off starting with http://www.opengl-tutorial.org/begin...al-3-matrices/
and reading some other literature on matrix transformations and spaces. because you clearly don't know what you're doing.

also, you can use this image as reference for transformation spaces:
http://www.paulsprojects.net/tutorials/smt/spaces.jpg
• 07-27-2013, 01:36 AM
hlewin
Rotation applies to more vertex-attributes(meaning normals for this). And in practice, when approximating a sphere with triangles, one may see quite a difference in the shape depending on the viewpoint.
But: believe it or not, what I write above is wrong: You just apply the Rotation to the object - not to the lights relative Position.
That is what you might be doing if multiplying the normal with gl_NormalMatrix - depending on how you use the ModelViewMatrix.
• 07-30-2013, 04:14 PM
Rakehell
Quote:

Originally Posted by Nowhere-01
you clearly don't know what you're doing.

Well, duh. I did ask for tutorials in the first post, so I'll check that one out. Thanks.
Show 40 post(s) from this thread on one page
Page 2 of 2 First 12