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:
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 ...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 spaceworld_2_camera_matrix
is inverted transformation matrix representing camera space
Z axis is usually view directionprojection_matrix
is just perspective matrix (used for rendering ...)you can make any matrix with origin
(0,0,0)
by setting its12,13,14
element to zero (elements are0,..,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)
)