1
votes

I have a directional light and I want to generate a view matrix for this light (using glm lookAt()). I know the light direction and its position, but how would I go about getting the up vector with only those parameters? (the cross-product requires the left vector aswell, but I only have the forward vector...). Is it always (0, 1, 0)?

1

1 Answers

0
votes

You want an orthonormal basis (V,U,R) where V is the view direction (light direction in your case), U is the up vector and R is the vector orthogonal to U and V. (V,U,R) + your light position O define the camera.

To define this basis you need 2 vectors, for instance U and V, and the third is deduced as cross(U,V). That's why glmLookAt needs 2 vectors and not just the V vector.

If you only have V then there are infinite possibilities for U: O+U define the whole unit circle centered at O.

You can pick a random U by taking a random vector X != V && X != -V then U can be computed as:

U = cross(normalize(V), normalize(X))

However for different X the rendering with that camera will be different!

If you're using this for shadow mapping, try setting you frustum so that for any U the shadowed scene is well covered (again, different frustum and U settings produce different amount of aliasing).