I am trying to shadowmap a large terrain, I position my light that it is always at the position of the player and looking at the player, the problem is that the shadows now move with the player, I tried to set the position to 0 1000 500 and look at the player always and its a good improvement however the player moves out of the light there are now no shadows :(

How am I supposed to make the light so it covers the entire terrain and everything has shadows all the time without the shadow moving effect?

I am really stuck right now, do I need to somehow calculate scene bounds? would that help at all?


It'd be helpful if we knew what API or engine you're using.

If your shadows are from the Sun, you should be using a directional light, not a point or spot light. This means using an orthographic projection matrix when rendering to your shadowmap, as explained here: http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/

If your terrain is very large, you may want to confine your shadowmap to a small region centered on the player. This is done through via the view and projection matrices used to render to the shadowmap. If you take this approach, you will encounter a "swimming" artifact discussed here: http://www.gamedev.net/topic/462238-swimming-shadow-edges-can-they-be-eliminated/

  • \$\begingroup\$ I am using OpenGL + C++ with my own engine, Why should I use an orthographic viewport? is there any difference? I don't think I am getting swimming using that method, I am getting the effect where the shadows move with the camera causing the shadow to appear elevated. \$\endgroup\$ – user1040769 Apr 27 '13 at 19:10
  • \$\begingroup\$ Why should I use an orthographic viewport? Because it's assumed that a directional light ( i.e the sun ) has all of its light rays in one parallel direction. \$\endgroup\$ – Sidar Nov 20 '17 at 15:23

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.