Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: My lighting is way off

  1. #11
    Junior Member Regular Contributor
    Join Date
    Nov 2012
    Location
    Bremen, Germany
    Posts
    149
    LightRelPos = LightAbsolutePos - ObjectAbsolutePos
    LightPosInObjectSpace = ObjectRotation * LightRelPos

    dot(LightPosInObjectSpace, normal)

  2. #12
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    22
    Quote Originally Posted by hlewin View Post
    LightRelPos = LightAbsolutePos - ObjectAbsolutePos
    LightPosInObjectSpace = ObjectRotation * LightRelPos

    dot(LightPosInObjectSpace, normal)
    They're spheres. Can they really be rotated?

  3. #13
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    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:

  4. #14
    Junior Member Regular Contributor
    Join Date
    Nov 2012
    Location
    Bremen, Germany
    Posts
    149
    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.

  5. #15
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    22
    Quote Originally Posted by Nowhere-01 View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •