Transforming normals from worldspace to the viewspace

跟風遠走 提交于 2019-12-24 11:33:03

问题


Let's say I have my normals in worldspace and I want to transform them into viewspace. What should I do? I have already tried to multiply them by viewProjection matrix and by inversed transformed view matrix, but both didn't work. Blue channel (z axis) appears to be missing. I am confused.


回答1:


  1. on fixed pipeline do nothing it does the work for you

    to work properly all world/object transforms should be inside modelview matrix else some advanced things like FOG will not work properly (ie GL_PROJECTION matrix abuse) but in most cases you do not see a thing ...

  2. on shaders you can handle lighting your self so this is the way

    point'  = object_2_world_matrix * world_2_camera_matrix * projection_matrix * point
    vector' = object_2_world_matrix(with origin 0,0,0) * world_2_camera_matrix(with origin 0,0,0) * vector
    


    object_2_world_matrix is transformation matrix representing rendered model space
    world_2_camera_matrix is inverted transformation matrix representing camera space
    Z axis is usually view direction
    projection_matrix is just perspective matrix (used for rendering ...)

    you can make any matrix with origin (0,0,0) by setting its 12,13,14 element to zero (elements are 0,..,15)

You did not remove matrix positions which transforms normal vectors to position of vertex ... That is the reason for weirdness ... so either substract the offset of matrices from the result or multiply by matrices without offset (origin = (0,0,0))



来源:https://stackoverflow.com/questions/22892594/transforming-normals-from-worldspace-to-the-viewspace

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!