parallel shadows

Hi

I would like to implement shadow mapping for directional light sources (parallel light rays). I have everything already done. But I don’t know, how to compute the screen scaling, that I put into the orthographic matrix calculation.


glOrtho( -screenScale, screenScale, -screenScale / aspect, screenScale / aspect, near, far );

Does anybody know a way to realisticly calculate this screenscale value?

Thanks in advance.

Marvin

hum, isn’t it your shadow map texture size ? 256256 512512 etc…

Yes. But the texture size is irrelevant. It just defines the shadow resolution (quality). I am talking about the screenScale, that defines, how much of the scene is rendered into the depth texture. Please tell me, if you need more info to understand my problem.

Marvin

ok maybe I have trouble to understand the problem, can you please explain a little more ? hard for now to see what could be a good answer or way to search, I mean the ortho frustrum should be over the 3D volum you want to shadow :

bigger => lower quality for a bigger area shadowed
smaller => higher quality for a smaller area shadowed

you want it to :

fit the visible area from current camera ?

or

fit the object you want to shadow ?

in the second case you can do a projection of the object vertices (or faster surrounding sphere/box) onto the ortho camera plane and pick xmin/max ymin/max on this plane to get both x/y scale.

using the light direction vector and its 3d location, you have to choose an arbitrary perpendicular axis for y and then a x vector. using those normalized vector (x/y) compute vertice projection relative to light pos on the plane using scalar product.

I guess I am going to be wrong way again :slight_smile:

Ah! This really sounds like we’re moving closer to a solution. Thank you very much.

Since noting beyond the visible space is interesting for the shadowing algorithm, I guess, I want the shadow to fit the visible area from current camera. Since I have a directional light, I don’t have a light position, but just a light direction. Do you have a solution for your first case, too?

Marvin

True, you dont have light pos so just use the center of the shadow caster or one of its vertices.

Current camera visible volume is a Hexahedron (thk google:) ) that can be used as an object witch 8 vertices same as second solution.

Using the camera frustrum/visible volume you can compute eight points and project those one on your ortho/light plane.

you can also before that, clip it using the max z for the rendered frame.

maybe :

  • compute the eight points of the camera frustum culling volume
  • compute your light ortho plane equation using light vector and one origin (one vertice of shadowed or shadow caster object)
  • compute x/y vector lying on the ortho plane perpendicular from each other
  • make a projection of the eight vertices from the camera culling volume to the orthos plane
  • use xmax-xmin & ymas-ymin as the scale values