Hi

I am in the process of implementing shadow maps but I have some questions for those more experienced in this.

When I create light view matrix I am using the equivalent of the gluLookAt (because this is what the general populous seem to do). GluLookAt takes an eye position, but what is the eye position of a directional light? If I had a spot or point light this would be obvious but not so for directional lights.

The perspective matrix for a directional light is orthographic, I am experienced in creating orthographic matrix for ui drawing but no so for light. Should the near far be the same as my normal perspective matrix? What are good parameters for the left right top bottom? People put examples up but they never really explain why they choose the values that did.

1. For the eye position, since you’re dealing specifically with directional lights, you can make a safe assumption that the light source is extremely far away (similar to the sun). Therefore, depending on what your direction is, you can position the eye such that it is far away.

2. For the left, right, top, bottom, near, far variables, it really depends a whole lot on your scene. Try different parameters, and keep playing around; there will never be a single set of parameters that suits all scenes for shadow mapping, which is why it’s pretty troublesome to implement and perfect. Keep tweaking the parameters for the orthographic projection matrix to see what suits your scene.

There is one way to compute the orthographic projection matrix based on your camera’s view frustum, which you could try. You’d have to compute the matrix every frame, however. ThinMatrix does this as well in his video tutorials, but his code is more than a little messy, and I don’t really follow his tutorials, so his code was pretty difficult for me to read, but you could give that a shot, too. Here’s a great explanation of how you can do this, by theagentd:

If you’re still having trouble, I suggest following learnopengl.com 's great tutorial; or maybe ThinMatrix’s 2-part tutorial on shadow mapping. If you don’t like the quality of your shadows (resolution, etc.) try using Cascaded Shadow Mapping.

Have fun!