04-24-2007, 08:01 AM
I need the direction vector of the camera in my shader. Is there an easy way to find it in a shader ( I don't wants the direction between the camera and the current vertex but the direction of the camera)
04-24-2007, 11:26 AM
The camera's direction is <0, 0, -1> in camera coordinate system. If you would like to get this vector in Model (or World) coordinate system, then multiply it by the CameraToModel (or CameraToWorld) matrix. Notice the *direction* <0, 0, -1> is represented as <0, 0, -1, 0> in homogenous space.
The OpenGL ModelView matrix is the ModelToCamera matrix (that is, when you multiply a vector by this matrix, you transform it from Model coordinates to Camera coordinates). Therefore, if you take its inverse, you get the ModelToCamera matrix. Multiply that by <0, 0, -1, 0> and you get the camera's direction vector in Model space: <x, y, z, 0> (you can drop the last zero after).
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.