5
\$\begingroup\$

I'm doing shadow mapping in my OpenGL 4.3 deferred renderer, and I'm starting with directional lights believing it to be the easiest.

What I do not understand is how the view projection matrix is to be constructed for the shadow mapping depth pass. I mean, all I have is the lights direction, and it affects the entire scene - so how do I construct the view matrix from only the direction, and what of the projection matrix?

Thanks

\$\endgroup\$
  • \$\begingroup\$ you can rotate/skew the scene so the light is vertical and build a height map \$\endgroup\$ – ratchet freak Dec 29 '13 at 16:23
  • 1
    \$\begingroup\$ @KaiserJohaan Do you know how to construct an orthographic projection matrix in general? \$\endgroup\$ – TravisG Dec 29 '13 at 19:51
  • \$\begingroup\$ I do not; only used perspective matrices so far \$\endgroup\$ – KaiserJohaan Dec 29 '13 at 21:12
3
\$\begingroup\$

Spotlight shadow maps are created by projecting the scene with a perspective frustum. This allows the light to radiate out from a single point. This perspective frustum is built using:

  1. A view matrix originating from the light's position and pointing in the direction of the spotlight
  2. A perspective projection matrix that encompasses the light volume

In a similar way, directional light shadow maps use an orthographic projection, so the direction of the light is uniform across the map so as to approximate a very far away light source (the sun). The frustum in this case is built unsing:

  1. A view matrix where the direction is parallel to the light's direction; it usually follows the camera around

  2. An orthographic projection matrix that defines the volume to be shadowed

The only tricky part of using a directional light is that it usually cannot shadow the whole scene at once. Instead, you have to use techniques such as cascaded shadow maps (CSM).

Cascaded shadow maps overview

With CSM, you have a number of shadow volumes of different sizes that overlap so as to cover the entire viewing frustum. Ideally, they would be sized and placed so that each screen pixel maps to at least one shadow texel while minimizing overdraw.

Cascaded shadow maps in perspective

The colored areas in this image each represent a different shadow volume. The red volume is the smallest and thus has the highest texel resolution, then green, and so on.

This page is more in-depth and should provide you with a pretty thorough understanding of the concept.

\$\endgroup\$
  • \$\begingroup\$ So the camera eye doesn't change, only the direction or, what? This is what I don't understand. My light's point of view matrix still have to take some positional information (i.e. where we are in the world) into consideration, how is this happening? \$\endgroup\$ – John Leidegren Sep 1 '16 at 10:53
0
\$\begingroup\$

you can rotate/shear the scene so the light is vertical and build a height map and use that as the shadow map

for the shear matrix it's something like

[1 0 -x/z 0]
[0 1 -y/z 0]
[0 0 1    0]
[0 0 0    1]
\$\endgroup\$
  • \$\begingroup\$ Not sure I understand the theory behind it; can you explain it some more? \$\endgroup\$ – KaiserJohaan Dec 29 '13 at 19:35
  • \$\begingroup\$ @KaiserJohaan You transform the scene so the light goes from up to down and build a height map. Using shearing allows the horizontal floor to be be at the same height throughout the height map, which is better for large horizontal areas while rotation would be handy for more vertical maps \$\endgroup\$ – ratchet freak Dec 29 '13 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.